akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public 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 num ;

		if(a>b){
			num = b;
			b = a;
			a = num;
		}
		if(b>c){
			num = c;
			c = b;
			b = num;
		}
		if(a>b){
			num = b;
			b = a;
			a = num;
		}
		System.out.println(a+" "+b+" "+c);
	}
}

Measured memory_bytes: 17356
#include <iostream>
#include <string>
#include <cmath>
#include <math.h>
#include <stdio.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    while(n != 0){
        double s[1000]={0},sum=0,ave,a=0;
        for(int i=0;i<n;i++){
            cin >> s[i];
            sum += s[i];
        }
        ave = sum/n;
        for(int i=0;i<n;i++){
            a += ((s[i]-ave)*(s[i]-ave))/n;
        }
        printf("%.8f\n",sqrt(a));
        cin >> n;
    }
}


Measured memory_bytes: 3212
s = h = 0 #カウンタ変数の初期化
try: #ここから下のエラーをけんちする
    while True: #無限ループ
        a,b,c = map(int,input().split(",")) #入力を","で区切る
        if a ** 2 + b ** 2 == c ** 2:s += 1 #さん平方の定理が成り立つなら長方形
        elif a == b:h += 1 #隣り合う2辺の長さが同じならひし形
        else:pass #それ以外は処理なし
except EOFError: #EOFErrorを拾う
    print(s) #長方形の数を出力
    print(h) #ひし形の数を出力


Measured memory_bytes: 5592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<int> vec1;
typedef vector<string> vec2;
typedef vector<double> vec3;
#define rep(i,n) for(int i=0;i<(n);i++)
const int MOD = 1000000007;

int main() {
  int a, b;
  cin >> a >> b;
  cout << (a+b)%24 << endl;
}

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

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define PB push_back

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

  while(true) {
    int p, q;
    cin >> p >> q;
    if(!p) break;
    vector<string> s(p), t(q);
    REP(i, p) cin >> s[i];
    REP(i, q) cin >> t[i];

    VI ans(q, -2);
    FOR(R, 1, 21) FOR(C, 1, 21) FOR(S, 1, 21) {
      int a = 0,  b = 0, c = 0;
      bool flag = true;
      REP(i, p) {
        int tmp = -1;
        REP(j, s[i].size()) if(s[i][j]!='.') {tmp = j; break;}
        if(R*a + C*b + S*c != tmp) {
          flag = false;
          break;
        }
        REP(j, s[i].size()) {
          if(s[i][j] == '(') a++;
          else if(s[i][j] == ')') a--;
          else if(s[i][j] == '{') b++;
          else if(s[i][j] == '}') b--;
          else if(s[i][j] == '[') c++;
          else if(s[i][j] == ']') c--;
        }
      }
      if(!flag) continue;
      // ここまで来てたら(R,C,S)の組を取ることが可能
      a = b = c = 0;
      REP(i, q) {
        // i行目のインデントで a*R + b*C + c*S となる可能性がある
        // i行目の答えを設定
        if(ans[i] == -2) ans[i] = a*R + b*C + c*S;
        // 2通り以上ある(答えが一意に決まらない)ときは-1
        else if(ans[i] != a*R + b*C + c*S) ans[i] = -1;
        REP(j, t[i].size()) {
          if(t[i][j] == '(') a++;
          else if(t[i][j] == ')') a--;
          else if(t[i][j] == '{') b++;
          else if(t[i][j] == '}') b--;
          else if(t[i][j] == '[') c++;
          else if(t[i][j] == ']') c--;
        }
      }
    }

    REP(i, q) cout << ans[i] << (i==q-1?"":" ");
    cout << endl;
  }

  return 0;
}



Measured memory_bytes: 3220
X, Y, Z, K = map(int, input().split())
import heapq

A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
a = b = c = 0
count = 1
heap = [(0, (0, 0, 0))]
log = [(0, 0, 0)]
heapq.heapify(heap)
while count <= K:
    count += 1
    q = heapq.heappop(heap)
    a = q[1][0]
    b = q[1][1]
    c = q[1][2]
    print(A[a]+B[b]+C[c])
    if(a+1 < len(A) and not (a+1, b, c) in log):
        heapq.heappush(heap, (q[0]+A[a]-A[a+1], (a+1, b, c)))
        log.append((a+1, b, c))
    if(b+1 < len(B)  and not (a, b+1, c) in log):
        heapq.heappush(heap, (q[0]+B[b]-B[b+1], (a, b+1, c)))
        log.append((a, b+1, c))
    if(c+1 < len(C)  and not (a, b, c+1) in log):
        heapq.heappush(heap, (q[0]+C[c]-C[c+1], (a, b, c+1)))
        log.append((a, b, c+1))
    
    

Measured memory_bytes: 4724
var
	n,i,j,c,ans:Longint;
	s:string[100];
	L,R:array[1..26]of Longint;
begin
	readln(n);
	readln(s);
	for i:=1 to length(s)do begin
		if L[ord(s[i])-96]=0 then L[ord(s[i])-96]:=i;
		R[ord(s[i])-96]:=i;
	end;
	for i:=2 to length(s)do begin
		c:=0;
		for j:=1 to 26 do if(L[j]<i)and(i<=R[j])then inc(c);
		if c>ans then ans:=c;
	end;
	writeln(ans);
end.

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 long long a,b,c;
  cin>>a>>b>>c;
 if(a>=c>0){
   a-=c;
   c=0;
 }
   else if(c>=a>0){
     c-=a;
     a=0;
   }
     if(b>=c>0){
       b-=c;
     }
  else if(c>=b>0){
  b=0;
  }
  cout<<a<<" "<<b<<endl;
  }
  

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

int main() {
	string S;
	cin >> S;
	if (S == "ABC") {
		puts("ARC");
	}
	else {
		puts("ABC");
	}
	return 0;
}

Measured memory_bytes: 3624
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

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

/*
 freopen("input","r",stdin);
 freopen("output","w",stdout);
*/

ll MOD = 1E9 + 7;

ll DP[10010][110];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;
    int d;
    cin >> d;
    memset(DP, 0, sizeof(DP));
    int l = s.size();
    DP[l][0] = 1;
    for (int i = l - 1;i >= 0;i--) {
        for (int j = 0;j <= 9;j++) {
            for (int k = 0;k < d;k++) {
                DP[i][(j + k) % d] += DP[i + 1][k];
                DP[i][(j + k) % d] %= MOD;
            }
        }
    }
    int prefix = 0;
    ll sol = 0;
    for (int i = 0;i < l;i++) {
        int x = s[i] - '0';
        int y = x;
        if (i == l - 1) y = x + 1;
        for (int j = 0;j < y;j++) {
            int crt = prefix + j;
            int rem = (d - (crt % d)) % d;
            sol += DP[i + 1][rem];
            sol %= MOD;
        }
        prefix += x;
        prefix %= d;
    }
    // exclude 0
    sol += MOD - 1;
    cout << sol % MOD << endl;
    return 0;
}

Measured memory_bytes: 8832
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=23,S=1<<20,mo=1000000007;
template<typename TP>
inline void read(TP &kk)
{
	TP ret=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){ret=ret*10+ch-'0';ch=getchar();}
	kk=ret*f;
}
int n,m,k;
int sc[S],ful,l1[N],l0[N];
int to[S][N],ne[S];
int dp[S];
int ans;

int xi,yi,zi;
signed main()
{
//	freopen("zigzag.in","r",stdin);
//	freopen("zigzag.out","w",stdout);
	memset(ne,-1,sizeof(ne));memset(to,-1,sizeof(to));
	read(n),read(m),read(k);n--;
	ful=(1<<n)-1;
	for(int i=1;i<=k;i++)
	{
		read(xi),read(yi),read(zi);
		yi--;
		l0[xi]|=(1<<yi);
		if(zi)l1[xi]|=(1<<yi);
	}
	for(int s=0;s<=ful;s++)
		for(int j=0;j<n;j++)
			if(s&(1<<j))
			{
				if(j&&!(s&(1<<(j-1))))
				{
					to[s][sc[s]]=s^(1<<j)^(1<<(j-1));
				}
				sc[s]++;
			}
	for(int s=0;s<=ful;s++)
		for(int j=n-1;j>=0;j--)
			if(!(s&(1<<j))){ne[s]=s^(1<<j);break;}
	dp[0]=1;
	for(int i=1;i<=m;i++)
	{
		for(int s=0;s<=ful;s++)
			if(ne[s]!=-1)
				(dp[ne[s]]+=dp[s])%=mo;
		for(int b=0;b<n;b++)
			for(int s=ful;s>=0;s--)
				if(to[s][b]!=-1)
					(dp[to[s][b]]+=dp[s])%=mo;
		for(int s=0;s<=ful;s++)
			if((s&l0[i])!=l1[i]) dp[s]=0;
	}
	for(int s=0;s<=ful;s++) (ans+=dp[s])%=mo;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 106624
#coding:utf-8
N,A,B,C,D = map(int,input().split())
S = input()
def isContinuous(S):
    for i in range(len(S)-1):
        if S[i:i+2] == "##":
            return True
    return False
def paint(S):
    P = [0] * len(S)
    for i in range(len(S)):
        if S[i] == "#":
            P[i] = 1
            if i != 0:
                P[i-1] = 1
            if i != (len(S)-1):
                P[i+1] = 1
    return P
if C < D:
    if (not isContinuous(S[A:C])) and (not isContinuous(S[B:D])):
        print ("Yes")
    else:
        print ("No")
else:
    P = paint(S)
    #print (P)
    #print (P[B-1:D])
    for i in P[B-1:D]:
        if i == 0:
            print ("Yes")
            exit()
    print ("No")


Measured memory_bytes: 5428
#include<stdio.h>

int main(void)
{   
  int i, a=0, b=0, o=0, ab=0;
  char blood[2];
  
  while(scanf("%d,%s",&i,blood)!=EOF)
  {
    if(blood[0]=='A')
      {
	if(blood[1]=='B')
	  ab++;
	else
	  a++;
      }
    else if(blood[0]=='B')
      b++;
    else
      o++;
  }
  
  printf("%d\n%d\n%d\n%d\n",a,b,ab,o);

  return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000
#define MOD 1000000007LL
#define MAX 100005
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> doup;
ll N, M, R;
ll i, j, k;
ll a, b, c;
ll d[201][201];
vector<ll> r;
ll sum;

int main(void) {
    cin >> N >> M >> R;
    ll t;
    for(i=0; i<R; i++) {
        cin >> t;
        t--;
        r.push_back(t);
    }
    
    for(i=0; i<N; i++) {
        for(j=0; j<N; j++) {
            d[i][j]=(i==j ? 0 : INF);
        }
    }
    
    for(i=0; i<M; i++) {
        cin >> a >> b >> c;
        a--; b--;
        d[a][b]=c;
        d[b][a]=c;
    }
    
    for(k=0; k<N; k++) {
        for(i=0; i<N; i++) {
            for(j=0; j<N; j++) {
                d[i][j]=min(d[i][j], d[i][k]+d[k][j]);
            }
        }
    }
    ll ans=INF;
    sort(r.begin(), r.end());
    do {
        sum=0;
        for(i=0; i<R-1; i++)
            sum+=d[r[i]][r[i+1]];
        ans=min(ans, sum);
    } while(next_permutation(r.begin(), r.end()));
    
    cout << ans << endl;
}


Measured memory_bytes: 512
import java.util.Scanner;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int t = sc.nextInt();
		int c[] = new int[n];
		int tn[] = new int[n];
		int cm=1001,tm=1001;
		for(int i= 0;i<n;i++){
			c[i]=sc.nextInt();
			tn[i]=sc.nextInt();
			if(cm>c[i]&&t>=tn[i]){
				cm=c[i];
				tm=tn[i];
			}

		}
		if(tm==1001){
			System.out.println("TLE");
		}else{
			System.out.println(cm);
		}
	}
}


Measured memory_bytes: 23636
#include<bits/stdc++.h>
using namespace std;
int a[31];
int main(){
	int n,m,i,j,k,num,ans=0;
	cin>>n>>m;
	for(i=1;i<=n;i++){
		cin>>k;
		for(j=1;j<=k;j++){
			cin>>num;
			a[num]++;
		} 
	}
	for(i=1;i<=m;i++){
		if(a[i]==n) ans++; 
	}
	cout<<ans;
	return 0;
}

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

int main() {
  int K, X;
  cin >> K >> X;

  int min = X - K + 1;
  int max = X + K - 1;
  for (int i = min; i <= max; i++) {
    printf(i == min ? "%d" : " %d", i);
  }
  printf("\n");
}

Measured memory_bytes: 256
n,k = gets.chomp.split.map(&:to_i)
xs = gets.chomp.split.map(&:to_i)
ans = 10 ** 18

(n-k+1).times do |i|
	l = xs[i]
	r = xs[i+k-1]
	if l < 0 && r > 0
		dist = [l.abs * 2 + r, l.abs + r * 2].min
	else
		dist = [l.abs , r.abs].max
	end
	ans = dist if ans > dist
end

puts ans

Measured memory_bytes: 12036
#include <stdio.h>
#include <cstdio>
#include <string>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>


std::string str;

long long int N[30] = { 0 };

int main()
{
	long long int ans = 0;
	std::cin >> str;

	for (int a = 0; a < str.length(); ++a)
		N[str[a] - 'a']++;

	ans = (str.length() * (long long int)(str.length() - 1)) / 2LL + 1;

	for (int a = 0; a < 26; ++a) ans -= (N[a] * (N[a] - 1)) / 2LL;

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

	return 0;
}

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

const int N = 405 , M = 5e3+5;

int n , m ;

long long dp[N][N] , a[N] , sum[N];

long long get(int l , int r)
{
    return sum[r] - sum[l-1];
}

long long solve(int l , int r )
{
    if(l==r)return 0;
    if(dp[l][r]>-1)
        return dp[l][r];
    long long  ret = 1e15;
    for(int i = l;i<r;i++)
        ret = min(ret ,get(l,i)+get(i+1,r) + solve(l , i) + solve(i+1 , r) );
    return dp[l][r]=ret;
}

int main()
{
    memset(dp , -1 , sizeof dp);
    cin>>n;
    for(int i = 1;i<=n;i++)
        cin>>a[i];
    for(int i = 1;i<=n;i++)
            sum[i] = sum[i-1]+ a[i];
    cout<<solve(1 , n);
    return 0;
}


Measured memory_bytes: 1536
#include <iostream>
using namespace std;
#define MAX 100000
int N;
long int A[MAX];

bool one_survive(){
    int survive = 0;
    for (int i = 0; i < N; i++){
        if (A[i] > 0){
            survive += 1;
        }
    }
    if (survive == 1){
        return true;
    }
    else{
        return false;
    }
}

int main(){
    cin >> N;
    for (int i = 0; i < N; i++){
        long int a;
        cin >> a;
        A[i] = a;
    }
    // long int minimum = A[0];
    long int min_val = A[0];
    int min_idx = 0;
    while (true){
        if (one_survive()){
            break;
        }
        for (int i = 0; i < N; i++){
            if (A[i] > 0 && min_val >= A[i]){
                min_val = A[i];
                min_idx = i;
            }
        }
        for (int i = 0; i < N; i++){
            if (i == min_idx || A[i] <= 0){
                continue;
            }
            else{
                A[i] %= min_val;
            }
        }
    }
    cout << min_val << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

interface Toi{
	public void exec(String[] args);
}

public class Main {
	public static void main(String[] args){
	Toi toi = new Toi11();
	toi.exec(args);
	}
}

class Toi8 implements Toi{
	public void exec(String[] args){
		solve();
	}
	public void solve(){
		Scanner sc = new Scanner(System.in);
		int[] whxyr = new int[5];
		for(byte i = 0;i < whxyr.length;i++){
			whxyr[i] = sc.nextInt();
		}
		calc(whxyr);
		int[] renewWh = {whxyr[0] - whxyr[4], whxyr[1] - whxyr[4], whxyr[2] + whxyr[4], whxyr[3] + whxyr[4]};
		if(renewWh[0] >= 0 && renewWh[1] >= 0 && renewWh[2] <= whxyr[0] && renewWh[3] <= whxyr[1]){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
	public int[] calc(int[] array){
		int tmp;
		for(byte i = 0;i < array.length - 2;i++){
			if(array[i + 2] < 0){
				tmp = array[i];
				array[i] = array[i + 2];
				array[i + 2] = tmp;
			}
		}
		return array;
	}
}

class Toi9 implements Toi{
	public void exec(String[] args){
		solve();
	}
	public void solve(){
		for(short i = 0;i < 1000;i++){
			System.out.println("Hello World");
		}
	}
}

class Toi10 implements Toi{
	public void exec(String[] args){
		solve();
	}
	public void solve(){
		short[] tmp = new short[10000];
		Scanner sc = new Scanner(System.in);
		for(short i = 0;i < 10000;i++) {
			try {
				tmp[i] = sc.nextShort();
				if (tmp[i] == 0) {
					break;
				}
			}catch (Exception e){
				break;
			}
		}
		for(short i = 1;i <= 10000;i++){
			if(tmp[i-1] == 0){
				break;
			}
			System.out.println("Case " + i + ": " + tmp[i-1]);
		}
	}
}

class Toi11 implements Toi{
	public void exec(String[] args){
		solve();
	}
	public void solve(){
		short[] xy = new short[6000];
		Scanner sc = new Scanner(System.in);
		short point = 0;
		for(short i = 0;i < 3000;i++) {
			try {
				xy[i] = sc.nextShort();
				xy[i+3000] = sc.nextShort();
			}catch (Exception e){
				break;
			}
			if (xy[i] == 0 && xy[i+3000] == 0){
				point = i;
				break;
			}
		}
		for(short i = 1;i <= point;i++){
			if(xy[i-1] < xy[i+3000-1]) {
				System.out.println(xy[i-1] + " " + xy[i+3000-1]);
			}else {
				System.out.println(xy[i+3000-1] + " " + xy[i-1]);
			}
		}
	}
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 1e5 + 5;
int n, m, k, ans;
string s;

int main() {
    cin >> n >> m >> s;
    bool ok = true;
    for (int i = 0; i < n; ++i) {
        if (!isdigit(s[i]))
            ok = false;
    }
    if (s[n] != '-')
        ok = false;
    for (int i = 0; i < m; ++i) {
        if (!isdigit(s[n + 1 + i]))
            ok = false;
    }
    if (ok)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define nmax 100005

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;

typedef tree<
int,
null_type,
less_equal<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

int n;
int a[nmax];

bool solve(int p){
	vector<int> pre(n+1,0);
	ordered_set st;
	ll ans=0;
	st.insert(0);
	for(int i=1;i<=n;i++){
		pre[i]=pre[i-1]+((a[i]<=p)?1:-1);
		ans+=st.order_of_key(pre[i]);
		st.insert(pre[i]);
		if(ans>(1ll*n*(n+1))/4){
			return 1;
		}
	}
	return ans>(1ll*n*(n+1))/4;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n;
	for(int i=1;i<=n;i++){
		cin >> a[i];
	}
	vector<int> b(a+1,a+n+1);
	sort(b.begin(),b.end());
	
	int l=-1, r=b.size()-1;
	while(l+1<r){
		int mid=(l+r)>>1;
		if(solve(b[mid])){
			r=mid;
		}
		else{
			l=mid;
		}
	}
	
	cout << b[r] << endl;
	return 0;
}

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


N, K = map(int, input().split())
A = list(map(int, input().split()))
S = []
for i in range(N):
    s = 0
    for j in range(i, N):
        s += A[j]
        S.append(s)


def f(a):
    ret = 0
    for x in S:
        if (x & a) == a:
            ret += 1
    return ret


# kaisetsu
def main():
    import math
    m = int(math.log(sum(A)*K, 2)) + 1
    ans = 0
    for i in range(m, -1, -1):
        k = f(ans | (1 << i))
        if k >= K:
            ans |= (1 << i)
    print(ans)


if __name__ == '__main__':
    main()


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

const double PI = acos(-1);

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000

void solve_abc_c() {
	ll n, m;
	ll x;
	ll a;
	string s;
	string s_ans;
	ll l_ans = 0;
	double d_ans = 0;
	
	cin >> x >> n;

	V p(n);
	vector<bool> z(101, false);
	rep(i, n) {
		cin >> p[i];
		z[p[i]] = true;
	}
	sort(ALL(p));

	ll pos = x;
	ll a1 = -1, a2 = 101;
	while (pos>=0) {
		if (!z[pos]) {
			a1 = pos;
			break;
		}
		pos--;
	}
	pos = x;
	while (pos <= 100) {
		if (!z[pos]) {
			a2 = pos;
			break;
		}
		pos++;
	}

	if ((x - a1) > (a2 - x)) {
		l_ans = a2;
	}
	else {
		l_ans = a1;
	}


	cout << l_ans << "\n";
}

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

	solve_abc_c();

	return 0;
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
int d=365, n=26;
int c[27];
int s[366][27];
int a[366];
int ans[366]={};
int last[27]={};
void Main(){
    cin >> d;
    For(i,1,n+1) cin >> c[i];
    For(i,1,d+1) For(j,1,n+1) cin >> s[i][j];
    For(i,1,d+1) cin >> a[i];
    For(i,1,d+1){
        ans[i] = ans[i-1] + s[i][a[i]];
        last[a[i]] = i;
        For(j,1,n+1){
            ans[i] -= (i-last[j]) * c[j];
        }
    }
    For(i,1,d+1) cout << ans[i] << endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

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

int main() {
  int n, m, ok = 0, ng = 0;
  cin >> n >> m;
  vector<int> res(n, 0), wa(n, 0);
  for (int i = 0; i < m; i++) {
    int x;
    string y;
    cin >> x >> y;
    if (res.at(x - 1) == 1) {
      continue;
    }
    else {
      if (y == "AC") {
        ok++;
        res.at(x - 1) = 1;
      }
      else {
        wa.at(x - 1)++;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (res.at(i) == 0) {
      continue;
    }
    else {
      ng += wa.at(i);
    }
  }
  cout << ok << " " << ng;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n; cin >> n;
  vector<int> S(n);
  for (int i = 0; i < n; i++) {
    cin >> S[i];
  }

  int q; cin >> q;
  int t, ans = 0;
  for (int i = 0; i < q; i++) {
    cin >> t;
    for (int j = 0; j < n; j++) {
      if (S[j] == t) {
        ans++;
        break;
      }
    }
  }
  cout << ans << endl;
}




Measured memory_bytes: 3136
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using ll = long long;

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


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

using namespace std;

int main()
{
    int a, b;

    cin >> a >> b;

    int ans = -1;

    for (int x = 1; x <= 1000000; x++)
    {
        if (floor(0.08 * x) == a && floor(0.1 * x) == b)
        {
            ans = x;
            break;
        }
    }

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

typedef struct p{
	int n;
	double t;
}P;
int comp(const void *p,const void *q){
	P *a=(P*)p,*b=(P*)q;
	int x=a->t*100,y=b->t*100;
	return x-y;
}
P x[8],y[30];
int main(){
	int i,j;
	
	for(i=0;i<3;i++){
		for(j=0;j<8;j++)scanf("%d%lf",&x[j].n,&x[j].t);
		qsort(x,8,sizeof(P),comp);
		printf("%d %.2lf\n",x[0].n,x[0].t);
		printf("%d %.2lf\n",x[1].n,x[1].t);
		//for(j=0;j<8;j++)printf("  %d %l0.2f\n",x[j].n,x[j].t);
		//printf("\n");
		for(j=2;j<8;j++)y[i*6+j-2]=x[j];
	}
	qsort(y,18,sizeof(P),comp);
	printf("%d %.2lf\n",y[0].n,y[0].t);
	printf("%d %.2lf\n",y[1].n,y[1].t);
		
	return 0;
}

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

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

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
    map<ll,ll> mp;
    ll s=0;
    for(int i = 0; i < n; i++) {
        int a;
        cin >> a;
        s+=a;
        mp[a]++;
    }
    ll q;
    cin >> q;
    vector<ll> b(q);
    vector<ll> c(q);
    for(int i = 0; i < q; i++) {
        cin >> b[i] >> c[i];
    }


    for(int i = 0; i < q; i++) {
        s+=(c[i]-b[i])*mp[b[i]];
        mp[c[i]]+=mp[b[i]];
        mp[b[i]]=0;
        cout << s << "\n";
    }

    return 0;
}

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

int main(void){
    int a, b, k, i;
  	cin>>a>>b>>k;
  	i=a;
    while(i<=a+k-1 && i<=b){
        cout<<i<<endl;
        i++;
    }
    if(i-1<b-k+1){
        i=b-k+1;
    }
        while(i<=b){
            cout<<i<<endl;
            i++;
        }
}


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


using namespace std;




int main(void) {
    int N, M;
    cin >> N >> M;
    vector<int> H(N + 1);
    vector<vector<int>> graph(N + 1);
    for (int i = 1; i <= N; i++) {
        cin >> H[i];
    }

    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    int ans = 0;
    for (int i = 1; i <= N; i++) {
        int h = H[i];
        bool good = true;
        for (auto e : graph[i]) {
            if (h <= H[e]) {
                good = false;
                break;
            }
        }

        if (good) {
            ans++;
        }
    }
    cout << ans << endl;
}


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

# define pb push_back
# define fr first
# define sc second
# define mk make_pair

using namespace std;

const int inf = 1e9 + 7;
const int N = 1e6 + 5;

typedef long long ll;

int n, a[N], b[N], c[N], ans;

int main()
{
      cin >> n;

      for(int i = 1; i <= n; i ++)
      {
            cin >> a[i];
            if(c[a[i]])
                  a[i] = 24 - a[i];
            if(c[a[i]])
                  ans = inf;
            c[a[i]] ++;
      }

      if(ans == inf)
      {
            cout << 0 << endl;
            return 0;
      }

      for(int mask = 0; mask < (1 << 13); mask ++)
      {
            for(int i = 1; i <= n; i ++)
            {
                  int j = mask & (1 << a[i]);
                  if(j) b[i] = 24 - a[i];
                  else b[i] = a[i];
            }
            int res = inf;
            for(int i = 1; i <= n; i ++)
                  for(int j = i + 1; j <= n; j ++)
                        res = min(res, abs(b[i] - b[j]));

            for(int i = 1; i <= n; i ++)
            {
                  int mn = inf;
                  mn = min(a[i], 24 - a[i]);
                  res = min(res, mn);
            }

            ans = max(ans, res);
      }

      cout << ans << endl;
}


Measured memory_bytes: 4352
/**Hey, What's up?*/

#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
vector<long long>v;
map<string,long long>mp;
int main()
{
    fastio;
    long long a=0,b=0,c,d,e,f=0,l,g,m,n,k,i,j,t,p,q;
    cin>>n;
    f=0;
    string s;
    for(i=0;i<n;i++){
        cin>>s;
        mp[s]++;
        f=max(f,mp[s]);

    }
    for(auto it:mp){
        if(it.second==f)cout<<it.first<<'\n';
    }

    return 0;
}


Measured memory_bytes: 23936
#include <iostream>
using namespace std;
const int MAX=100000;
typedef long long ll;

int n, k;
ll T[MAX];

int check(ll P) {
  int i=0;
  for (int j=0; j<k; j++) {
    ll s=0;
    while (s+T[i]<=P) {
      s+=T[i];
      i++;
      if (i==n) {
        return n;
      }
    }
  }
  return i;
}
int solve() {
  ll left=0;
  ll right=100000*10000;
  ll mid;
  while (right-left>1) {
    mid=(left+right)/2;
    int v=check(mid);
    if (v>=n) {
      right=mid;
    } else {
      left=mid;
    }
  }
  return right;
}
int main() {
  cin>>n>>k;
  for (int i=0; i<n; i++) {
    cin>>T[i];
  }
  ll ans=solve();
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3856
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main(){
	int n;
	cin>>n;
	ll a=0,b=0;
	while(n--){
		int c,e;char d;
		cin>>c>>d>>e;
		if(d=='(')a+=e;
		else b+=e;
		if(a==b)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
}

Measured memory_bytes: 1156
while 1:
    l = int(input())
    if l == 0:
        break

    money = []
    for _ in range(12):
        m, n = map(int, input().split())
        money.append(m-n)

    total = 0
    for i, p in enumerate(money):
        total += p
        if total >= l:
            print(i+1)
            break
    else:
        print("NA")



Measured memory_bytes: 5612
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <climits>
#include <cmath>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
using namespace std;

#define pb push_back
#define fst first
#define snd second

typedef long long ll;
typedef pair<int,int> pii;
template<typename T> using min_queue=priority_queue<T,vector<T>,greater<T>>;

const ll MOD=1e9+7;

int N,K;

inline ll pw(ll a, ll b) {
  a%=MOD;
  ll res=1;
  for(;b;b>>=1) {
    if (b&1) res=res*a%MOD;
    a=a*a%MOD;
  }
  return res;
}


ll fac[4020],ifac[4020];

inline ll choose(int a, int b) {
  if (b<0 || b>a) return 0;
  return fac[a]*ifac[b]%MOD*ifac[a-b]%MOD;
}

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

  cin>>N>>K;

  fac[0]=ifac[0]=1;
  for(int i=1;i<=4001;i++) fac[i]=fac[i-1]*i%MOD, ifac[i]=pw(fac[i],MOD-2);

  for(int i=1;i<=K;i++) cout<<choose(K-1,i-1)*choose(N-K+1,i)%MOD<<endl;

  return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#define NIL NULL
#define DEBUG

typedef struct node{
  struct node* parent;
  struct node* left;
  struct node* right;
  int k;
}Node;

Node* tree;

void insert(int);
void inorder(Node*);
void preorder(Node*);
int find(Node*,int);

int main(){
  int m,i,k,f;
  char s[10];

  scanf("%d",&m);

  for(i=0;i<m;i++){
    scanf("%s",s);
    if(s[0]=='i'){
      scanf("%d",&k);
      insert(k);
    }
    else if(s[0]=='p'){
      inorder(tree);
      printf("\n");
      preorder(tree);
      printf("\n");
    }
    else if(s[0]=='f'){
      scanf("%d",&k);
      f=find(tree,k);
      if(f) printf("yes\n");
      else printf("no\n");
    }
  }

  return 0;
}

void insert(int k){
  Node* y = NIL;
  Node* x = tree;
  Node* z;
  z=(Node *)malloc(sizeof(Node));
  z->k=k;
  z->left=NIL;
  z->right=NIL;

  while(x!=NIL){
    y=x;
    if(z->k < x->k ){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }
  z->parent = y;

  if(y==NIL) tree=z;
  else if(z->k < y->k) y->left=z;
  else y->right=z;
  return;
}

void inorder(Node* tree){
  if(tree != NIL){
    inorder(tree->left);
    printf(" %d",tree->k);
    inorder(tree->right);
  }
  return;
}

void preorder(Node* tree){
  if(tree != NIL){
    printf(" %d",tree->k);
    preorder(tree->left);
    preorder(tree->right);
  }
  return;
}

int find(Node* tree,int f){
  if(tree != NIL){
    if(tree->k == f) return 1;
    if(tree->k > f) return find(tree->left,f);
    else return find(tree->right,f);
  }
  else return 0;
}

Measured memory_bytes: 19364
#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
bool c[5];
int main(){
char a[5];
memset(c,0,sizeof(c));
cin>>a;
for(int i=0;i<3;i++){
    if(a[i]=='a'){c[0]=1;}
    if(a[i]=='b'){c[1]=1;}
    if(a[i]=='c'){c[2]=1;}
}
int j;
for( j=0;j<3;j++){
    if(c[j]==0){break;}
}
if(j==3){
    printf("Yes");
}
else{printf("No");}
return 0;

}




Measured memory_bytes: 256
#include<iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;
#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++)

int main() {
  int a, b, ans;
  cin >> a >> b;
  if (a == b) ans = a + b;
  else ans = max(a, b) * 2 - 1;
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
using namespace std;

#ifndef __gcd
long long __gcd(long long a, long long b){
    long long t = 0;
    while(b != 0){
        t = b;
        b = a % b;
        a = t;
    }
    return a;
}
#endif


int main() {
    long long a, b;
    cin >> a >> b;
    set<long long> x;
    for(long long i = 1; i*i <= min(a, b); i++){
        if(a % i == 0){
            if(b % i == 0){
                x.insert(i);
            }
            if(b % (a / i) == 0){
                x.insert(a / i);
            }
        }
        if(b % i == 0){
            if(a % i == 0){
                x.insert(i);
            }
            if(a % (b / i) == 0){
                x.insert(b / i);
            }
        }
    }
    vector<long long> r;
    for(auto& i : x){
        bool f = 1;
        for(auto& j : r){
            if(__gcd(i, j) != 1) {
                f = 0;
                break;
            }
        } 
        if(f) r.push_back(i);
    }
    cout << r.size() << '\n';
}

Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
int d[252];
int dp[252][252];
int Max;
int n;
int main() {
	while(scanf("%d",&Max),Max) {
		scanf("%d",&n);
		d[0]=d[n+1]=0;
		for(int i=1;i<=n;i++) {
			scanf("%d",&d[i]);
		}
		memset(dp,0,sizeof(dp));
		for(int i=0;i<n+2;i++) {
			for(int j=1;j<=Max;j++) {
				int p;
				p=min(i+j,n+1);
				p+=d[p];
				p=min(max(p,0),n+1);
				dp[i][p]=1;
			}
		}
		for(int k=0;k<n+2;k++) {
			for(int i=0;i<n+2;i++) {
				for(int j=0;j<n+2;j++) {
					if(dp[i][k]&&dp[k][j]) dp[i][j]=1;
				}
			}
		}
		bool OK=1;
		for(int i=0;i<=n;i++) {
			if(dp[0][i]&&!dp[i][n+1]) {OK=0;break;}
		}
		if(OK) printf("OK\n"); else printf("NG\n");
	}
}

Measured memory_bytes: 1268
#include <stdio.h>
#define MAX_N 201
#define MOD 998244353

int x[MAX_N], y[MAX_N], p[MAX_N];

int main(void)
{
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d%d", &x[i], &y[i]);
    p[0] = 1;
    for (int i = 0; i < n; i++)
        p[i + 1] = (p[i] << 1) % MOD;
    int ans = p[n] - n - 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < i; j++) {
            int cnt = 0;
            for (int k = 0; k < j; k++) {
                if ((x[i] - x[j]) * (y[i] - y[k]) == (x[i] - x[k]) * (y[i] - y[j]))
                    cnt++;
            }
            ans -= p[cnt];
            ans += MOD;
            ans %= MOD;
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstring>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
typedef pair<double,double>P_D;
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define reprev(i, n) for (int i = (int)n - 1; i >= 0; i--)
#define ALL(a)  (a).begin(),(a).end()
#define MAX 100100
#define MAX_N 200100
#define SENTINEL 2000000000
#define MAX_B 1001001
#define NIL -1
#define MOD 1000000007
#define INF 1 << 29
#define INFTY 1000000000000000000LL

int main(){
    int a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    int m=min(x,y);
    int ma=max(x,y);
    int z=(x>y)?(x-y)*a:(y-x)*b;
    int s_1=m*2*c+z;
    int s_2=x*a+y*b;
    int s_3=ma*2*c;
    cout<<min(s_1,min(s_2,s_3))<<endl;
}

Measured memory_bytes: 256
_, a, b, c, d = gets.split.map(&:to_i)
s = gets.chomp
if c < d
  if !s[a..d].match(/##/)
    puts 'Yes'
  else
    puts 'No'
  end
else
  if (s[b - 2..d].match(/\.\.\./) || s[b - 2..d].match(/\.\.\.$/)) && !s[a..c].match(/##/)
    puts 'Yes'
  else
    puts 'No'
  end
end

Measured memory_bytes: 2300
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int64_t dp[110][110];
int main() {
	int h, w; cin >> h >> w;
	string s[h]; rep(i,h) cin >> s[i];
	rep(i,h)rep(j,w) dp[i][j] = INF;
	priority_queue<tuple<int64_t, int, int>> que;
	if(s[0][0] == '.') {
		que.emplace(0, 0, 0);
		dp[0][0] = 0;
	} else {
		que.emplace(1, 0, 0);
		dp[0][0] = 1;
	}
	while(not que.empty()) {
		int cost, y, x;
		tie(cost, y, x) = que.top();
		que.pop();
		// cerr << y << " " << x << '\n';
		if(cost > dp[y][x]) continue;
		const int dy[] = {0, 1};
		const int dx[] = {1, 0};
		for(int d = 0; d < 2; ++d) {
			int ny = y + dy[d];
			int nx = x + dx[d];
			if(ny < 0 or h <= ny) continue;
			if(nx < 0 or w <= nx) continue;
			int nc = cost;
			if(s[y][x] == '.' and s[ny][nx] == '#') {
				++nc;
			}
			// cerr << nc << " " << ny << " " << nx << '\n';
			if(nc < dp[ny][nx]) {
				dp[ny][nx] = nc;
				que.emplace(nc, ny, nx);
			}
		}
	}
	// rep(i,h)rep(j,w) cerr << dp[i][j] << '\n';
	cout << dp[h - 1][w - 1] << '\n';
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
#define INF 1000000000
int n,ans=-INF;
int m[1005][1005],r[1005][1005],u[1005][1005];
int main(void){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            scanf("%d",&m[i][j]);
            r[i][j]+=m[i][j];
            u[i][j]+=m[i][j];
            r[i][j+1]+=r[i][j];
            u[i+1][j]+=u[i][j];
        }
    }
    for(int a=1;a<=n;a++){
        for(int i=1;i<=n;i++)for(int j=i;j<=n;j++)ans=max(ans,u[j][a]-u[i-1][a]);
        for(int b=a+1;b<=n;b++){
            int p=-INF;
            for(int i=1;i<=n;i++){
                ans=max(ans,p+u[i-1][a]+u[i-1][b]+r[i][b]-r[i][a-1]);
                p=max(p,r[i][b-1]-r[i][a]-u[i-1][b]-u[i-1][a]);
            }
        }
    }
    for(int a=1;a<=n;a++)for(int i=1;i<=n;i++)for(int j=i;j<=n;j++)ans=max(ans,r[a][j]-r[a][i-1]);
    printf("%d\n",ans);
}



Measured memory_bytes: 6744
def Input():
    return mapt(int, input().split(" "))


def calc(i, h):
    return all(h[i] >= h[j] for j in range(i))


def main():
    data = [int(input()) for _ in range(5)]
    k = int(input())
    print("Yay!" if k >= data[-1] - data[0] else ":(")


main()

Measured memory_bytes: 9104
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <cstdlib>
#define int long long
using namespace std;

int n, a, b;
int h[100000];

bool check(int k) {
	int i;
	int cnt = 0;
	
	for (i = 0; i < n; i++) {
		int hp = h[i] - k * b;
		if (hp <= 0) continue;
		cnt += (hp + a - b - 1) / (a - b);
	}
	return cnt <= k;
}

signed main() {
	int i;
	
	cin >> n >> a >> b;
	for (i = 0; i < n; i++) cin >> h[i];
	
	int st = 0, ed = 1000000007, mid; //xxxooo, (st, ed]
	while (ed - st >= 2) {
		mid = (st + ed) / 2;
		if (check(mid)) {
			ed = mid;
		}
		else {
			st = mid;
		}
	}
	cout << ed << endl;
	return 0;
}

Measured memory_bytes: 1152
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

long long int INF = 1e18;
using namespace std;

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

long long int R[210000], R_max[210000], R_min[210000];

int main(){
	
	int n;
	cin >> n;
	
	for(int i = 0; i < n; i++){
		cin >> R[i];
	}
	
	R_min[0] = R[0];
	for(int i = 1; i < n; i++){
		R_min[i] = min(R_min[i - 1], R[i]);
	}
	
	R_max[n - 1] = R[n - 1];
	for(int i = n - 2; i >= 0; i--){
		R_max[i] = max(R_max[i + 1], R[i]);
	}
	
	long long int ans = -INF;
	for(int i = 0; i < n - 1; i++){
		ans = max(ans, R_max[i + 1] - R_min[i]);
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 7804
use std::io::*;
use std::str::FromStr;
use utils::*;

pub fn main() {
    let i = stdin();
    let mut o = Vec::new();
    run(i.lock(), &mut o);
    stdout().write_all(&o).unwrap();
}

fn run<R: BufRead, W: Write>(i: R, o: &mut W) {
    let mut i = CpReader::new(i);
    let (n, x) = i.read2::<usize, usize>();
    let a = i.read_vec::<usize>(n);
    writeln!(o, "{}", solve(x, a)).unwrap();
}
fn solve(mut x: usize, mut a: Vec<usize>) -> usize {
    a.sort();

    let mut r = 0;
    for &a in &a {
        if x < a {
            return r;
        }
        x -= a;
        r += 1;
    }
    if x != 0 {
        r -= 1;
    }
    r
}

mod utils {
    use super::*;

    pub struct CpReader<R: BufRead> {
        r: R,
        s: String,
    }

    macro_rules! fn_read {
        { $f:ident($($t:ident),*) } => {
            #[allow(dead_code)]
            pub fn $f<$($t: FromStr),*>(&mut self) -> ($($t),*) {
                let i = &mut self.read_line().split(' ');
                ($(read_next::<$t,_>(i)),*)
            }
        };
    }

    impl<R: BufRead> CpReader<R> {
        pub fn new(r: R) -> Self {
            CpReader {
                r: r,
                s: String::new(),
            }
        }
        pub fn read_line(&mut self) -> &str {
            self.s.clear();
            self.r.read_line(&mut self.s).unwrap();
            self.s.trim()
        }

        fn_read! { read2(T1, T2) }
        fn_read! { read3(T1, T2, T3) }
        fn_read! { read4(T1, T2, T3, T4) }
        fn_read! { read5(T1, T2, T3, T4, T5) }

        pub fn read_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            self.read_line()
                .split(' ')
                .take(n)
                .map(|x| x.parse().ok().unwrap())
                .collect()
        }
    }
    fn read_next<'a, T: FromStr, I: Iterator<Item = &'a str>>(i: &mut I) -> T {
        i.next().unwrap().parse().ok().unwrap()
    }
}


Measured memory_bytes: 4352
#define _USE_MATH_DEFINES

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <climits>
typedef long long ll;
using namespace std;

int main(void){
  double a,b,x;
  cin>>a>>b>>x;

  double tans;

  if(a*a*b>x*2){
    tans=(a*b*b)/2/x;
  }
  else{
    tans=(a*a*b-x)*2/(a*a*a);
  }
  
  double ans=atan(tans)/M_PI*2*90;

  printf("%.6f",ans);

  return 0;
}


Measured memory_bytes: 256
// #pragma GCC optimize("O3", "unroll-loops")
// #pragma GCC target("avx2")
 
#include <bits/stdc++.h>
using namespace std;
 
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
// #define ost tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
#define    int                      long long int
#define    ld                       long double
#define    f(i,j,n)                 for(int i = j; i <= n; i++)
#define    r(i,n,j)                 for(int i = n; i >= j; i--)
#define    mod                      1000000007
#define    speed                    ios_base::sync_with_stdio(false);
#define    upp                      cin.tie(NULL),cout.tie(NULL);
#define    pb                       push_back
#define    mp                       make_pair
#define    T                        int ttt; cin >> ttt; while(ttt--)
#define    ff                       first
#define    ss                       second
#define    all(container)            container.begin() , container.end()
#define    sz(container)            (int)container.size()
#define    pii                      pair <int , int>
#define    sp(x)                    setprecision(x)
#define    bp(x)                    __builtin_popcount(x)
#define    endl                     "\n"

int power(int x, int y, int p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0; 
    while (y > 0)  
    {     
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res; 
}

int32_t main()
{
    speed upp
    int n,k;
    vector<int>v;
    cin>>n>>k;
    int a[n+1],x;
    f(i,1,n)
        cin>>a[i];
    v.pb(1);
    x=a[1];
    set<int>s;
    s.insert(1);
    while(s.find(x)==s.end())
    {
        v.pb(x);
        s.insert(x);
        x=a[x];
    }
    int i=0;
    while(v[i]!=x)
        i++;
    
    vector<int>vv;
    if(sz(v)>k)
        cout<<v[k];
    else
    {
        k-=(i-1);
        f(j,i,sz(v)-1)
            vv.pb(v[j]);
        k=k%sz(vv);
      
        k--;
        if(k<0)
            k+=sz(vv);
        cout<<vv[k];
    }
}


Measured memory_bytes: 16592
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll one = 1;
const ll INF = 9223372036854775807; //10^18
const int inINF = 2147483647; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    int N, Q;
    cin >> N >> Q;
    dsu d(N);
    int a, b, q;
    for (int i = 0; i < Q; i++) {
        cin >> q >> a >> b;
        if(q == 0){
            d.merge(a, b);
        }
        else{
            if(d.same(a, b)){
                printf("%d\n", 1);
            }
            else{
                printf("%d\n", 0);
            }
        }
    }

}

Measured memory_bytes: 3976
s=input()
from bisect import bisect_left as bl,bisect_right as br
if len(s)==26:
  if s=="zyxwvutsrqponmlkjihgfedcba":print(-1);exit()
  f=s[-1]
  p=[s[-1]]
  for i in range(2,26):
    if s[-i]>f:
      f=s[-i];p.append(f)
    else:print(s[:-i]+p[bl(p,s[-i])]);exit()
  print(chr(ord(s[0])+1))
else:
  f=sorted(list(set(list("aqzxswedcvfrtgbnhyujmkilop"))-set(list(s))))
  print(s+f[0])

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define debug(x)        cout<<#x<<" :"<<x<<endl;
#define ff              first
#define ar              array
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define f(i,n)          for(int i=0;i<n;i++)
#define MOD             1000000007
#define pi              3.14159265
#define umii            unordered_map<int,int>
#define umci            unordered_map<char,int>
#define umsi            unordered_map<string,int>

void k_007()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#ifndef ONLINE_JUDGE
	freopen("ip1.txt", "r", stdin);
	freopen("op1.txt", "w", stdout);
#endif
}
bool sortbysec(const pair<int, int> &a,
               const pair<int, int> &b);
int gcd(int a, int b) ;
int prime(int n);
int power(int x, int y);
int lcm(int a, int b);
int maxf(int a, int b) {if (a > b) return a; else return b;}
int diff(int a, int b) {return abs(a - b);}
int mul(int a, int b) { return (a * b) % mod; }
int32_t main()
{
	k_007();
	int n;
	cin >> n;
	int a[n];
	int ans = 0;
	vector<pii> v;
	f(i, n)
	{
		cin >> a[i];
		v.pb(mp(a[i], i + 1));
	}

	sort(v.begin(), v.end());

	for (int i = 0; i < v.size(); i++)
	{
		cout << v[i].ss << " ";
	}
}

bool sortbysec(const pair<int, int> &a, const pair<int, int> &b)
{
	return (a.second < b.second);
}
int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int prime(int n) {
	int flag = 1;
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0) {flag = 0; break;}
	}
	return flag;
}
int power(int x, int y)
{
	if (y == 0)
		return 1;
	else if (y % 2 == 0)
		return ((power(x, y / 2) % MOD) * ( power(x, y / 2) % MOD)) % MOD;
	else
		return ((x % MOD) * (power(x, y / 2) % MOD) * (power(x, y / 2) % MOD)) % MOD;
}
int lcm(int a, int b)
{
	return (a * b) / gcd(a, b);
}

Measured memory_bytes: 5856
#include<bits/stdc++.h>
#define ll long long
using namespace std;
main(){
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        long long a,b,c,d;
        cin >> a >> b >> c >> d;
        if(d < b || a < b) {
            cout<<"No"<<endl;
            continue;
        }
        if(a % __gcd(b,d) + b - __gcd(b,d) <= c){
            cout << "Yes"<<endl;
            continue;
        }
        cout << "No"<<endl;
        continue;
    }

}


Measured memory_bytes: 256