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

using namespace std;

const int N = 200010;
const int inf = 2e9;

int tab[21][N];
int a[N];
int n;

int query(int l, int r) {
  if (l < 0 || l >= n || r < 0 || r >= n) {
    return -inf;
  }
  int k = __lg(r - l + 1);
  return min(tab[k][l], tab[k][r - (1 << k) + 1]);
}

int find_left(int rr, int v) {
  int lo = -1, hi = rr + 1;
  while (hi - lo > 1) {
    int mi = (lo + hi) >> 1;
    if (query(mi, rr) < v) {
      lo = mi;
    } else {
      hi = mi;
    }
  }
  return lo + 1;
}

int find_right(int ll, int v) {
  int lo = ll - 1, hi = n;
  fprintf(stderr, "(%d, %d]\n", lo, hi);
  while (hi - lo > 1) {
    int mi = (lo + hi) >> 1;
    fprintf(stderr, "querying[%d,%d] : %d\n", ll, mi, query(ll, mi));
    if (query(ll, mi) < v) {
      hi = mi;
    } else {
      lo = mi;
    }
  }
  return hi - 1;
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    tab[0][i] = a[i];
  }
  int k = __lg(n);
  for (int t = 0; t < k; t++) {
    int l = 1 << t;
    for (int i = 0; i < n - 2 * l + 1; i++) {
      tab[t + 1][i] = min(tab[t][i], tab[t][i + l]);
    }
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    int l = find_left(i - 1, a[i]);
    int r = find_right(i + 1, a[i]);
    ans += 1ll * a[i] * (i - l + 1) * (r - i + 1);
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 16640
S = input()
T = input()

ms = [0]
for s in S:
    if s == 'A':
        ms.append(ms[-1] + 1)
    else:
        ms.append(ms[-1] - 1)

mt = [0]
for t in T:
    if t == 'A':
        mt.append(mt[-1] + 1)
    else:
        mt.append(mt[-1] - 1)

q = int(input())
for _ in range(q):
    a, b, c, d = map(int, input().split())
    if (ms[b] - ms[a - 1]) % 3 == (mt[d] - mt[c - 1]) % 3:
        print('YES')
    else:
        print('NO')

Measured memory_bytes: 11500
#include <iostream>
#include <cstdio>
#include <cstring> 
using namespace std;
int n, m, k;
int cnt[15][1005];
char mp[15][1005];
bool vis[1005];
int cut[20], top;
int ans = 0x7f7f7f7f;
int cal(int x1, int x2, int y1, int y2) {
	return cnt[x2][y2] - cnt[x2][y1 - 1] - cnt[x1 - 1][y2] + cnt[x1 - 1][y1 - 1];
}
void dfs(int pos) {
	cut[++top] = pos;
	if (pos == n) {
		memset(vis, 0, sizeof(vis)); 
		int sx, sy;
		int lst = 0;
		int tmp = 0;
//		cout << "**********" << endl;
		for (int j = 1; j <= m; j++) {
			for (int i = 1; i <= top; i++) {
//				cout << cut[i] << " ";
				sx = cut[i - 1] + 1;
				sy = lst + 1;
//				cout << sx << " " << sy << ", " << cut[i] << " " << j << endl;
//				cout << cal(sx, cut[i], sy, j) << endl;
				if (cal(sx, cut[i], sy, j) > k) {
					if (lst == j - 1) {
						top--;
						return;
					} else {
//						cout << j << endl;
						sy = j;
						if (!vis[j - 1]) {
							tmp++;
							vis[j - 1] = 1;
						}
					}
				}
			}
			if (vis[j - 1]) lst = j - 1;
		}// cout << endl;
//		cout << tmp << " " << top << endl; 
		ans = min(ans, tmp + top - 1);
		top--;
		return;
	}
	for (int i = pos + 1; i <= n; i++) {
		dfs(i);
	}
	top--;
}
int main() {
	scanf("%d%d%d", &n, &m, &k);
	for (int i = 1; i <= n; i++) {
		scanf("%s", mp[i] + 1); 
		for (int j = 1; j <= m; j++) {
			cnt[i][j] = cnt[i - 1][j] + cnt[i][j - 1] - cnt[i - 1][j - 1] + mp[i][j] - '0';
		}
	}
//	for (int i = 1; i <= n; i++) {
//		for (int j = 1; j <= m; j++) {
//			cout << cnt[i][j] << " ";
//		} cout << endl;
//	}
	for (int i = 1; i <= n; i++) {
		dfs(i);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
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 INF = 1e9;
const ll MOD = 1e9 + 7;


int main(){
    int h, w, k;
    cin >> h >> w >> k;
    vector<vector<char>> m(h, vector<char>(w));
    rep(i, h){
        rep(j, w) cin >> m[i][j];
    }

    int ans = 0;

    for(int r=0; r<(1<<h); r++){
        for(int c=0; c<(1<<w); c++){
            auto tmp = m;
            rep(i, h){
                if((r>>i)&1){
                    rep(j, w) tmp[i][j] = 'x';
                }
            }
            rep(i, w){
                if((c>>i)&1){
                    rep(j, h) tmp[j][i] = 'x';
                }
            }

            int sum = 0;
            rep(i, h){
                rep(j, w) sum += (tmp[i][j] == '#');
            }

            ans += (sum == k);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const ll INF = 1LL<<60;
const int ny[4] = {-1,1,0,0}, nx[4] = {0,0,-1,1};
int sy,sx,gy,gx;

int main(){
  int n; cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  map<int,int> cnt;
  cnt[1]++;
  int now = 1, ans = 0;
  while(true){
    ans++;
    now = a[now-1];
    cnt[now]++;
    if(now == 2){
      cout << ans << endl;
      return 0;
    }
    if(cnt[now] == 2){
      cout << -1 << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 5376
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int R = sc.nextInt();
        int C = sc.nextInt();
        int K = sc.nextInt();
        int[][] V = new int[R][C];
        for (int i = 0; i < K; i++) {
            int r = sc.nextInt();
            int c = sc.nextInt();
            int v = sc.nextInt();
            V[--r][--c] = v;
        }

        long[][][] dp = new long[R][C][4];
        for (int i = 0; i < R; i++) {
            for (int j = 0; j < C; j++) {
                for (int k = 0; k <= 3; k++) {
                    dp[i][j][k] = -1;
                }
            }
        }
        dp[0][0][3] = 0;
        if (V[0][0] > 0) dp[0][0][2] = V[0][0];
        for (int i = 0; i < R; i++) {
            for (int j = 0; j < C; j++) {
                for (int k = 0; k <= 3; k++) {
                    if (dp[i][j][k] == -1) continue;
                    if (i+1 < R) {
                        // i+1
                        long max = 0;
                        for (int kk = 0; kk <= 3; kk++) {
                            max = Math.max(max,dp[i][j][kk]);
                        }
                        if (V[i+1][j] > 0) {
                            dp[i+1][j][2] = Math.max(dp[i+1][j][2],max+V[i+1][j]);
                        }
                        dp[i+1][j][3] = Math.max(dp[i+1][j][3],max);
                    }
                    if (j+1 < C) {
                        // j+1
                        if (V[i][j+1] > 0 && k > 0) {
                            dp[i][j+1][k-1] = Math.max(dp[i][j+1][k-1],dp[i][j][k]+V[i][j+1]);
                        }
                        dp[i][j+1][k] = Math.max(dp[i][j+1][k],dp[i][j][k]);
                    }
                }
            }
        }

        long ans = 0;
        for (int k = 0; k <= 3; k++) {
            ans = Math.max(ans,dp[R-1][C-1][k]);
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 697808
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
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>;

int dp[1000005][2];

signed main()
{

ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    string a;
    cin>>a;
    int n=a.length();
    reverse(a.begin(),a.end());
    a="#"+a;
    int ans=0;
    fill_n(&dp[0][0],1000005*2,1e17);
    dp[0][0]=0;
    for(int i=1;i<=n;i++)
    {
        int z=a[i]-'0';
        dp[i][0]=min(dp[i][0],dp[i-1][0]+z);
        dp[i][1]=min(dp[i][1],dp[i-1][0]+(10-z));
        z++;
        dp[i][0]=min(dp[i][0],dp[i-1][1]+z);
        dp[i][1]=min(dp[i][1],dp[i-1][1]+(10-z));
    }
    int mn=min(dp[n][0],dp[n][1]+1);
    cout<<mn;
} 



Measured memory_bytes: 16968
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int a = Integer.parseInt(sc.next());
		String s = sc.next();

		int idx;

		if (a >= 3200) {
			System.out.println(s);
		} else {
			System.out.println("red");
		}


	}

}


Measured memory_bytes: 22740
# include <bits/stdc++.h>
  using namespace std;
# define res(a,b,c) for (int64 a=b ; a<c ; a++)
# define ress(a,b)  for (auto a = b.begin() ; a!=b.end() ; a++) 
# define all(con) con.begin() , con.end()
# define INF (int)1e9  
# define MOD 1000000007
# define pb push_back   
# define mp make_pair
# define f first
# define s second   
# define MAX numeric_limits<int>::max() 
# define MIN numeric_limits<int64>::min()
# define mymin -1000000000000000001
# define mymax 1000000000000000001
# define watch(x) cout<<(#x)<<" is "<<(x)<<endl
# define in(x) cin>>(x)
# define inn(x,y) cin>>(x)>>(y)  
# define out(x) cout<<(x)<<"\n"  
# define outt(x,y) cout<<(x)<<" "<<(y)<<"\n"  
typedef long long int int64;
typedef unsigned long long int uint64;
typedef vector<int64> vi;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef pair<int64,int64> pi; 
bool doubleSame(double a, double b)
{ const double eps = 1e-15; return ( abs(a-b)<= eps*abs(a) ); }

int main()
{
	int a,b;
	string str;
	cin>>a;
	cin>>str;
	cin>>b;
	if(str=="+")
		cout<<(a+b)<<"\n";
	else
		cout<<(a-b)<<"\n";
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define ALL(name) name.begin(),name.end()
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

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

    int N;
    cin >> N;
    int ans = 0;
    for(int i = 1; i <= N; ++i) {
        if(to_string(i).length() % 2 != 0) { ans++; }
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 256
def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)
def lcm(a,b):
    return a*b//gcd(a,b)

a,b,c,d = map(int,input().split())
l = lcm(c,d)
ans = b-a+1
ans-=b//c
ans-=b//d
ans+=b//l
ans+=(a-1)//c
ans+=(a-1)//d
ans-=(a-1)//l
print(ans)


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int x,a,b;
  cin>>x>>a>>b;
  cout<<(abs(x-a)<abs(x-b) ? "A" : "B")<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;

template <typename Tp> inline void getint(Tp &num){
	register int ch, neg = 0;
	while(!isdigit(ch = getchar())) if(ch == '-') neg = 1;
	num = ch & 15;
	while(isdigit(ch = getchar())) num = num * 10 + (ch & 15);
	if(neg) num = -num;
}

int N, K;

int main(){
	getint(N), getint(K);
	return printf("%d\n", N - K + 1), 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>

using namespace std;

typedef long long ll;

int N;
string S;

ll cnt[4000 + 10][3];//r0 g1 b2
ll D[4000 + 10];

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

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 3; j++)
			cnt[i + 1][j] = cnt[i][j];
		if (S[i] == 'R')cnt[i + 1][0]++;
		if (S[i] == 'G')cnt[i + 1][1]++;
		if (S[i] == 'B')cnt[i + 1][2]++;
	}

	for (int i = 0; i < N; i++) {
		for (int l = i - 1, r = i + 1; l >= 0 && r < N; l--, r++) {
			if (S[l] != S[i] && S[i] != S[r] && S[l] != S[r])D[i]++;
		}
	}

	ll ans = 0;
	const int aite[3][2] = { {1, 2}, {2, 0}, {0, 1} };
	for (int i = 0; i < N; i++) {
		int c;
		if (S[i] == 'R')c = 0;
		if (S[i] == 'G')c = 1;
		if (S[i] == 'B')c = 2;
		ans += (cnt[i][aite[c][0]] * (cnt[N][aite[c][1]] - cnt[i + 1][aite[c][1]])) +
			(cnt[i][aite[c][1]] * (cnt[N][aite[c][0]] - cnt[i + 1][aite[c][0]]))
			- D[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3760
import Control.Applicative
import Control.Monad
import Control.Monad.ST
-- import qualified Data.ByteString as BS
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
--import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
import Data.Array
--import Data.Array.Unboxed
--import Data.Array.IArray
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
import GHC.ST
-- import System.IO.Unsafe
 
-- templete
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
getDoubles = map readDouble . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
tjoin :: (Show a, Show b) => (a, b) -> String
tjoin (x, y) = show x ++ (' ' : show y)
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
infixl 7 `divCeil`
divCeil :: Integral a => a -> a -> a
x `divCeil` y = (x+y-1) `div` y
coverC :: Ord a => (a, a) -> a -> Bool
coverC (l,r) x = l<=x && x<=r
coverH :: Ord a => (a, a) -> a -> Bool
coverH (l,r) x = l<=x && x<r
ibsearch :: (Int -> Bool) -> (Int,Int) -> Int
ibsearch f (ok,ng) = if abs (ok-ng) <= 1 then ok else let mid = (ok + ng) `div` 2 in ibsearch f (if f mid then (mid,ng) else (ok,mid))
-- templete


main = getInt >>= \n -> replicateM n getInts >>= print . (n-) . length . group . sort . map (apply3 (,,) . sort)



Measured memory_bytes: 5140
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919810893LL;
const ll MOD = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}

ll N, M;
ll L[101010];
ll R[101010];
ll C[101010];

vector<P>path[101010];

ll cost[101010];

ll solve(){
    rep(i, 101010)cost[i] = INF;
    priority_queue<P, vector<P>, greater<P> >Q;
    Q.push(P(0, 1));
    ll r = 1;
    while(!Q.empty()){
        ll cst = Q.top().first;
        ll idx = Q.top().second;
        Q.pop();
        if(r > idx)continue;
        if(cost[idx] < INF)continue;
        cost[idx] = cst;
        for(; r <= idx; r++){
            rep(i, path[r].size()){
                Q.push(P(cst + path[r][i].first, path[r][i].second));
            }
        }
    }
    if(cost[N] < INF)return cost[N];
    return -1;
}

int main(){

    cin >> N >> M;
    rep(i, M){
        cin >> L[i] >> R[i] >> C[i];
        path[L[i]].push_back(P(C[i], R[i]));
    }
    cout << solve() << endl;

    return 0;
}

Measured memory_bytes: 10488
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////
ll memoh[1000000];
ll hpow(ll x,ll y){
    if(memoh[y]!=0){
        return memoh[y];
    }
    ll ans=1;
    ll i=x;
    if(y==0)return memoh[y]=1;
    ll yy=y;
    while(y>0){
        if(y%2==1){
            ans=(ans*i)%i_7;
        }
        i=(i*i)%i_7;
        y=y/2;
        
    }
    return memoh[yy]=ans;
}

int main(){
    ll n;cin>>n;
    ll c[n];
    rep(i,0,n-1)cin>>c[i];
    sort(c,c+n);
    ll ans=0;
    rep(i,0,n-1)ans+=(c[i]*(((hpow(2,2*n-2))%i_7*(n+1-i))%i_7))%i_7;
    cout<<ans%i_7<<endl;
    
    
    return 0;
}


Measured memory_bytes: 3840
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <numeric>
#include <vector>
#include <queue>
#include <map>
typedef unsigned long long ull;
typedef long long ll;
#define MAX 200005
#define __TRUE "Yes"
#define __FALSE "No"
using namespace std;

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(abs(a-c)<=d || (abs(a-b)<=d && abs(b-c)<=d) ) {
    cout << __TRUE << endl;
  }else {
    cout << __FALSE << endl;
  }
  return 0;
}

Measured memory_bytes: 256
h, w = map(int, input().split())
s = []
for _ in range(h):
	s.append(input())
dp = [[0] * w] * h
p = 10**9 + 7
for i in range(h):
	for j in range(w):
		if s[i][j]=="#":
			dp[i][j] = 0
		elif i==0 and j==0:
			dp[i][j] = 1
		elif i==0:
			dp[i][j] = dp[i][j-1]
		elif j==0:
			dp[i][j] = dp[i-1][j]
		else:
			dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % p
print(dp[h-1][w-1])

Measured memory_bytes: 4212
#include<bits/stdc++.h>
using namespace std;
#define ll long long
string solve(string a,string b,int n,int m)
{
    int dp[n+1][m+1]{};
    for(int i=1;i<=n;i++)
    {  int g=0;
        for(int j=1;j<=m;j++)
        {
            if(a[i-1]==b[j-1])
            {
                g=dp[i-1][j-1]+1;
            }
            if(dp[i-1][j]<g)
            dp[i][j]=g;
            else if(dp[i-1][j]>=g)
            {
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    int k=0;
   string c;
   int j=m;
   for(int i=n;i>0;i--)
   {
       k=dp[i][j];
       
    while(dp[i][j]==k && j>=0)
    {
        j--;
    }  
    j++;
   
    if(dp[i][j]!=dp[i-1][j])
    {
        c+=a[i-1];
       
    } 
   }
   reverse(c.begin(),c.end());
    return c;

}
int main()
{
    string a,b;
    cin>>a>>b;
    int n=a.length();
    int m=b.length();
    string c=solve(a,b,n,m);
    cout<<c;
 return 0;
}

Measured memory_bytes: 38772
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e18+10;

/*----------------------------------------------*/


signed main(){
  int n,k;
  cin>>n>>k;
  vi a(n);
  rep(i,n)cin>>a[i];

  while(k--){
    vi b(n,0);
    int all=0;
    int mae=0,ushi=-1;
    vector<pair<int,int>> memo(2*n); //second:0(mae),1(ushi)
    rep(i,n){
      int x=max(0ll,i-a[i]),y=min(i+a[i],n-1);
      memo[2*i]=(make_pair(x,0));
      memo[2*i+1]=(make_pair(y,1));
    }
    sort(all(memo));

    int cnt=0;
    rep(i,n){
      int x=upper_bound(all(memo),make_pair(i,0ll))-lower_bound(all(memo),make_pair(i,0ll));
      cnt+=x;
      b[i]=cnt;
      int y=upper_bound(all(memo),make_pair(i,1ll))-lower_bound(all(memo),make_pair(i,1ll));
      cnt-=y;
    }



    bool ok=1;
    rep(i,n){
      a[i]=b[i];
      if(a[i]<n){
        ok=0;
      }
    }

    if(ok) break;

  }

  rep(i,n){
    cout<<a[i];
    if(i<n-1) cout<<' ';
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 12772
#include <cstdio>
#include <cstring>
#include <utility>
#include <typeinfo>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <string>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
using namespace std;

int main()
{
  int k,s;
  cin >> k >> s;
  ll ans=0;

  for(int i=0;i<min(k,s)+1;i++)
  {
    if(s-i > 2*k)
    {

    }
    else if (k >= s-i)
    {
      ans += s-i +1 ;
    }
    else
    {
      ans += k +1 -(s - i - k);
    }

  }

  cout << ans << endl;

  return 0;
}




Measured memory_bytes: 256
import java.util.*
import kotlin.collections.HashMap
import kotlin.math.*

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single long
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map(String::toInt) // list of ints
private fun readLongs() = readStrings().map(String::toLong) // list of longs

fun main() {
    var n = readLong()
    var r = ""
    while (true) {
        n--
        val d = n % 26L
        r = ('a' + d.toInt()) + r
        n -= d
        if (n == 0L) {
            break
        }
        n /= 26L
    }
    println(r)
}


Measured memory_bytes: 34564
n=int(input())
s=input()
l=[0]
r=[0]
for i in range(n):
    if s[i]=="#":
        l.append(l[i]+1)
    else:
        l.append(l[i])
    if s[n-i-1]==".":
        r.append(r[i]+1)
    else:
        r.append(r[i])
r.reverse()
print(min([l[i]+r[i] for i in range(n+1)]))

Measured memory_bytes: 21128
package main

import (
	"bufio"
	"fmt"
	"os"
	"reflect"
	"sort"
	"strconv"
)

const (
	maxBufSize = 1024 * 1024
)

var (
	sc = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, 1)
		sc.Buffer(buf, maxBufSize)
		sc.Split(bufio.ScanWords)
		return sc
	}()
	out = bufio.NewWriter(os.Stdout)
)

const yes = "Yes"
const no = "No"

func solve(s string, t string) bool {
	ss := []byte(s)
	ts := []byte(t)
	sort.Slice(ss, func(i int, j int) bool {
		return ss[i] < ss[j]
	})
	sort.Slice(ts, func(i int, j int) bool {
		return ts[i] > ts[j]
	})
	sss := string(ss)
	tss := string(ts)
	return sss < tss
}

func main() {
	defer out.Flush()

	s := next()
	t := next()
	if solve(s, t) {
		fmt.Fprintln(out, yes)
	} else {
		fmt.Fprintln(out, no)
	}
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextStringAsBytes() []byte {
	sc.Scan()
	return []byte(sc.Text())
}

func nextInt() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

func nextFloat() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int64) []int64 {
	ret := make([]int64, n)
	for i := int64(0); i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

func nextFloats(n int64) []float64 {
	ret := make([]float64, n)
	for i := int64(0); i < n; i++ {
		ret[i] = nextFloat()
	}
	return ret
}
func nextStrings(n int64) []string {
	ret := make([]string, n)
	for i := int64(0); i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func containStr(arr []string, target string) bool {
	for _, v := range arr {
		if v == target {
			return true
		}
	}
	return false
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "orz")
	}
}

// mapからkeysとvaluesを返す
func splitKeyValue(m map[interface{}]interface{}) (keys, values []interface{}) {
	switch reflect.TypeOf(m).Kind() {
	case reflect.Map:
		s := reflect.ValueOf(m)
		for _, v := range s.MapKeys() {
			keys = append(keys, v)
			values = append(values, s.MapIndex(v))
		}
	default:
		fmt.Fprintln(out, "orz")
	}
	return
}


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

int main(){
    double N;
    cin >> N;

    int ans;
    ans = int(N / 1.08);
    if(int(ans*1.08) == N)
        cout << ans << endl;
    else if(int((ans+1)*1.08) == N){
        ans++;
        cout << ans << endl;
    }else{
        cout << ":(" << endl;
    }
    
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long ll;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(void){
    ll n,k;
    cin >> n >> k;
    COMinit();
    for(ll i = 0;i < k;i++){
        ll tmp = COM(n-k+1,i+1);
        tmp %= MOD;
        tmp *= COM(k-1,i);
        tmp %= MOD;
        cout << tmp << endl;
    }
    return 0;
}


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

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<LD, LD> PDD;

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define dbl(k, x) fixed << setprecision(k) << (x)

template <typename _T>
inline void _DBG(const char *s, _T x) {
  cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _DBG(const char *s, _T x, args... a) {
  while (*s != ',') cerr << *s++;
  cerr << " = " << x << ',';
  _DBG(s + 1, a...);
}

#define _upgrade                \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)

// ********************** CODE ********************** //

int main() {
  _upgrade;
  int n, m;
  cin >> n >> m;

  if (n & 1) {
    for (int i = 1; i <= m; i++) {
      cout << i << " " << n - i + 1 << "\n";
    }
  } else {
    int mid = (m + 1) / 2;
    for (int i = 1; i <= mid; i++) {
      cout << i << " " << n - i + 1 << "\n";
    }
    for (int i = mid + 1; i <= m; i++) {
      cout << i << " " << n - i << "\n";
    }
  }
  return 0;
}

Measured memory_bytes: 3480
#include<cstdio>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<iostream>
#include<sstream>
using namespace std;
typedef long long ll;

int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=0;i<k;i++){
        int a,b;
        scanf("%d%d",&a,&b);
        if(a>(n+1)/2)a-=a*2-(n+1);
        if(b>(n+1)/2)b-=b*2-(n+1);
        int mi=min(a,b)%3;
        if(mi==0)mi=3;
        printf("%d\n",mi);
    }
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;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--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    string S;
    cin >> S;
    int n = 0, s = 0, e = 0, w = 0;
    rep(i, S.size()) {
        if (S[i] == 'N') n++;
        if (S[i] == 'E') e++;
        if (S[i] == 'W') w++;
        if (S[i] == 'S') s++;
    }
    bool ok = true;
    if (n > 0) {
        if (s == 0) {
            ok = false;
        }
    }
    if (s > 0) {
        if (n == 0) {
            ok = false;
        }
    }
    if (w > 0) {
        if (e == 0) {
            ok = false;
        }
    }
    if (e > 0) {
        if (w == 0) {
            ok = false;
        }
    }
    cout << (ok ? "Yes" : "No") << '\n';
}

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


Measured memory_bytes: 256
h, w, k = map(int, input().split())
lis = []

for i in range(h):
    lis.append(input())

ans = 0

for rows in range(1 << h):
    for cols in range(1 << w):
        b = 0
        for i in range(h):
            if (rows >> i) & 1 == 1:
                continue
            for j in range(w):
                if (cols >> j) & 1 == 1:
                    continue
                
                if lis[i][j] == "#":
                    b += 1
        
        if b == k:
            ans += 1


print(ans)

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

#define int long long
typedef vector<int> vint;
typedef pair<int, int> pint;
const double PI = 3.141592653589793238462643383279;
const int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
template<typename T, typename U> inline bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> inline bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
struct Init {
    Init() {
        cout << fixed << setprecision(20);
    };
} init;

int N, d[110000];
signed main() {
    cin >> N;
    for (int i = 0; i < N; i++) { cin >> d[i]; }
    sort(d, d + N);
    cout << d[N / 2] - d[N / 2 - 1] << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

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

using namespace std;

int main()
{
	string alpha = "abcdefghijklmnopqrstuvwxyz.?! ";
	char table[5][6];

	int t = 0;
	rep(i,6)
	{
		rep(j,5)
		{
			table[j][i] = alpha[t];
			t++;
		}
	}
	
	string s;
	while(cin >> s)
	{
		if(s.size()%2 != 0)
		{
			cout << "NA" << endl;
		}
		else
		{
			t = 0;
			bool flag = true;
			vector<char> v;
			while(true)
			{
				if(t >= s.size())
				{
					break;
				}
			
				int a = s[t] - '1';
				int b = s[t+1] - '1';

				if(0 <= a && a < 6 && 0 <= b && b < 5)
				{
					v.push_back(table[b][a]);
				}
				else
				{
					flag = false;
				}

				t += 2;
			}
			if(flag)
			{
				rep(i,v.size())
				{
					cout << v[i];
				}
				cout << endl;
			}
			else
			{
				cout << "NA" << endl;
			}
		}
	}
	return 0;
}

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

typedef long long ll;

int main(){
    
    int N, K;
    cin >> N >> K;
    
    ll x[N], y[N];
    for(int i=0; i<N; i++){
        cin >> x[i] >> y[i];
    }
    
    int xM, xm, yM, ym;
    int cnt;
    ll S, ans = 4e18;
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            for(int k=0; k<N; k++){
                for(int l=0; l<N; l++){
                    xM = max(x[i],x[j]);
                    xm = min(x[i],x[j]);
                    yM = max(y[k],y[k]);
                    ym = min(y[l],y[l]);
                    cnt = 0;
                    for(int m=0; m<N; m++){
                        if(xm<=x[m] && x[m]<=xM && ym<=y[m] & y[m]<=yM) cnt++;
                    }
                    S = 1LL * (xM-xm) * (yM-ym);
                    if(cnt>=K && S>0){
                        ans = min(ans, S);
                    }
                }
            }
        }
    }
    
    cout << ans << endl;
    
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>

using namespace std;

long gcd(long a,long b){
    if (a<b) return gcd(b,a);
    else {
        if (b==1) return 1;
        else if (b==0) return a;
        else return gcd(b,a%b);
    }
}


int main(){
    int n;
    cin >> n;
    long a[n+10];
    a[0]=0;
    for (int i=1;i<=n;i++){
        cin >> a[i];
    }
    long l[n+10];
    long r[n+10];
    
    l[0]=0;
    r[n+1]=0;
    
    for(int i=1;i<=n;i++){
        l[i]=gcd(l[i-1],a[i-1]);
    }
    for(int i=n;i>0;i--){
        r[i]=gcd(r[i+1],a[i]);
    }
    
    long m[n+10];
    
    for(int i=1;i<=n;i++){
        m[i]=gcd(l[i],r[i+1]);
    }
    long ans;
    ans=m[1];
    for(int i=1;i<=n;i++){
        ans=max(ans,m[i]);
    }
    
    cout << ans << endl;
    
}





Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a+b+c<=21) {
    cout << "win" << endl;
  }
  else {
    cout << "bust" << endl;
  }
}

Measured memory_bytes: 3588
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		int n=sc.I;
		long ans=0;
		int[] a=new int[n+1];
		for(int i = 0;i<n;i++) {
			a[i]=sc.I;
			if(i==0){
				if(a[i]!=0){ans=-1;break;}
			}
			else{
				if(a[i]-a[i-1]>1){ans=-1;break;}
				else if(a[i]<=a[i-1]){ans+=a[i-1];}
			}
		}
		if(ans!=-1){ans+=a[n-1];}
		Console.WriteLine("{0}",ans);
	}
}
public class Sc{
	private string[] a;
	private int n=-1,m=0;
	public int I{get{if(n==-1||n==a.Length-1){n=-1;a=Console.ReadLine().Split();}n++;return int.Parse(a[n]);}}
	public long L{get{if(n==-1||n==a.Length-1){n=-1;a=Console.ReadLine().Split();}n++;return long.Parse(a[n]);}}
	public double D{get{if(n==-1||n==a.Length-1){n=-1;a=Console.ReadLine().Split();}n++;return double.Parse(a[n]);}}
	public string S{get{if(n==-1||n==a.Length-1){n=-1;a=Console.ReadLine().Split();}n++;return a[n];}}
	public int[] Ia{get{if(n!=-1&&n!=a.Length-1){m=n;n=-1;return Array.ConvertAll(a.Skip(m+1).ToArray(),int.Parse);}return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()).Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
}

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

bool check(int a, int b, int c){
    return (a<b+c) && (b<c+a) && (c<a+b);
}

int main(void){
    int N;
    cin >> N;
    vector<int> v(N);
    for(auto& x:v) cin >> x;
    sort(v.begin(), v.end(), greater<>());

    int ans = 0;
    for(int i=0;i<=N-2;i++){
        for(int j=0;j<i;j++){
            int ok = i+1;
            int ng = N;
            if(!check(v[ok], v[i], v[j])) continue;
            while(abs(ok-ng) > 1){
                int mid = (ok+ng)/2;
                if(check(v[mid],v[i],v[j])){
                    ok = mid;
                } else {
                    ng = mid;
                }
            }
            ans += ok - i;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
constexpr double EPS = 1e-11;

struct point{
    double x=0,y=0;
    constexpr point(double x=0,double y=0):x(x),y(y){}
    constexpr bool operator==(const point& r)const{return (x==r.x&&y==r.y);};
    constexpr point operator+(const point& r)const{return point(*this)+=r;}
    constexpr point operator+=(const point& r){
        x+=r.x;y+=r.y;
        return *this;
    }
    constexpr point operator-(const point& r)const{return point(*this)-=r;}
    constexpr point operator-=(const point& r){
        x-=r.x;y-=r.y;
        return *this;
    }
    constexpr point operator*(const double& r)const{return point(*this)*=r;}
    constexpr point operator*=(const double& r){
        x*=r;y*=r;
        return *this;
    }
    constexpr point operator/(const double& r)const{return point(*this)/=r;}
    constexpr point operator/=(const double& r){
        x/=r;y/=r;
        return *this;
    }
};

double norm(const point& a){return a.x*a.x+a.y*a.y;}
double abs(const point& a){return sqrt(a.x*a.x+a.y*a.y);}
double dot_product(const point& a,const point& b){return a.x*b.x+a.y*b.y;}
double cross_product(const point& a,const point& b){return a.x*b.y-a.y*b.x;}
point projection(const point& p,const point& b){return b*dot_product(p,b)/norm(b);}
double area(const point& a,const point& b,const point& c){ return cross_product(c-a,c-b)/2.0;}

point Point[4];

int main(){
    int n;
    cin >> n;
    rep(i,n){
        rep(j,4) cin >> Point[j].x >> Point[j].y;
        //rep(j,4) cout << setprecision(10) << Point[j].x << " " << Point[j].y << endl;
        Point[3] = Point[0] + Point[3] - Point[2];
        if(abs(area(Point[0],Point[1],Point[3])) < EPS) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}


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


#define ll              long long int
#define fo(i,n)         for(ll i=0;i<n;i++)
#define rfo(i,n)        for(ll i=n-1;i>=0;i--)
#define Ull             unsigned long long
#define pb              push_back
#define F               first
#define S               second
#define INF             2e16
#define PI              acos(-1.0)
#define mp              make_pair
#define pii             pair<int,int>
#define pll             pair<ll,ll>
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define FastRead        ios_base::sync_with_stdio(0);cin.tie(nullptr);
#define tr(it, a)       for(auto it = a.begin(); it != a.end(); it++)
#define deb(x)          cout << #x << "=" << x << endl
#define deb2(x, y)      cout << #x << "=" << x << "," << #y << "=" << y << endl

const int N = 2;
const ll MOD = 1e9 + 7;


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


bool comp(const pll &p1, const pll &p2)
{
	if (p1.first == p2.first)
		return p1.second > p2.second;

	else
		return p1.first > p2.first;
}

bool isPrime(ll x)
{
	if (x < 2)
		return false;

	if (x <= 3) return true;

	if (x % 2 == 0 || x % 3 == 0) return false;

	for (ll i = 5; i <= sqrt(x); i += 6)
	{
		if (x % i == 0 || x % (i + 2) == 0)
			return false;
	}

	return true;
}














void Solve()
{
	ll x, y;
	cin >> x >> y;
	if (y == 0)
	{
		cout << x << "\n";
		return;
	}
	ll a[y];
	ll val = INT_MIN;
	unordered_map<ll, ll> mp;
	ll minv = INT_MAX;
	fo(i, y)
	{
		cin >> a[i];
		val = max(val, a[i]);
		minv = min(minv, a[i]);
		mp[a[i]]++;

	}
	vector<ll> v;
	v.pb(minv - 1);
	for (ll i = 1; i <= val; i++)
	{
		if (mp.find(i) == mp.end())
			v.pb(i);
	}

	v.pb(val + 1);
	ll ans = INT_MAX;
	ll f_nas;
	fo(i, v.size())
	{
		if (ans > abs(x - v[i]))
		{
			ans = abs(x - v[i]);
			f_nas = v[i];
		}
	}

	cout << f_nas << "\n";




}







int main()
{

	FastRead;
	int T = 1;
	//cin >> T;

	while (T--)
	{
		Solve();
	}


	return 0;
}







Measured memory_bytes: 3640
N = gets.chomp
K = gets.to_i

case K
when 1
  puts (N.size-1) * 9 + N[0].to_i
when 2
  wk = 0
  wk += (N.size-1) * (N.size-2) / 2 * 81 if N.size > 2
  wk += (N[0].to_i - 1) * 9 * (N.size-1)
  (1...N.size).each{|i|
    next if N[i] == '0'
    wk += 9 * (N.size-1-i) + N[i].to_i
    break
  }
  puts wk
when 3
  wk = 0
  wk += ((N.size-2)**3 - (N.size-2)) / 6 * 729 if N.size > 3
  wk += (N[0].to_i - 1) * 81 * (N.size-1) * (N.size-2) / 2
  cnt = 0
  (1...N.size).each{|i|
    next if N[i] == '0'
    wk += 9 * (N.size-1-i) * (N[i].to_i - 1) if cnt == 0
    wk += 81 * (N.size-1-i) * (N.size-2-i) / 2 if cnt == 0 && i < N.size-1
    wk += 9 * (N.size-1-i) + N[i].to_i if cnt == 1
    cnt += 1
    break if cnt == 2
  }
  puts wk
end


Measured memory_bytes: 1788
k, n = gets.chomp.split.map(&:to_i)
as = gets.chomp.split.map(&:to_i)

dmax=0
n.times do |i|
    if i==n-1
        d=k-as[i] + as[0]
    else
        d=as[i+1]-as[i]
    end
    dmax=d if d>dmax
end

puts k-dmax

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

int d, s, t;

int main() {
	scanf("%d%d%d", &d, &s, &t);
	if ((double) d / s <= t) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 3688
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

bool isInteger(double x) {
    return floor(x) == x;
}

int main() {
    int N, D;
    cin >> N >> D;
    vector<vector<int>> x(N, vector<int>(D));
    rep(i, N) {
        rep(j, D) {
            cin >> x.at(i).at(j);
        }
    }

    int ans = 0;
    for (int i = 0; i < N - 1; i++) {
        for (int j = i + 1; j < N; j++) {  // 2点選択
            double sum = 0;
            for (int k = 0; k < D; k++) {  // 点の距離を計算
                sum += pow(x.at(i).at(k) - x.at(j).at(k), 2);
            }
            if (isInteger(sqrt(sum))) ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3564
/*
このコード、と～おれ!
Be accepted!
  ∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define printyn(a) printf(a ? "Yes\n" : "No\n");
#define printYN(a) printf(a ? "YES\n" : "NO\n");
#define all(x) (x).begin(), (x).end()

using ll = long long;

//マクロとかここまで

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
//#include <vector>

using namespace std;

int main() {

	int h, w;
	char str[100];
	scanf("%d%d", &h, &w);
	rep(i, h) {
		scanf("%s", str);
		printf("%s\n%s\n", str, str);
	}
	return 0;
}


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

vector<ll> H;
using Graph = vector<vector<int>>;

ll search(const Graph &G, int v) {
    int idx = v;
    ll score = H[v];
    for (auto next_v : G[v]) {
      if(score <= H[next_v]){
        score = H[next_v];
        idx = next_v;
      }
    }
    return idx;
}

int main(){
  int N,M;
  cin >> N >> M;
  
  set<pair<int,int>> ch;
  Graph G(N);
  rep(i,N){
    ll h;
    cin >> h;
    H.push_back(h);
  }
  rep(i,M){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    pair<int,int> c = make_pair(a,b);
    if(0 != ch.count(c))continue;
    ch.insert(c);
    G[a].push_back(b);
    G[b].push_back(a);
  }
  
  int cnt = 0;
  rep(i,N){
    if(i == search(G,i))cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 13752
#include<iostream>
using namespace std;
int main() {
	int n, h, m, s;
	char c, d;
	while (cin >> n && n) {
		int data[86400] = {};
		for (int i = 1; i <= n; ++i) {
			cin >> h >> c >> m >> d >> s;
			data[h * 3600 + m * 60 + s]++;
			cin >> h >> c >> m >> d >> s;
			data[h * 3600 + m * 60 + s]--;
		}
		int max = 0;
		for (int i = 1; i < 86400; ++i) {
			data[i] += data[i - 1];
			if (max < data[i]) max = data[i];
		}
		cout << max << endl;
	}
	return 0;
}


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

N,Q=map(int,input().split())
A=list(map(int,input().split()))

seg_el=1<<(N.bit_length()) # Segment treeの台の要素数
SEG=[0]*(2*seg_el) # 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化

for i in range(N): # Aを対応する箇所へupdate. Aは0-indexedなことに注意. 
    SEG[i+seg_el]=A[i]

for i in range(seg_el-1,0,-1): # 親の部分もupdate
    SEG[i]=max(SEG[i*2],SEG[i*2+1])

def update(n,x,seg_el): # A[n]をxへ更新（反映）
    i=n+seg_el
    SEG[i]=x
    i>>=1 # 子ノードへ
    
    while i!=0:
        SEG[i]=max(SEG[i*2],SEG[i*2+1])
        i>>=1
        
def getvalues(l,r): # 区間[l,r)に関するmaxを調べる
    L=l+seg_el
    R=r+seg_el
    ANS=0

    while L<R:
        if L & 1:
            ANS=max(ANS , SEG[L])
            L+=1

        if R & 1:
            R-=1
            ANS=max(ANS , SEG[R])
        L>>=1
        R>>=1

    return ANS

def bisect_on_SEG(l,x): # l以上で、x以上の最小のindexを返す。ただし、存在しない場合はNを返す。
    L=l+seg_el
    R=seg_el*2-1
    while L<R:
        if SEG[L]>=x:
            break
        if L & 1:
            L+=1
        L>>=1
        R>>=1

    if SEG[L]<x:
        return N

    while L<seg_el:
        if SEG[L*2]>=x:
            L=L*2
        else:
            L=L*2+1

    return L-seg_el

for queries in range(Q):
    T,X,V=map(int,input().split())
    if T==1:
        update(X-1,V,seg_el)
    elif T==2:
        print(getvalues(X-1,V))
    else:
        print(1+bisect_on_SEG(X-1,V))

Measured memory_bytes: 31460
n, h = map(int, input().split())

A = []
B = []

for i in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

A = sorted(A)
B = sorted(B)

t = 0
total = 0
max_a = max(A)

for i in B:
    if i >= max_a:
        t += 1
        total += i

if total <= h:
    h = h - total

    if h % max_a == 0:
        print(h // max_a + t)
    else:
        print(h//max_a + t + 1)
else:
    ans = 0
    for j in B[::-1]:
        if h > 0:
            h -= j
            ans += 1
        else:
            break
    print(ans)

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

using namespace std;

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

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

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

  string n;
  cin >> n;

  if (n[0] == '9' || n[1] == '9') cout << "Yes" << "\n";
  else cout << "No" << "\n";

  return 0;
}

Measured memory_bytes: 256