akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <math.h>
//#include <map>
#include <iomanip>
#include <vector>
#include <queue>

using namespace std;

const int INF = 1000000000;

typedef pair<int, int> P;	//縦、横

int H, W, N;
char maze[1001][1001];
int sx, sy;
int gx, gy;
int d[1001][1001];		//各点までの最短距離の配列
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int cnt;


int bfs()
{
	queue<P> que;
	
	for (int i=0; i<H; i++)
	{
		for (int j=0; j<W; j++)
		{
			d[i][j] = INF;
		}
	}
	
	que.push(P(sy, sx));
	d[sy][sx] = 0;
	
	while (que.size())
	{
		P p = que.front();
		que.pop();
		if (p.first == gy && p.second == gx) break;
		
		for (int i=0; i<4; i++)
		{
			int nx = p.second + dx[i];
			int ny = p.first + dy[i];
			
			if (0<=nx && nx<W && 0<=ny && ny<H && maze[ny][nx]!='X' && d[ny][nx]==INF)
			{
				que.push(P(ny, nx));
				d[ny][nx] = d[p.first][p.second] + 1;
			}
		}
	}
	
	return d[gy][gx];
}


int main()
{
	//入力
	cin >> H >> W >> N;
	for (int i=0; i<H; i++)
	{
		cin >> maze[i];
	}
	
	//巣と１番目のチーズ工場（ゴール）の設定
	cnt = 0;
	for (int k=1; k<=N; k++)
	{
		for (int i=0; i<H; i++)
		{
			for (int j=0; j<W; j++)
			{
				if (k == 1)
				{
					if (maze[i][j] == 'S')
					{
						sx = j;
						sy = i;
					} else if (maze[i][j] == '1') {
						gx = j;
						gy = i;
					}
				} else {
					if (maze[i][j] == '1' + k - 2)
					{
						sx = j;
						sy = i;
					} else if (maze[i][j] == '1' + k - 1) {
						gx = j;
						gy = i;
					}
				}
			}
		}
		
		cnt += bfs();
	}
	
	cout << cnt << endl;
	
	/*
	cout << "cnt = " << cnt << endl;
	
	//テスト出力
	for (int i=0; i<H; i++)
	{
		cout << maze[i] << endl;
	}
	*/
	
	return 0;
}

Measured memory_bytes: 6112
var
  n,i,j,x,y:longint;
  a:array[0..100000]of boolean;
  b:array[0..100000]of longint;
begin
  readln(n);
  a[1]:=true;
  for i:=2 to trunc(sqrt(100000)) do
    if a[i]=false then
      for j:=2 to 100000 div i do
        a[i*j]:=true;
  b[1]:=0;
  for i:=2 to 100000 do
    if (a[i]=false)and(a[(i+1) div 2]=false) then b[i]:=b[i-1]+1
                                             else b[i]:=b[i-1];
  for i:=1 to n do
  begin
    readln(x,y);
    writeln(b[y]-b[x-1]);
  end;
end.

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod=1e9+7;

ll add(ll a,ll b){
  return (a+b+mod+mod)%mod;
}

ll mul(ll a,ll b){
  return (a*b)%mod;
}

ll mpow(ll a,ll b){
  ll res=1;
  while(b){
    if(b%2==1)res=mul(res,a);
    b/=2;
    a=mul(a,a);
  }
  return res;
}

ll divi(ll a,ll b){
  return mul(a, mpow(b,mod-2) );
}

ll Fact[300000];
ll fact(ll n){
  if(n==0)return 1;
  if(Fact[n]>0)return Fact[n];
  return Fact[n]=mul(n, fact(n-1) );
}

ll nCr(ll n,ll r){
  return divi( fact(n), mul( fact(r) , fact(n-r)   ) );
}

#define MAX_N 100005

int N, flag;
int a[MAX_N];
vector<int> G[MAX_N];
map<int,bool> visited;

void init(){
  visited.clear();
  flag=0;
  for(int i=0;i<N;i++)
    G[i].clear();
}

void dfs(int pos,int prev){
  if(visited[pos]){
    flag=1;
    return;
  }
  visited[pos]=true;
  int cc=0;
  for(int i=0;i<(int)G[pos].size();i++){
    int to=G[pos][i];
    if(to==prev)continue;
    dfs(to,pos);
    cc++;
  }
  if(cc>1)flag=1;
}


ll compute(int A){
  ll total=fact(A);
  int aa=(A+1)/2 + (A+1)%2;
  return mul(total, aa );
}

ll solve(int A,int B){
  if(B==0){
    ll res=compute(A);
    res=mul(res, mpow(2,A));
    res=mul(res, mpow(2,B));
    return res;
  }
  
  if(B==1){
    ll res=0;
    for(int i=0;i<=A;i++){
      ll k=compute(i);
      ll p=nCr(A,i);
      p=mul(p, fact(A-i));
      res=add(res, mul(p, k) );
      res=add(res, mul(p ,k) );
    }
    res=mul(res, mpow(2,A));
    res=mul(res, mpow(2,B));
    return res;
  }
  
  ll res=0;
  for(int i=0;i<=A;i++){
    ll k=compute(i);
    
    ll p=nCr( A-i + B-1 , B-1 );
    p=mul(p, nCr(A,i));
    p=mul(p, fact(A-i));
    p=mul(p, fact(B));
          
    res=add(res,  mul(p , k) );
    res=add(res,  mul(p , k) );

    p=fact(A-i + 1 + B-2);
    p=divi(p, fact(A-i));
    p=divi(p, fact(B-2));
    
    p=mul(p, nCr(A,i));
    p=mul(p, fact(A-i) );
    p=mul(p, fact(B));
    
    res=add(res, mul(p, k));
  }
  res=mul(res, mpow(2,A));
  res=mul(res, mpow(2,B));
  return res;
}

int main(){
  while(1){
    scanf("%d",&N);
    if(N==0)break;
    init();
    
    for(int i=0;i<N;i++){
      scanf("%d",&a[i]);
      a[i]--;
      G[ a[i] ].push_back(i);
    }
    int A=0,B=0;
    for(int i=0;i<N;i++){
      if( visited.count(i)>0 )continue;
      
      if(a[ a[i] ]==i){
        int fi=visited.size();
        dfs(i,a[i]);
        dfs(a[i],i);
        int se=visited.size();
        if(se-fi==2)A++;
        else B++;
      }
    }

    if((int)visited.size()!=N || flag==1){
      cout<<0<<endl;
      continue;
    }
    //    cout<<A<<' '<<B<<endl;
    printf("%lld\n",solve(A,B));
  }
  
  return 0;
}

Measured memory_bytes: 14684
N, M = [int(c) for c in input().split()]
A = sorted([int(c) for c in input().split()])

t = {}
for a in A:
    t[a] = t[a]+1 if a in t else 1

for i in range(M):
    B, C = [int(c) for c in input().split()]
    t[C] = t[C]+B if C in t else B

s,v=0,0
for k in sorted(t.keys(), reverse=True):
    v += k*min(N-s, t[k])
    s += t[k]
    if s>=N: break

print(v)

Measured memory_bytes: 32064
#include <stdio.h>
#define MAX 100000
#define N 2
typedef struct node{
  int pare;
  int left;
  int right;
  int sib;
  int deg;
  int hei;
}Node;

Node a[MAX];
int depth[MAX];
void searchdep(int,int);
int searchhei(int);
int main(){
  int n,i,j,num,tmp,count;
  scanf("%d",&n);
  
  for(i = 0;i<n ;i++){
    a[i].left = -1;
    a[i].right =-1;
    a[i].pare = -1;
    a[i].sib = -1;
    a[i].hei = 0;
  }

  for(i = 0 ;i<n ;i++){
    scanf("%d",&num);
    count=0;
    for(j = 0;j<N;j++){
      scanf("%d",&tmp);
      if(tmp ==-1){
	continue;
      }
      if(j ==0) {
	a[num].left = tmp;
	count++;
	if(a[num].left !=-1){
	  a[a[num].left].sib = a[num].right;
	}
	if(a[num].right!=-1){
	  a[a[num].right].sib = a[num].left;
	}
      }
      else {
	a[num].right= tmp;
	count++;
	if(a[num].left !=-1){
	  a[a[num].left].sib = a[num].right;
	}
	if(a[num].right!=-1){
	  a[a[num].right].sib = a[num].left;
	}
      }
      if( tmp !=-1){
	a[tmp].pare =num;
      }
      a[num].deg = count;
    }
  }
  for(i = 0;i<n;i++){
    if(a[i].pare ==-1)
      searchdep(i,0);
  }
  for(i = 0 ;i<n;i++){
    a[i].hei = searchhei(i);
  }

 
  for(i = 0 ;i<n;i++){
    if(a[i].pare ==-1){
      printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, root\n",i,a[i].pare,a[i].sib,a[i].deg,depth[i],a[i].hei);
    }
    else if(a[i].right ==-1 && a[i].left==-1){
      printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, leaf\n",i,a[i].pare,a[i].sib,a[i].deg,depth[i],a[i].hei);
    }
    else if(a[i].right !=-1 ||  a[i].left!=-1){
      printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, internal node\n",i,a[i].pare,a[i].sib,a[i].deg,depth[i],a[i].hei);
    }
  }
  return 0;
}

void searchdep(int b,int c){
  depth[b] = c;
  if(a[b].left != -1){
    searchdep(a[b].left,c+1);
  }
  if(a[b].right !=-1){
    searchdep(a[b].right ,c+1);
  }
}

int searchhei(int d){
  int b=0,c=0;
  if(a[d].left ==-1 && a[d].right ==-1){
    return 0;
}
  if(a[d].right!=-1){
  b = searchhei(a[d].right);
  }
  if(a[d].left !=-1){
  c = searchhei(a[d].left);
  }
  if(b>=c){
    return b+1;
  }
  else{ return c+1;}
}



Measured memory_bytes: 2048
N = int(input())
Ori = 10 ** N % 1000000007

cnt = 0
# 0と9が一個もない
cnt -= 8 ** N % 1000000007

# 0はあるが9が無い
cnt += 9 ** N % 1000000007

# 9はあるが0が無い
cnt += 9 ** N % 1000000007

ans = (Ori - cnt)  % 1000000007

print(ans)

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

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;

int main() {
    cin >> n >> m;
    cout << n + m / 2 << endl;
    return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
using ll = long long;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b)a=b;};
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b)a=b;};

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

  Int n,m,k;
  while(cin>>n>>m>>k,n){
    using D = double;
    const Int ofs = m+10;

    const D INF = 1e15;
    vector<D> as(k+ofs,-INF),bs(k+ofs,-INF),cs(k+ofs,-INF);
    vector<D> fs(k+ofs,0),ds(k+ofs,0);
    for(Int i=0;i<n;i++){
      Int x,l,f,d,ud;
      cin>>x>>l>>f>>d>>ud;
      if(ud) swap(f,d),bs[x]=0;
      fs[x]=(D)l/f;
      ds[x]=(D)l/d;
    }
    vector<D> vs(m);
    for(Int i=0;i<m;i++) cin>>vs[i];

    for(Int i=0;i<m;i++){
      D t=(D)i/vs[i];
      for(Int j=1;j+1<k+ofs;j++){
        t+=(D)1/vs[i];
        // wait prev ship
        chmax(t,as[j+1]);
        as[j]=t;

        // wait gate down
        chmax(t,bs[j]+ds[j]);

        // wait gate up
        t+=fs[j];
        bs[j]=t;

        // wait prev ship
        chmax(t,cs[j+1]);
        cs[j]=t;

        //cout<<i<<" "<<j<<":"<<as[j]<<" "<<bs[j]<<" "<<cs[j]<<endl;
      }
    }
    cout<<fixed<<setprecision(12)<<as[k]<<endl;
  }

  return 0;
}



Measured memory_bytes: 3268
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int main(){
    int n;
    cin >> n;
    int a[100050],l[100050],r[100050];
    for(int i = 0;i < n;i++){
        cin >> a[i];
        l[i] = (i == 0 ? a[0] : gcd(l[i-1],a[i]));
    }
    for(int i = n-1;i >= 0;i--){
        r[i] = (i == n-1 ? a[n-1] : gcd(a[i],r[i+1]));
    }
    int ans = max(r[1],l[n-2]);
    for(int i = 1;i < n-1;i++){
        ans = max(ans,gcd(l[i-1],r[i+1]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
#!/usr/bin/python


def main():
  times = int(input())
  min_rate = int(input())
  maxv = - 10 ** 9
  for _ in range(1, times):
    rate = int(input())

    if rate - min_rate > maxv:
      maxv = rate - min_rate

    if rate < min_rate:
      min_rate = rate

  print(maxv)
  return 0


if __name__ == '__main__':
  main()

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

int main(){
    int n;
    cin >> n;
    int a[n+1], b[n];
    int sum2 = 0;
    for(int i = 0; i <= n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n; i++){
        cin >> b[i];
    }
    long long sum = 0;
    for(int i = 0;i < n; i++){
        sum += min(a[i],b[i]);
        b[i] -= min(a[i],b[i]);
        a[i] -= min(a[i],b[i]);
        sum += min(a[i+1], b[i]);
        a[i+1] -= min(a[i+1],b[i]);
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0;i < n;i++)
#define REP(i,n,k) for(int i = n;i < k;i++)
#define P(p) cout << (p) << endl;
#define sP(p) cout << setprecision(15) << fixed << p << endl;
#define vi vector<int>
#define printv(v) for(int i = 0;i < v.size();i++)P(v[i]);
#define printt(a,b) cout << a << " " << b << endl; 
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)

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

void solve() {
    int a,b,c;
    cin >> a >> b >> c;
    cout << max(c-(a-b),0) << endl;
}

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


Measured memory_bytes: 256
#include <stdio.h>
 
int main(void) {
    int a, b, c, cnt;
    scanf("%d %d %d", &a, &b, &c);

	if ((a == b) && (b == c)){
      cnt = 1;
    }
    else {
      if ((a != b) && (b != c) && (a != c)){
        cnt = 3;
      }
      else {
        cnt = 2;
      } 
    }
    printf("%d" ,cnt);
}

Measured memory_bytes: 128
# AOJ 1106

import sys
import math

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

def factor(a, b, c):
    disc = b * b - 4 * a * c
    if disc < 0:
        print("Impossible")
        return
    rd = math.sqrt(disc)
    if rd - math.floor(rd) > 0:
        print("Impossible")
        return
    aa = 1
    p = 2 * a
    q = b - rd
    if q == 0:
        p = 1
    else:
        d = gcd(p, q)
        p /= d
        q /= d
            
    r = 2 * a
    s = (b + rd)
    if s == 0:
        r = 1
    else:
        d = gcd(r, s)
        r /= d
        s /= d
    
    if p < 0:
        p, q = -p, -q
    if r < 0:
        r, s = -r, -s
    if p < r or (p == r and q < s):
        p, q, r, s = r, s, p, q

    print("%d %d %d %d" % (p, q, r, s))
    return

while True:
    line = input().split()
    a, b, c = map(int, list(line))
    if a == 0 and b == 0 and c == 0:
        break
    factor(a, b, c)


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

using namespace std;

int main() {
  bool isCoincide;
  string s, t; cin >> s; cin >> t;
  for (int i = s.size() - t.size(); i >= 0; --i) {
    if (s[i] == t[0] || s[i] == '?') {
      isCoincide = true;
      for (int j = 1; j < t.size(); ++j) {
        if (s[i + j] != t[j] && s[i + j] != '?') {
          isCoincide = false;
          break;
        }
      }
      if (isCoincide) {
        for (int j = 0; j < t.size(); ++j) s[i + j] = t[j];
        break;
      }
    }
  }
  if (isCoincide) {
    for (int i = 0; i < s.size(); ++i) {
      if (s[i] == '?') s[i] = 'a';
    }
    cout << s << endl;
  } else {
    cout << "UNRESTORABLE" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import sys
input=lambda: sys.stdin.readline().rstrip()

n,m=map(int,input().split())
A=[int(i)//2 for i in input().split()]
ct=0
s=A[0]
while s:
  if s%2==0:
    s//=2
    ct+=1
  else:
    s=0
chk=True
for i in range(1,n):
  cur=0
  a=A[i]
  while a:
    if a%2==0:
      a//=2
      cur+=1
    else:
      a=0
  if cur!=ct:
    chk=False
    break


def gcd(a,b):
  while b:
    a,b=b,a%b
  return a
if not chk:
  print(0)
else:
  lcm=A[0]
  for i in range(1,n):
    lcm*=A[i]//gcd(lcm,A[i])
  print((m//lcm+1)//2)

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

#define ASSERT(expr...) assert((expr))

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;
using ll = long long;

constexpr i64 INF = 1010000000000000017LL;

constexpr i64 MOD = 1000000007LL;

constexpr f64 EPS = 1e-12;

constexpr f64 PI = 3.14159265358979323846;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

ll mod_pow(ll x, ll n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        return mod_pow(x * x % MOD, n / 2) % MOD;
    } else {
        return x * mod_pow(x, (n - 1)) % MOD;
    }
}

ll mod_pow_r(ll x, ll n) {
    if (x == 0) return 0;
    if (n == 0) return 1;

    ll ret = 1;
    while (n) {
        if (n & 1) ret = ret * x % MOD;
        x = x * x % MOD;
        n /= 2;
    }
    return ret;
}

ll factorial(ll n) {
    ll ret = 1;
    REP(i, n) {
        ret *= (i + 1);
        ret %= MOD;
    }
    return ret;
}

ll combination(ll n, ll r) {
    if (n < 0 || n < r || r < 0) return 0;
    ll fn = factorial(n);
    ll fr = factorial(r);
    ll fn_r = factorial(n-r);

    ll d = (mod_pow(fr, MOD - 2) * mod_pow(fn_r, MOD - 2)) % MOD;
    ll u = fn % MOD;
    return u * d % MOD;
}

void solve() {
    string str; cin >> str;
    string ret;
    for (size_t i = 0; i < str.size(); ++i) {
        ret.push_back('x');
    }
    cout << ret;
}

signed main() {
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <unordered_map>

using namespace std;

int main(){
    string str;
    cin >> str;
    int num = str.size();
    int count = 0;
    for(int i = 0; i < num/2; i++){
        if(str.substr(i,1) != str.substr(num-1-i,1)){
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define INF 1987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset(a,0,sizeof(a));
#define MEM_1(a) memset(a,-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 998244353;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1 }, dy[] = { 1,0,-1,0 };
int ddx[] = { 0,0,1,1,1,-1,-1,-1 }, ddy[] = { 1,-1,1,0,-1,1,0,-1 };

int a[2001],n,A,B;
int d[2001][2001][2];
int go(int N,int M,int c)
{
	if(N==n)
	{
		if(M==0)return (int)abs(a[N]-B);
		return (int)abs(a[N]-a[M]);
	}
	if(M==n)
	{
		if(N==0)return (int)abs(A-a[M]);
		return (int)abs(a[N]-a[M]);
	}
	int &ret=d[N][M][c];
	if(ret!=-1)return ret;
	int next=max(N,M)+1;
	if(c==0)
	{
		ret=0;
		ret=max({ret,go(next,M,0),go(next,M,1)});
	}
	else
	{
		ret=INF;
		ret=min({ret,go(N,next,0),go(N,next,1)});
	}
	return ret;
}
int main() {
	MEM_1(d);
	scanf("%d%d%d",&n,&A,&B);
	fup(i,1,n,1)scanf("%d",a+i);
	printf("%d",go(0,0,0));
}

Measured memory_bytes: 31744
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
using namespace std;

int main(){
        int Q,T,F,i,inv=0;
        char C;
        string S;
        cin >> S;
        cin >> Q;
        queue<char> qB;
        queue<char> qE;
        for(i=0;i<Q;++i){
                cin >> T;
                if(T==1){
                        inv = (inv+1)%2;
                }else{
                        cin >> F >> C;
                        if(!inv&&F==1||inv&&F==2) qB.push(C);
                        else qE.push(C);
                }
        }
        queue<char> q1;
        queue<char> q2;
        vector<char> v;
        if(inv){
                for(i=0;i<S.length();++i){
                        v.push_back(S[i]);
                }
                q1 = qE;
                q2 = qB;
        }else{
                for(i=S.length()-1;i>=0;--i){
                        v.push_back(S[i]);
                }
                q1 = qB;
                q2 = qE;
        }
        while(!q1.empty()){
                v.push_back(q1.front());
                q1.pop();
        }
        reverse(v.begin(),v.end());
        while(!q2.empty()){
                v.push_back(q2.front());
                q2.pop();
        }
        for(i=0;i<v.size();++i) cout << v.at(i);
        cout << endl;
        return 0;
}

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

int main()
{
	//cout << "hoge" << endl;
	int n;
	cin >> n;
	if (n < 1200)
	{
		cout << "ABC" << endl;
	}
	else if (n < 2800)
	{
		cout << "ARC" << endl;

	}
	else
	{
		cout << "AGC" << endl;
	}
    return 0;
}

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(long long N, std::string S){
    int ans = 0;
    int now = 0;
    REP(i, N) {
        now += S[i] == 'I' ? 1 : -1;
        ans = max(now, ans);
    }

    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}



Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define SZ(x) ((int)((x).size()))

template <typename T1, typename T2>
string print_iterable(T1 begin_iter, T2 end_iter, int counter) {
    bool done_something = false;
    stringstream res;
    res << "[";
    for (; begin_iter != end_iter and counter; ++begin_iter) {
        done_something = true;
        counter--;
        res << *begin_iter << ", ";
    }
    string str = res.str();
    if (done_something) {
        str.pop_back();
        str.pop_back();
    }
    str += "]";
    return str;
}

vector<int> SortIndex(int size, std::function<bool(int, int)> compare) {
    vector<int> ord(size);
    for (int i = 0; i < size; i++) ord[i] = i;
    sort(ord.begin(), ord.end(), compare);
    return ord;
}

template <typename T>
bool MinPlace(T& a, const T& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool MaxPlace(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <typename S, typename T>
ostream& operator <<(ostream& out, const pair<S, T>& p) {
    out << "{" << p.first << ", " << p.second << "}";
    return out;
}

template <typename T>
ostream& operator <<(ostream& out, const vector<T>& v) {
    out << "[";
    for (int i = 0; i < (int)v.size(); i++) {
        out << v[i];
        if (i != (int)v.size()-1) out << ", ";
    }
    out << "]";
    return out;
}

template<class TH>
void _dbg(const char* name, TH val){
    clog << name << ": " << val << endl;
}
template<class TH, class... TA>
void _dbg(const char* names, TH curr_val, TA... vals) {
    while(*names != ',') clog << *names++;
    clog << ": " << curr_val << ", ";
    _dbg(names+1, vals...);
}

#if DEBUG && !ONLINE_JUDGE
    ifstream input_from_file("input.txt");
    #define cin input_from_file

    #define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
    #define dbg_arr(x, len) clog << #x << ": " << print_iterable(x, x+len, -1) << endl;
#else
    #define dbg(...)
    #define dbg_arr(x, len)
#endif

///////////////////////////////////////////////////////////////////////////
//////////////////// DO NOT TOUCH BEFORE THIS LINE ////////////////////////
///////////////////////////////////////////////////////////////////////////


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); // Remove in problems with online queries!
    string S;
    cin >> S;
    int N = SZ(S) + 1;
    vector<int> c(N);
    c[N-1] = 0;
    for (int i = N-2; i >= 0; i--) {
        if (S[i] == '<') c[i] = 0;
        else c[i] = c[i+1]+1;
    }
    vector<int> a(N);
    a[0] = c[0];
    for (int i = 1; i < N; i++) {
        if (S[i-1] == '<') a[i] = max(a[i-1]+1, c[i]);
        else a[i] = c[i];
    }
    // dbg(a);
    // dbg(c);
    LL s = 0;
    for (int i = 0; i < N; i++) s += a[i];
    cout << s << endl;
    
}


Measured memory_bytes: 4764
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        long n = scanner.nextInt() - 1;
        long a = scanner.nextInt();
        long b = scanner.nextInt();
        long c = scanner.nextInt();
        long d = scanner.nextInt();
        for (long i = 0, j = n; i < n; i++, j--) {
            if (i * d - j * c >= Math.abs(a - b) && i * c - j * d <= Math.abs(a - b)) {
                System.out.println("YES");
                return;
            }
        }
        System.out.println("NO");
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int n;
arr<int> G;
vector<int> x;
int q;
vector<bool> seen;

void dfs(int pp, int k, vector<int>& y){
    seen[k] = true;

    // cout << pp << " " << k << " ";
    // prvec(y);

    if(pp!=-1) y[k] += y[pp];
    y[k] += x[k];
    for(int m: G[k]){
        if(seen[m]) continue;
        dfs(k, m, y);
    }
}

int main()
{
    cin >> n >> q;
    G.resize(n);
    x.resize(n, 0);
    rep(i, n-1){
        int a, b; cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    rep(i, q){
        int p, t; cin >> p >> t;
        p--;
        x[p]+=t;
    }
    seen.assign(n, false);
    vector<int> y(n, 0);
    dfs(-1, 0, y);
    // prvec(x);
    prvec(y);
    return 0;}

Measured memory_bytes: 25092
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

#define no {printf("NO\n"); return 0;}

typedef long long ll;

const ll MOD = 1e9+7;

ll a[100005];
ll br[100005];

int main() {
	ll n;
	scanf("%lld", &n);
	ll uk = 0;
	for (ll i=0 ; i<n ; i++) {
		scanf("%lld", a+i);
		uk += a[i];
	}
	if (uk % (n*(n+1)/2)) no;
	ll pot = uk / (n*(n+1)/2);
	for (ll i=0 ; i<n ; i++) {
		ll p = i?i-1:n-1;
		ll nx = a[p] + pot;
		if (a[i] > nx) no;
		ll raz = nx - a[i];
		if (raz % n) no;
		br[i] = raz/n;
	}
	ll prvi = 0;
	ll dod = 1;
	ll p = 0;
	for (ll i=0 ; i<n ; i++) {
		p += br[i];
		prvi += dod * br[i];
		dod--;
		if (!dod) dod = n;
	}
	if (p != pot or prvi != a[0]) no;
	printf("YES\n");
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
  
#define min(a,b) ((a) < (b) ? (a) : (b))
#define MAX 100
#define INF 1000000000
  
int V;
int cost[MAX][MAX];
int mincost[MAX];
int used[MAX];
  
int prim() {
  int i,res,v,u;
  
  for (i = 0 ; i < V ; i++) {
    mincost[i] = INF;
    used[i] = 0;
  }
  
  mincost[0] = 0;
  res = 0;
  
  while (1) {
    v = -1;
  
    for (u = 0 ; u < V ; u++) {
      if (!used[u] && (v == -1 || mincost[u] < mincost[v])) {
    v = u;
      }
    }
  
    if (v == -1) {
      break;
    }
    used[v] = 1;
    res += mincost[v];
  
    for (u = 0 ; u < V ; u++) {
      if (cost[v][u] != -1) {
    mincost[u] = min(mincost[u],cost[v][u]);
      }
    }
  
  }
  
  return res;
}
  
int main() {
  int i,j;
    
  scanf("%d" ,&V);
  for (i = 0 ; i < V ; i++) {
    for (j = 0 ; j < V ; j++) {
      scanf("%d" ,&cost[i][j]);
    }
  }
  
  printf("%d\n" ,prim());
  
  return 0;
}

Measured memory_bytes: 636
N, M = map(int, (input().split()))
input_list = [input().split() for _ in range(M)]

AnsN = [0] * N
WrongN = [0] * N
AnsSum = 0
WrongSum = 0

for i in range(M):
    if (input_list[i][1] == 'AC') and (AnsN[int(input_list[i][0])-1] == 0):
        AnsN[int(input_list[i][0]) - 1] = 1
        AnsSum += 1
        WrongSum += WrongN[int(input_list[i][0])-1]
    elif (input_list[i][1] == 'WA') and (AnsN[int(input_list[i][0])-1] == 1):
        continue
    elif (input_list[i][1] == 'WA') and (AnsN[int(input_list[i][0])-1] >= 0):
        WrongN[int(input_list[i][0])-1] += 1

print(AnsSum, WrongSum)



Measured memory_bytes: 33688
#include <iostream>
#include <string>
#include <cmath>
using namespace std;

int main()
{
    int a;
    cin >> a ;
    if(a == 3 ){
    cout << "YES" ;
    }
    else if(a == 5 ){
    cout << "YES" ;
    }
    else if(a == 7 ){
    cout << "YES" ;
    }
    else {
    cout << "NO";
    }
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 922337203685477;
const ll mininf = -922337203685477;
const ll nax = 1e5 + 5;
int n;

int main(){
	IOS
	cin >> n;
	int ta=0, tb=0;
	string a, b, c;
	cin >> a >> b;
	for(int i=0;i<2*n;i++){
		if(i&1){
			c+=b[tb];
			tb++;
		}
		else{
			c+=a[ta];
			ta++;
		}
	}
	cout << c << '\n';
}


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

int gcd_two(int a, int b) {
    if (a == 0)
        return b;
    return gcd_two(b % a, a);
}

int gcd(int a, int b, int c) {
	return gcd_two(gcd_two(a, b), c);	
}

int main() {

	int k;
	cin >> k;

	int ans = 0;
	for(int i = 1; i <= k; i++) {
		for(int j = 1; j <= k; j++) {
			for(int l = 1; l <= k; l++) {
				ans += gcd(i, j, l);	
			}
		}
	}

	cout << ans << endl;

	return 0;
}

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

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

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

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

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

    vector<vector<int>> ans(1, vector<int>());
    
    int cnt = 0;
    for (int i = 1; i <= N; ++i) {
        if (cnt == 0) ans.push_back(vector<int>());
        ans[cnt].push_back(i);
        ans[ans.size() - 1].push_back(i);
        if (cnt + 1 == ans.size() - 1) {
            cnt = 0;
        } else {
            cnt++;
        }
    }

    rep(i, ans.size() - 1) {
        if (ans[i].size() != ans[i + 1].size()) {
            puts("No");
            return 0;
        }
    }

    puts("Yes");
    cout << ans.size() << endl;
    for (vector<int>& i : ans) {
        cout << i.size() << " ";
        for (int j : i) cout << j << " ";
        cout << endl;
    }
}

Measured memory_bytes: 2304
import java.util.Scanner;
import java.util.Stack;

public class Main {

    Scanner sc = new Scanner(System.in);

    void solve() {
        // Input
        String[] rawInputs = sc.nextLine().split(" ");

        // Solve
        Stack<String> stack = new Stack<>();
        for (String input : rawInputs) {
            switch (input) {
                case "+": {
                    Integer opl = Integer.valueOf(stack.pop());
                    Integer opr = Integer.valueOf(stack.pop());
                    Integer result = opr + opl;
                    stack.push(String.valueOf(result));
                    break;
                }
                case "-": {
                    Integer opl = Integer.valueOf(stack.pop());
                    Integer opr = Integer.valueOf(stack.pop());
                    Integer result = opr - opl;
                    stack.push(String.valueOf(result));
                    break;
                }
                case "*": {
                    Integer opl = Integer.valueOf(stack.pop());
                    Integer opr = Integer.valueOf(stack.pop());
                    Integer result = opr * opl;
                    stack.push(String.valueOf(result));
                    break;
                }
                default: {
                    stack.push(input);
                }
            }
        }
        String result = stack.pop();

        // Output
        System.out.println(result);
    }

    public static void main(String[] args) {
        new Main().solve();
    }
}



Measured memory_bytes: 26180
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	
	void run() {
		FastScanner sc=new FastScanner();
		int x=sc.nextInt();
		System.out.println(x^1);
	}
	
	void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));}
}

Measured memory_bytes: 32488
#pragma region Template

#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <bitset>
#include<map>
#include<cmath>
#include <set>
#include<limits.h>
#include<fstream>

#define lli long long int
#define us unsigned short
#define mod 1000000007
#define INF 1e18+5

#define vi vector<int>
#define vd vector<double>
#define vus vector<unsigned short>
#define vlli vector<long long int>
#define vs vector<string>
#define mii map<int,int>
#define mlli map<long long int,long long int>

#define w(t) int t; cin>>t;while(t--)

using namespace std;

#pragma endregion

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

	vector<vector<double>> dp(N+1,vector<double>(N+1));
	vd p(N+1);
	dp[0][0] = 1;
	double ans=0;

	for (int i = 1; i <= N; i++)
	{
		cin >> p[i];
	}

	for (int i = 1; i <=N; i++)
	{
		for (int j = 0; j <= N; j++)
		{
			if (j == 0)
				dp[i][j] = dp[i - 1][j] * (1 - p[i]);
			else
				dp[i][j] = dp[i - 1][j - 1] * p[i] + dp[i - 1][j] * (1 - p[i]);
		}
	}

	for(int i=1;i<=N;i++)
	{ 
		if (i > N - i)
			ans += dp[N][i];
	}

	printf("%.10f\n",ans);
	
	return 0;
}


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

int main(void) {
  int n, k;
  cin >> n >> k;

  int ans = 0;
  rep (i, n) {
    int h;
    cin >> h;
    if (h >= k) ans++;
  }
  cout << ans << 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, M, fa[100005], deg[100005], deg0[100005], topd, tope;
struct Edge {int np; Edge *nxt;} E[100005], *V[100005];

inline void addedge(const int &u, const int &v){
	E[++tope].np = v, E[tope].nxt = V[u], V[u] = E + tope;
}

int main(){
	getint(N), getint(M);
	for(register int i = 1; i < N + M; i++){
		int u, v; getint(u), getint(v);
		addedge(u, v), deg[v]++;
	}
	for(register int i = 1; i <= N; i++) if(!deg[i]) deg0[++topd] = i;
	for(register int i = 1; i <= N; i++){
		const int u = deg0[topd--];
		for(register Edge *ne = V[u]; ne; ne = ne->nxt)
			if(fa[ne->np] = u, --deg[ne->np] == 0) deg0[++topd] = ne->np;
	}
	for(register int i = 1; i <= N; i++) printf("%d\n", fa[i]);
	return 0;
}

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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(W,n)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {REP(aaa,i){REP(bbb,j)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

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

int main(){

	int n;cin >> n;

	vector<int> v;
	vector<int> u;
	REP(i,n+1){
		bool flag = false;
		int tmp = 0;
		string str;
		cin >> str;

		REP(j,str.size()){
			if(str[j] >= '0' && str[j] <= '9'){
				flag = true;
				tmp *= 10;
				tmp += str[j] - '0';
			}
			else{
				if(flag){
					flag = false;
					v.PB(tmp);
					tmp = 0;
				}
				v.PB(str[j] + INF);
			}

		}

		if(flag){
			v.PB(tmp);
		}
		if(i != 0){
			if(v >= u){
				cout << "+" << endl;
			}
			else {
				cout << "-" << endl;
			}
		}
		else{
			u = v;
		}

		v.clear();
	}

	return 0;
}



Measured memory_bytes: 3208
/*input
100 0

*/
 
 
 
#include <bits/stdc++.h>
using namespace std;
 
 
 
#define int long long int
#define rep(i,n) \
    for(int i = 0; i < n; i++)
#define rep2(i, a, b) \
    for(int i = a; i < b; i++)
#define all(c) \
    c.begin(), c.end()
#define init(arr, num) \
    memset(arr, num, sizeof(arr))
#define fast\
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inputFile \
    freopen("input.txt", "r", stdin); 
#define outputFile \
    freopen("output.txt", "w", stdout);
#define modM 1000000007
#define PI 3.1415926535897932
#define F first
#define S second  
#define pb push_back  
#define INF 3e18
#ifdef gaviria
#define TRACE
#endif
#ifdef TRACE
#define trace(...) _f(#VA_ARGS, __VA_ARGS_)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std::endl;
 
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define trace(...)
#endif
 
 
typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair< ll, ll > ii;
typedef unordered_set<int> usi;
 


ll n,i,j,k,m;

void solve()
{
cin>>k>>n;

int a[n];
set <int> s;
rep(i,n)
{
cin>>a[i];
s.insert(a[i]);
}int ans=0;
for(i=0;i<102;i++)
{

    if(abs(k-i)<abs(k-ans)&&s.find(i)==s.end())
    {
        ans=i;
    }

}
cout<<ans;

}



 
 
 
signed main()
{
 
    // inputFile;
    // outputFile;
    fast;
    int T = 1;
 // cin >> T;
ll h=T;
    while(T--){
 
        solve();
        cout<<endl;
 
     
        
        
 
    }
    
    
    return 0;
 
}

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

#define int long long
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

const int MOD = 1e9+7;
const int M = 101;

vector<vector<int> > cur(M,vector<int>(2,0));
vector<vector<int> > nex(M,vector<int>(2,0));

int md[M][10],d;
string s;

signed main()
{
    fast;
    
    cin >> s >> d;
    
    int n = s.length();
    reverse(s.begin(),s.end());
    
    f(i,d) f(j,10)
        md[i][j] = ((i - j)%d + d)%d;
    
    cur[0][0] = cur[0][1] = 1;
    
    for(int i=1;i<=n;i++)
    {
        
    f(j,d)
    {
        nex[j][1] = nex[j][0] = 0;
        
        f(v,10)
            nex[j][1] = (nex[j][1] + cur[md[j][v]][1])%MOD;
        
        f(v,s[i-1]-'0')
            nex[j][0] = (nex[j][0] + cur[md[j][v]][1])%MOD;
        
        nex[j][0] = (nex[j][0] + cur[md[j][s[i-1]-'0']][0])%MOD;
    }
     
        swap(cur,nex);
    }
    
    cout << ( cur[0][0] - 1 + MOD)%MOD;
}

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

typedef long long ll;

int a, b, ans;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> a >> b;
    for (int i = 0; i < 2; ++i) {
        if (a > b) {
            ans += a;
            --a;
        } else {
            ans += b;
            --b;
        }
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3592
"use strict";
function maketrans(from, to) {
    var replaces = {}, i, c, exp = '', re;
    for (i in from) {
        c = from[i];
        replaces[c] = to.substr(i, 1);
        exp += '[]-^\\'.indexOf(c) < 0 ? c : '\\' + c;
    }
    re = RegExp('[' + exp + ']', 'g');
    function replacer(c) { return replaces[c]; }
    return function (str) { return str.replace(re, replacer); };
}

function main(input) {
    const line = input.split("\n");
    const N = parseInt(line[0]);
    const S = line[1];
    const alp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    let trans = maketrans(
        alp,
        alp.slice(N) + alp.slice(0, N)
    );
    console.log(trans(S));
    return;
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int main() {
  // ここにプログラムを追記
  int s;
  cin>> s;
  int s1= s / 100;
  int s2= (s - s1 * 100) / 10;
  int s3= s - s1*100 - s2* 10;
  cout<<s1 + s2 + s3<<endl;
}

Measured memory_bytes: 256
s = int(input())
n = s

ans = [0] * 1000
ans[0] = s

j = 1
while 1:
        if j  > 1000000:
                break
        if ans[j-1] % 2 == 0:
                ans[j] = ans[j-1] // 2
        else:
                ans[j] = 3 * ans[j-1] + 1
        for i in range(len(ans)):
                if i == j:
                        break
                if ans[i] == ans[j]:
                        print(j+1)
                        exit()
        j += 1

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

int main() {
  int n, a;
  cin >> n;
  a = 0;
  for ( int i = 0; i < n; i++ ){
    int l, r;
    cin >> l >> r;
    a += r - l + 1;
  }
  cout << a << endl;
}


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

#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)

int main(int argc, const char * argv[]) {
    string S;
    cin >> S;
    
    vector<string> w = vector<string>();
    w.push_back("Sunny");
    w.push_back("Cloudy");
    w.push_back("Rainy");
    
    for (int i = 0; i < 3; i++) {
        if (S == w[i]) {
            cout << w[(i + 1) % 3] << endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
 
using namespace std;
 
typedef long long                                        ll;
typedef long double                                      ld;
typedef pair <int, int>                                  pii;
 
# define A                                               first
# define B                                               second
# define endl                                            '\n'
# define sep                                             ' '
# define all(x)                                          x.begin(), x.end()
# define kill(x)                                         return cout << x << endl, 0
# define InTheNameOfGod                                  ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
 
ll power(ll a, ll b, ll md) {return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md));}
 
const int xn = 3e5 + 10;
const int xm = - 20 + 10;
const int sq = 320;
const int inf = 1e9 + 10;
const ll INF = 1e18 + 10;
const ll mod = 1e9 + 7;
const int base = 257;

ll n, dp[2][2][xn], ans, pw[xn], ted;
string s;

void solve1(){
	if (s[0] == '0' || s[n - 1] == '0') return;
	ted = 0;
	for (int i = 1; i < n - 1; ++ i) ted += s[i] == '?';
	ans = (ans + pw[ted]) % mod;
}
void solve2(){
	reverse(all(s));
	if (s[0] == '0' || s[n - 1] == '1') return;
	memset(dp, 0, sizeof dp);
	dp[0][1][0] = 1;
	ted = 0;
	for (int i = 1; i < n; ++ i){
		if (i < n - 1) ted += bool(s[i] == '?');
		if (i % 2){
			if (s[i] != '1') dp[0][0][i] = (dp[0][0][i - 1] + dp[0][1][i - 1]) % mod;
			if (s[i] != '0') dp[0][1][i] = dp[0][0][i - 1];
		}
		else{
			if (s[i] != '1') dp[0][0][i] = (dp[0][0][i - 1] + dp[0][1][i - 1]) % mod;
			if (s[i] != '0') dp[0][1][i] = (dp[0][0][i - 1] + dp[0][1][i - 1]) % mod;
		}
	}
	ans = (ans + pw[ted] - dp[0][0][n - 1] + mod) % mod;
}
void solve3(){
	if (s[0] == '1' || s[n - 1] == '1') return;
	memset(dp, 0, sizeof dp);
	dp[0][0][0] = 1;
	for (int i = 1; i < n; ++ i){
		ted += bool(s[i] == '?');
		if (i % 2){
			if (s[i] != '1') dp[0][0][i] = (dp[0][0][i - 1] + dp[0][1][i - 1]) % mod;
			if (s[i] != '0') dp[0][1][i] = (dp[0][0][i - 1] + dp[0][1][i - 1]);
		}
		else{
			if (s[i] != '1') dp[0][0][i] = (dp[0][0][i - 1] + dp[0][1][i - 1]) % mod;
			if (s[i] != '0') dp[0][1][i] = dp[0][0][i - 1];
		}
	}
	dp[1][0][n - 1] = 1;
	ted = 0;
	for (int i = n - 2; i > 0; -- i){
		if (i % 2){
			if (s[i] != '1') dp[1][0][i] = (dp[1][0][i + 1] + dp[1][1][i + 1]) % mod;
			if (s[i] != '0') dp[1][1][i] = (dp[1][0][i + 1] + dp[1][1][i + 1]) % mod;
		}
		else{
			if (s[i] != '1') dp[1][0][i] = (dp[1][0][i + 1] + dp[1][1][i + 1]) % mod;
			if (s[i] != '0') dp[1][1][i] = dp[1][0][i + 1];
			if (s[i] == '0') continue;
			ans = (ans + dp[0][1][i - 1] * (pw[ted] - dp[1][1][i] + mod) % mod) % mod;
		}
		ted += bool(s[i] == '?');
	}
}

int main(){
    InTheNameOfGod;
    
	cin >> s;
	n = s.size();
	if (n == 1) kill(bool(s[0] == '?' || s[0] == '1'));
	pw[0] = 1;
	for (int i = 1; i < xn; ++ i) pw[i] = pw[i - 1] * 2LL % mod;
	solve1();
	solve2();
	solve2();
	solve3();
	cout << ans << endl;
	
    return 0;
}


Measured memory_bytes: 15464