akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

pair<char,int> p[9];
bool flag[9];

bool ans(int pos){
  if(pos == 9) return true;
  if(flag[pos]) return ans(pos+1);
  flag[pos] = true;
  int same = 0;
  for(int i=pos+1; i<9; i++)
    if(!flag[i] && p[pos] == p[i]) same++;
  if(same >= 2){
    int pp[2] = {-1, -1};
    int cnt = 0;
    for(int i=pos+1; i<9; i++)
      if(!flag[i] && p[pos] == p[i]){
        pp[cnt++] = i;
        if(cnt == 2) break;
      }else
        break;
    if(cnt == 2){
      flag[pp[0]] = flag[pp[1]] = true;
      if(ans(pos+1)) return true;
      flag[pp[0]] = flag[pp[1]] = false;
      //printf("pair1 : %d %d %d\n",pos,pp[0],pp[1]);
    }
  }
  int pp[2] = {-1, -1};
  for(int i=pos+1; i<9; i++){
    if(p[pos].f != p[i].f) break;
    if(flag[i]) continue;
    if(p[pos].s + 1 == p[i].s){
      if(pp[0] == -1)
        pp[0] = i;
    }
    if(p[pos].s + 2 == p[i].s){
      if(pp[1] == -1)
        pp[1] = i;
    }
  }
  if(pp[0] != -1 && pp[1] != -1){
    //printf("pair2 : %d %d %d\n",pos,pp[0],pp[1]);
    flag[pp[0]] = flag[pp[1]] = true;
    if(ans(pos+1)) return true;
    flag[pp[0]] = flag[pp[1]] = false;
  }
  flag[pos] = false;
  return false;
}

int main(){
  int n; cin>>n;
  while(n --> 0){
    REP(i,9) cin>>p[i].s;
    REP(i,9) cin>>p[i].f;
    REP(i,9) flag[i] = false;
    sort(p, p+9);
    puts(ans(0)?"1":"0");
  }
  return 0;
}

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

int main(void){
    int N, T;
    cin >> N >> T;
    int c[N], t[N];
    int i;
    for(i=0; i<N; i++) cin >> c[i] >> t[i];
    int r = 10000;
    for(i=0; i<N; i++){
        if(t[i] <= T && c[i] < r) r = c[i];
    }
    if(r == 10000) cout << "TLE" << endl;
    else cout << r << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <string.h>
#define pai 3.1415926535

	int main(void) {
		int A, B;
		scanf("%d%d", &A, &B);
		if (A == B) {
			printf("Draw");
		}else if ((A > B || A == 1)&&B!=1) {
			printf("Alice");
		}
		else {
			printf("Bob");
		}

		return 0;
}


Measured memory_bytes: 128
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int N=2e5+10;
int n,m,a[N],ans,vis[N];
vector<int>G[N];
void dfs(int u,int fa)
{
    vis[u]=1;
    int flag=1;
    for(int v:G[u]){
        if(a[v]>=a[u]) flag=0;
        if(vis[v]) continue;
        dfs(v,u);
    }
    if(flag) ans++;
}
int main()
{
    cin>>n>>m;
    rep(i,1,n) cin>>a[i];
    rep(i,1,m)
    {
        int u,v;
        cin>>u>>v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    rep(i,1,n)
    {
        if(vis[i]) continue;
        dfs(i,-1);
    }

    cout<<ans<<endl;
}
/*
3 2
1 2 3
1 2
1 2
*/


Measured memory_bytes: 13544
import sys
import collections


sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    S = [input().strip() for _ in range(N)]

    c = collections.Counter(S)

    print("AC x " + str(c["AC"]))
    print("WA x " + str(c["WA"]))
    print("TLE x " + str(c["TLE"]))
    print("RE x " + str(c["RE"]))

    
    
    

if __name__ == '__main__':
    main()



Measured memory_bytes: 16620
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag,
		tree_order_statistics_node_update> ordered_set;
int n,a,s[4];
double dp[303][303][303];
double sol(int a,int b,int c)
{
	if(a+b+c==0)
		return 0;
	if(dp[a][b][c])
		return dp[a][b][c];
	double ret=1;
	if(a)
		ret+=(double)a*sol(a-1,b,c)/(1.0*n);
	if(b)
		ret+=(double)b*sol(a+1,b-1,c)/(1.0*n);
	if(c)
		ret+=(double)c*sol(a,b+1,c-1)/(1.0*n);

	double mg = a + b + c;
	ret+=(ret*(n-mg)/(mg));

	return dp[a][b][c]=ret;
}
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;s[a]++;
	}
	cout<<fixed<<setprecision(10)<<sol(s[1],s[2],s[3]);
	return 0;
}


Measured memory_bytes: 217344
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
const int INF = INT_MAX / 2;

int main(){
    int N, M; cin >> N >> M;
    vector<int> v(M, 0);
    for (int i = 0; i < N; i++)
    {
        int K; cin >> K;
        for (int i = 0; i < K; i++)
        {
            int a; cin >> a;
            a--;
            v[a]++;
        }
    }
    
    int cnt = 0;
    for(int i : v){
        if(i==N) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
    H, W, K = map(int, input().split())
    C = [list(input()) for _ in range(H)]

    ans = 0

    for i in range(1 << H):
        for j in range(1 << W):
            cnt = 0
            for a in range(H):
                for b in range(W):
                    if not (i >> a & 1 or j >> b & 1) and C[a][b] == '#':
                        cnt += 1
            if cnt == K:
                ans += 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9204
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    ll n, m;
    cin >> n >> m;
    VVL b(m);
    REP(i,n){
        ll x = in() - 1, y = in();
        if (x < m) b[x].push_back(y);
    }
    priority_queue<ll> que;
    ll ans = 0;
    REP(i,m){
        for (ll x : b[i]) que.push(x);
        if (!que.empty()){
            ans += que.top();
            que.pop();
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5632
#include <stdio.h>

int n;
long ans=-1000000241;
int f[100][10] = {};
long p[100][11] = {};

int main() {
    scanf("%d", &n);
    for (int i=0; i<n; i++)
        for (int j=0; j<10; j++)
            scanf(" %d", &f[i][j]);
    for (int i=0; i<n; i++)
        for (int j=0; j<11; j++)
            scanf(" %ld", &p[i][j]);
    for (int t=1; t<1024; t++) {
        long v = 0;
        int num[100] = {};
        for (int j=0; j<10; j++)
            if (t & (1<<j))
                for (int i=0; i<n; i++)
                    if (f[i][j] == 1)
                        num[i]++;
        for (int i=0; i<n; i++)
            v += p[i][num[i]];
        if (v > ans)
            ans = v;
    }
    printf("%ld\n", ans);
}

Measured memory_bytes: 128
#include <iostream>

#define MAX_N 32
#define INF -1

int ans, n;
long memo[MAX_N];

inline
void solve();

long dp(int a);

inline
int answer(int in);

int main(){
    while(true){
        std::cin >> n;
        
        if(n == 0)
            break;
        
        for(int i = 0; i < MAX_N; ++i)
            memo[i] = INF;
        
        solve();
        
        std::cout << answer(ans) << std::endl;
    }
    return 0;
}

inline
void solve(){
    ans = dp(n + 1);
    return;
}

long dp(int a){
    if(a < 1) return 0;
    if(a == 1) return 1;
    
    if(memo[a] == INF){
        memo[a] = dp(a - 1) + dp(a - 2) + dp(a - 3);
        return memo[a];
    }
    
    return memo[a];	
}

inline
int answer(int in){
    return in % 3650 > 0 ? in / 3650 + 1 : in / 3650;
}

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

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr long double EPS = 1e-8;

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

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

	cin >> N;
	string a, b;
	int flag = 1;
	while (a.size() < N) {
		if (flag) {
			a.push_back('#');
			b.push_back('#');
			cout << a << endl;
			cout << b << endl;
			char c;
			cin >> c;
			if (c == 'T') {
				continue;
			}
			a.pop_back();
			b.pop_back();
			a.push_back('#');
			b.push_back('.');
			cout << a << endl;
			cout << b << endl;
			cin >> c;
			if (c == 'T') {
				continue;
			}
			a.pop_back();
			b.pop_back();
			a.push_back('.');
			b.push_back('#');
			cout << a << endl;
			cout << b << endl;
			cin >> c;
			if (c == 'T') {
				continue;
			}
			a.pop_back();
			b.pop_back();
			a.push_back('.');
			b.push_back('.');
			cout << a << endl;
			cout << b << endl;
			cin >> c;
			if (c == 'T') {
				continue;
			}
			a.pop_back();
			b.pop_back();
			flag = false;
		}
		else {
			reverse(a.begin(), a.end());
			reverse(b.begin(), b.end());
			a.push_back('#');
			b.push_back('#');
			reverse(a.begin(), a.end());
			reverse(b.begin(), b.end());
			cout << a << endl;
			cout << b << endl;
			char c;
			cin >> c;
			if (c == 'T') {
				continue;
			}
			reverse(a.begin(), a.end());
			reverse(b.begin(), b.end());
			a.pop_back();
			b.pop_back();
			a.push_back('#');
			b.push_back('.');
			reverse(a.begin(), a.end());
			reverse(b.begin(), b.end());
			cout << a << endl;
			cout << b << endl;
			cin >> c;
			if (c == 'T') {
				continue;
			}
			reverse(a.begin(), a.end());
			reverse(b.begin(), b.end());
			a.pop_back();
			b.pop_back();
			a.push_back('.');
			b.push_back('#');
			reverse(a.begin(), a.end());
			reverse(b.begin(), b.end());
			cout << a << endl;
			cout << b << endl;
			cin >> c;
			if (c == 'T') {
				continue;
			}
			reverse(a.begin(), a.end());
			reverse(b.begin(), b.end());
			a.pop_back();
			b.pop_back();
			a.push_back('.');
			b.push_back('.');
			reverse(a.begin(), a.end());
			reverse(b.begin(), b.end());
			cout << a << endl;
			cout << b << endl;
			cin >> c;
			if (c == 'T') {
				continue;
			}
			reverse(a.begin(), a.end());
			reverse(b.begin(), b.end());
			a.pop_back();
			b.pop_back();
			reverse(a.begin(), a.end());
			reverse(b.begin(), b.end());
		}
	}
	cout << a << endl;
	cout << b << endl;
}

Measured memory_bytes: 724
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.buffer.readline().rstrip()
rs = lambda: sys.stdin.buffer.readline().split()
ri = lambda: int(sys.stdin.buffer.readline())
rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.buffer.readline().split()))

n = ri()
ans = 0
d = 2
while d**2 <= n:
    if n % d != 0:
        d += 1
        continue

    dd = d
    while n % d == 0:
        n //= d
        d *= dd
        ans += 1

    while n % dd == 0:
        n //= dd
    d = dd + 1

if n != 1:
    ans += 1
print(ans)



Measured memory_bytes: 27112
# i行、j列それぞれにある爆弾の数を数える。
# 足して最大になるところにおけば良い。
H,W,M = map(int,input().split())
R = [0]*H
C = [0]*W
d = set()
ans = 0
for _ in range(M):
    h,w = map(int,input().split())
    h -= 1;w -= 1
    d.add((h,w))
    R[h] += 1
    C[w] += 1
r = []
c = []
tmp = 0
for i in range(H):
    if R[i] > tmp:
        tmp = R[i]
        r = [i]
    elif R[i] == tmp:
        r.append(i) 
    
ans += tmp
tmp = 0
for j in range(W):
    if C[j] > tmp:
        tmp = C[j]
        c = [j]
    elif C[j] == tmp:
        c.append(j)
ans += tmp
# もし選んだ行と列に共通して同じ爆弾が含まれていたら、それを削除したい。
select = []
for i in r:
    for j in c:
        if (i,j) in d:
            continue
        else:
            select = [i,j]
            break
if select == []:
    ans -= 1
print(ans)


Measured memory_bytes: 166908
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <cmath>
#include <cassert>
#include <cstdio>

using namespace std;
using namespace placeholders;

using LL = long long;
using ULL = unsigned long long;
using VI = vector< int >;
using VVI = vector< vector< int > >;
using VS = vector< string >;
using SS = stringstream;
using PII = pair< int, int >;
using VPII = vector< pair< int, int > >;
template < typename T = int > using VT = vector< T >;
template < typename T = int > using VVT = vector< vector< T > >;
template < typename T = int > using LIM = numeric_limits< T >;

template < typename T > inline istream& operator>>( istream &s, vector< T > &v ){ for ( T &t : v ) { s >> t; } return s; }
template < typename T > inline ostream& operator<<( ostream &s, const vector< T > &v ){ for ( int i = 0; i < int( v.size() ); ++i ){ s << ( " " + !i ) << v[i]; } return s; }
template < typename T > inline T fromString( const string &s ) { T res; istringstream iss( s ); iss >> res; return res; }
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); }

#define REP2( i, n ) REP3( i, 0, n )
#define REP3( i, m, n ) for ( int i = ( int )( m ); i < ( int )( n ); ++i )
#define GET_REP( a, b, c, F, ... ) F
#define REP( ... ) GET_REP( __VA_ARGS__, REP3, REP2 )( __VA_ARGS__ )
#define FOR( e, c ) for ( auto &&e : c )
#define ALL( c ) begin( c ), end( c )
#define AALL( a, t ) ( t* )a, ( t* )a + sizeof( a ) / sizeof( t )
#define DRANGE( c, p ) ( c ).begin(), ( c ).begin() + ( p ), ( c ).end()

#define SZ( v ) ( (int)( v ).size() )
#define EXIST( c, e ) ( ( c ).find( e ) != ( c ).end() )

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

#define PB push_back
#define EM emplace
#define EB emplace_back
#define BI back_inserter

#define MP make_pair
#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

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

	int N, X;
	scanf( "%d%d", &N, &X );

	VT< LL > A( N * 2 );
	A.resize( N );
	for_each( ALL( A ), []( LL &a ){ scanf( "%lld", &a ); } );

	VT< LL > mins( A );
	copy_n( begin( A ), N, BI( A ) );

	LL res = accumulate( ALL( mins ), 0LL );
	REP( i, 1, N )
	{
		REP( j, N )
		{
			mins[j] = min( mins[j], A[ N + j - i ] );
		}

		chmin( res, LL( i ) * X + accumulate( ALL( mins ), 0LL ) );
	}

	printf( "%lld\n", res );
	fflush( stdout );

	return 0;
}


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

const int maxn=1e6+7;
int p[maxn],cnt=1;
bool np[maxn];
long long a,b;

void get_prime()
{
	for(int i=2;i<maxn;++i) {
		if(!np[i]) p[++p[0]]=i;
		for(int j=1;j<=p[0]&&i*p[j]<maxn;++j) {
			np[i*p[j]]=1;
			if(i%p[j]==0) break;
		}
	}
}

int main()
{
	get_prime();
	scanf("%lld %lld",&a,&b);
	int t=sqrt(min(a,b));
	for(int i=1;p[i]<=t;++i) {
		if(a%p[i]==0&&b%p[i]==0) cnt++;
		while(a%p[i]==0) a/=p[i];
		while(b%p[i]==0) b/=p[i];
	}
	if(a==b&&a!=1) cnt++;
	printf("%d",cnt);
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (b) - 1; i >= (a); i--)
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define ALL(i) (i).begin(),(i).end()
#define RALL(i) (i).begin(),(i).end(),greater<int>()
 
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
 
typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 100005
#define TENFIVE2 200005
// #define int long long
const int INF = 999999999;
const int MOD = 1e9 + 7;
const double EPS = 1e9 + 7;
const double PI = acos(-1);
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
 
inline int in(){int x;std::cin>>x;return x;}
 
using lint = long long;
using pint = pair<int, int>;
using vi = vector<int>;
using vii = vector<vector<int> >;
using vl = vector<long long>;
using vp = vector<pint>;
 
template <typename T> void print(T x) { std::cout << x << '\n'; }
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T*)array, (T*)(array + N), val);
}

signed main(){
    int r, D, x;
    cin>>r>>D>>x;
    rep(i,10){
        int newx = r*x -D;
        print(newx);
        x = newx;
    }
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <cctype>
#include <cstdio>
#include <math.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<pair<long long,long long>> ab(n);
    for(int i=0;i<n;i++){
        long long x,y;
        cin >> x;
        cin >> y;
        ab[i]=make_pair(x,y);
    }
    long long ans=0;
    reverse(ab.begin(),ab.end());
    for(int i=0;i<n;i++){
        if((ans+ab[i].first)%ab[i].second!=0){
            if((ans+ab[i].first)<ab[i].second){
                ans+=ab[i].second-(ans+ab[i].first);
                
            }else{
                ans+=(((ans+ab[i].first)/ab[i].second)+1)*ab[i].second-(ans+ab[i].first);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

H1,M1,H2,M2,K = map(int,S().split())

x = 60*H1+M1
y = 60*H2+M2

print(y-x-K)

Measured memory_bytes: 61920
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true; } return false; }

//INT_MAX	2,147,483,647 = 2*1.0e9

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

  if(N == 1) cout << "Hello World" << endl;
  else {
    int A, B ;
    cin >> A >> B;
    cout << A+B << endl;
  }

  return 0;
}


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

bool comp(vector<int>& a, vector<int>& b){
    return a[1] > b[1];
}

int main(){
    while(1){
        int n, m; cin >> n >> m;
        if(n == 0) break;
        vector<vector<int> > a(n, vector<int> (2));
        for(int i = 0; i < n; i++) cin >> a[i][0] >> a[i][1];
        sort(a.begin(), a.end(), comp);

        for(int i = 0; i < a.size(); i++){
            if(a[i][0] <= m){
                m -= a[i][0];
                a[i][0] = 0;
            }else{
                a[i][0] -= m;
                break;
            }
        }

        int ans = 0;
        for(int i = 0; i < a.size(); i++){
            //cout << a[i][0] << " " << a[i][1] << endl;
            ans += a[i][0] * a[i][1];
        }

        cout << ans << endl;
        
    }

    return 0;

}

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

using namespace std;
typedef long long LL;

#define MAXN 100001
#define MOD 1000000007

int A[MAXN];

int main(int argc, char** argv) {
#ifdef OJ
    freopen("input.txt", "r", stdin);
    //    freopen("output.txt", "w", stdout);
#endif
    std::ios::sync_with_stdio(false);

    int N;
    cin >> N;

    for (int i = 1; i < MAXN; i++)
        A[i] = i;

    int k = 1;
    while (k < MAXN) {
        k *= 6;
        for (int i = k; i < MAXN; i++)
            A[i] = min(A[i], A[i - k] + 1);
    }

    k = 1;
    while (k < MAXN) {
        k *= 9;
        for (int i = k; i < MAXN; i++)
            A[i] = min(A[i], A[i - k] + 1);
    }

    cout << A[N] << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int n;
char s[11111],res[5555],tmp[5555],tmp2[5555];
void upd()
{
    int flag=0;
    for(int i=1;i<=n;i++)
    {
        if(tmp2[i]<res[i]){flag=1;break;}
        else if(tmp2[i]>res[i])break;
    }
    if(flag)memcpy(res,tmp2,(n+3)*sizeof(char));
}
int main()
{
    int k;scanf("%d%d",&n,&k);
    scanf("%s",s+1);
    char minchar='z';
    for(int i=1;i<=n;i++)minchar=min(minchar,s[i]);
    int bef=0,maxnum=0;
    for(int i=1;i<=n;i++)
    {
        if(s[i]==minchar)bef++;
        else bef=0;
        maxnum=max(maxnum,bef);
    }
    int now=bef;
    for(int i=1;i<=k;i++)
    {
        now=min(n,now*2);
        if(now==n)break;
    }
    int now2=maxnum;
    for(int i=1;i<k;i++)
    {
        now2=min(n,now2*2);
        if(now2==n)break;
    }
    res[1]='z'+1;
    if(now==n||now2==n){
        for(int i=1;i<=n;i++)putchar(minchar);
        puts("");
        return 0;
    }
    bef=0;
    for(int i=1;i<=n;i++)
        s[n+(n-i+1)]=s[i];
    for(int i=1;i<=now2;i++)tmp2[i]=minchar;
    for(int i=1;i<=n;i++)
    {
        if (s[i] == minchar)bef++;
        else bef = 0;
        if(bef==maxnum)
        {
            int k=n+(n-i+1)+bef-1;
            for(int i=1;i<=n;i++)tmp[i]=s[k-(n-i)];
            for(int i=now2+1;i<=n;i++)tmp2[i]=tmp[n-maxnum-(i-now2-1)];
            upd();
        }
    }
    if(bef)
    {
        for (int i = 1; i <= now; i++)tmp2[i] = minchar;
        for (int i = now + 1; i <= n; i++)tmp2[i] = s[n - bef - (i - now - 1)];
        upd();
    }
    printf("%s\n",res+1);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <math.h>
#include <algorithm>
#include <functional>
#include<iostream>
#include <string>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i,n) for(int i=0;i<n;i++)
#define fro(i,j,n) for(int i=j;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)


int main() {
    string x;
	cin >> x;
    string ans="Yes";
    fr(i,x.size()){
      if(x[i]=='L'&&i%2==0)ans="No";
      if(x[i]=='R'&&i%2==1)ans="No";
    }
      cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b;
    char ch;
    scanf("%d %c %d",&a,&ch,&b);
    if(ch=='+')
        printf("%d\n",a+b);
    else if(ch=='-')
        printf("%d\n",a-b);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
const ll MOD=1e9+7;

vector<vector<int>> r(110);
vector<int> d(110),f(110);
int cnt=0;

void dfs(int now) {
    ++cnt;
    d[now]=cnt;
    rep(i,r[now].size()) {
        int next=r[now][i];
        if (d[next]==0) dfs(next);
    }
    ++cnt;
    f[now]=cnt;
}

int main() {
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    rep(i,n) {
        int u,k,v;
        cin >> u >> k;
        rep(j,k) {
            cin >> v;
            r[i].push_back(v-1);
        }
    }
    rep(i,n) {
        if (d[i]==0) dfs(i);
    }
    rep(i,n) cout << i+1 << ' ' << d[i] << ' ' << f[i] << endl;

    return 0;
}


Measured memory_bytes: 3216
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int i,n,loc,left,right;
char logg[2000],order[60];

int main(){
	for(scanf("%d",&n);n>0;n--){
		scanf("%s",logg);
		loc=30;left=30;right=30;
		order[30]=logg[0];
		for(i=1;i<(signed)strlen(logg);i+=3){
			if(logg[i]=='<'){
				if(loc==left)left--;
				loc--;
			}
			else{
				if(loc==right)right++;
				loc++;
			}
			order[loc]=logg[i+2];
		}
		for(i=left;i<=right;i++){printf("%c",order[i]);}
		printf("\n");
	}

	return 0;
}

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

int main(){
    string s, tuika[4] = {"maerd", "remaerd", "esare", "resare"};
    bool can=true, can2;
    cin >> s;
    reverse(s.begin(), s.end());
    for(int i=0; i<s.size();){
        can2 = false;
        for(int j=0; j<4; j++){
            if(s.substr(i, tuika[j].size()) == tuika[j]){
                i += tuika[j].size();
                can2 = true;
            }
        }
        if(!can2){
            can = false;
            break;
        }
    }
    if(can) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

int main(){
  int n,k,ans=0,ii;
  long long sum=0;
  cin>>n>>k;
  vector<long long> a(n,0),m(n,0),msum(n+1,0);
  REP(j,n){
    cin>>a.at(j);
    sum+=a.at(j);
  }
  
  for(int i=1; i*i<=sum; i++){
    if(sum%i) continue;
    REP(l,2){
      if(l) ii=sum/i;
      else ii=i;
      REP(j,n) m.at(j)=a.at(j)%ii;
      sort(m.begin(),m.end());
      REP(j,n) msum.at(j+1)=msum.at(j)+m.at(j);
      
      REP(j,n){
        long long front=msum.at(j+1)-msum.at(0),back=msum.at(n)-msum.at(j+1);
        if((front==(n-j-1)*ii-back) && (front<=k)) ans=max(ans,ii);
      }
    }
  }

  cout<<ans<<endl;
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> h(n);
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }
    int l = 0;
    int r = 0;
    int ans = 0;
    while (r < h.size() - 1) {
        if (h[r] < h[r + 1]) {
            l = r + 1;
        } else {
            ans = max(ans, r + 1 - l);
        }
        r++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9)+7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef pair<P, int> PP;
ll a[50];int n; 
bool ok() {
	bool res = true;
	rep(i, n) {
		if (a[i] >= n)res = false;
	}
	return res;
}
ll calsum() {
	ll res = 0;
	rep(i, n) {
		res += a[i];
	}
	return res;
}
int main() {
	cin >> n;
	ll sum = 0;
	rep(i, n) {
		cin >> a[i]; sum += a[i];
	}
	ll key = n * (n - 1);
	ll out = 0;
	if (sum < key) {
		while (!ok()) {
			sort(a, a + n,greater<ll>());
			out += a[0] / (ll)n;
			Rep(i, 1, n) {
				a[i] += a[0] / (ll)n;
			}
			a[0] %= n;
		}
	}
	else {
		rep(i, n) {
			a[i] %= (ll)(n + 1);
		}
		ll ma = 0;
		rep(i, n+1) {
			if (ok()) {
				ma = max(ma, calsum());
			}
			rep(j, n) {
				a[j] = (a[j] + 1) % (n + 1);
			}
		}
		out = sum - ma;
	}
	cout << out << endl;
	return 0;
}

Measured memory_bytes: 256
#include <string>
#include <algorithm>
#include <vector> 
#include <math.h>
#include <iostream>
using namespace std;
long long mod = 1000000000 + 7;


int main()
{
	int n;
	cin >> n;
	
	int ans = 180 * (n - 2);


	cout << ans << endl;
	return 0;

}


Measured memory_bytes: 256
import Data.Char

getInts :: IO [Int]
getInts = map read . words <$> getLine

infixl 1 |>
x |> f = f x

between :: Int -> Int -> Int -> Bool
between a b x = (a <= y) && (y <= b)
    where y = x |> show |> map digitToInt |> sum

main = do
  n:a:b:_ <- getInts
  [1..n] |> filter (between a b) |> sum |> show |> putStrLn


Measured memory_bytes: 892
N, M = map(int, input().split())

L, R = 0, float("inf")

for _ in range(M):
    l, r = map(int, input().split())
    if l > L:
        L = l
    if r < R:
        R = r

count = 0
if L <= R:
    for i in range(1, N+1):
        if L <= i <= R:
            count += 1

print(count)

Measured memory_bytes: 9120
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
        
n,m,k=map(int,input().split())
uf=UnionFind(n+1)
friendlist=[]
blocklist=[]
for i in range(n+1):
  friendlist.append([])
  blocklist.append([])
for i in range(m):
  a,b=map(int,input().split())
  friendlist[a].append(b)
  friendlist[b].append(a)
  uf.union(a,b)
for i in range(k):
  c,d=map(int,input().split())
  blocklist[c].append(d)
  blocklist[d].append(c)
for i in range(1,n+1):
  ans=uf.size(i)-1
  ans-=len(friendlist[i])
  for j in blocklist[i]:
    if uf.same(i,j):
      ans-=1
  print(ans)

Measured memory_bytes: 104628
n,m = gets.split.map(&:to_i)
a = []
m.times do |i|
  a << gets.split.map(&:to_i)
end
mx = 10 ** n - 1
mi = n == 1 ? 0 : (10 ** (n-1))

mi.upto(mx) do |i|
  flg = true
  t = i.to_s
  a.each do |s,c|
    flg = false if t[s-1].to_i != c
  end
  if flg
    p i
    exit
  end
end
p -1

Measured memory_bytes: 1788
package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Scan()
	t := sc.Text()

	for i := 0; i+1 < len(t); i++ {
		if t[i] == t[i+1] {
			fmt.Println("Bad")
			return
		}
	}
	fmt.Println("Good")

}

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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)


int main(void){


	ll L, R; cin >> L >> R;
	
	R = min(R, L+4038);

	int ans = 2018;

	for(ll i = L; i <= R; i++){
		for(ll j = i+1; j <= R; j++){
			int x = i*j%2019;
			ans = min(ans, x);
		}
	}


	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int a[10],b,c,i,j,n,f;

  scanf("%d",&n);
  for(i=0;i<n;i++){    
    c=0;f=1;
    for(j=0;j<10;j++)
      scanf("%d",&a[j]);
    b=a[0];
    for(j=1;j<10;j++){
      if(b>c){
	if(a[j]>b)
	  b=a[j];
	else if(a[j]>c)
	  c=a[j];
	else
	  f=0;
      }
      else{
	if(a[j]>c)
	  c=a[j];
	else if(a[j]>b)
	  b=a[j];
	else
	  f=0;
      }
    }
    if(f)
      puts("YES");
    else
      puts("NO");
  }
  return 0;
}

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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}


// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  ll N; cin >> N;

  vector<ll> a(N); rep(i, N) cin >> a[i];
  sort(a.begin(), a.end());
  ll tut = 0;
  rep(i, N-1) tut += a[i];
  
  // ll ans = 0;
  bool ok = tut > a[N-1];
  
  // cout << ans << endl;
  cout << (ok?"Yes":"No") << endl;
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


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


int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k,l,i;
    double temp;
    cin >> n >> k;
    double p[n];
    rep(i,n) cin >> p[i];
    vector<double> v;
    rep(i,k)
    {
        temp+=(p[i]+1)/2;
    }
    v.push_back(temp);
    repp(i,k,n)
    {
        temp+=(p[i]-p[i-k])/2;
        v.push_back(temp);
    }
    sort(v.begin(),v.end());
    l=v.size();
    cout << fixed << setprecision(7) << v[l-1];
}

Measured memory_bytes: 3956
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>

using namespace std;

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  for(int i = 0; i < n; i++){
    cin >> h[i];
  }
  sort(h.begin(), h.end());
  long long  s = 0;
  for(int i = 0; i < n - k; i++){
    s += h[i];
  }
  cout << s << endl;
}


Measured memory_bytes: 1024
import sys
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

x,n,*p = map(int,read().split())
nums=list(range(-1,102))
for a in p:
    nums.remove(a)
ans=min(nums,key=lambda y: (abs(y-x),y))
print(ans)

Measured memory_bytes: 9108
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = Integer.parseInt(sc.next());

		for(int i = 1; i <= X; i++) {
			if(i * (i+1) / 2 >= X) {
				System.out.println(i);
				break;
			}
		sc.close();
		}
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define ll long long
using namespace std;
char a[1000005];
int b[1000005];
int d[8]={1,-1,-1,1,-1,-1,1,1};
int fun1(int n)
{
	if(a[n-1]=='o')
	{
		if(b[n-1]==1&&b[n-2]==b[0])
		return 1;
		if(b[n-1]==-1&&b[n-2]!=b[0])
		return 1;
	}
	else  if(a[n-1]=='x')
	{
		if(b[n-1]==1&&b[n-2]!=b[0])
		return 1;
		if(b[n-1]==-1&&b[n-2]==b[0])
		return 1;
	}
	return 0;
}
int fun(int n){
	for(int i=1;i<n-1;i++)
	{
		if(a[i]=='o')
		{
			if(b[i]==1)
			{
				b[i+1]=b[i-1];
			}
			else
			    b[i+1]=-1*b[i-1];
		}
		else
		{
			if(b[i]==1)
			{
				b[i+1]=-1*b[i-1];
			}
			else
			    b[i+1]=b[i-1];
		}
	}
	if(a[0]=='o')
	{
		if(b[0]==1&&b[n-1]==b[1])
		return fun1(n);
		if(b[0]==-1&&b[n-1]!=b[1])
		return fun1(n);
	}
	else if(a[0]=='x')
	{
		if(b[0]==1&&b[n-1]!=b[1])
		return fun1(n);
		if(b[0]==-1&&b[n-1]==b[1])
		return fun1(n);
	}
	
	return 0;
}
int main()
{
	int n;
	int flog;
	scanf("%d",&n);
	cin>>a;
	for(int i=0;i<8;i+=2)
	{
		
		b[0]=d[i];
		b[1]=d[i+1];
		flog=fun(n);
		if(flog)
		break;
	}
	if(flog)
	{
		for(int i=0;i<n;i++)
		{
			if(b[i]==1)
		     printf("S");
		    else
		     printf("W");
		}
	}
	else
	printf("-1");
	printf("\n");
	return 0;
}


Measured memory_bytes: 2816
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class Main{
    public static void main(String[] Args) throws IOException{
        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        final int n = Integer.parseInt(br.readLine());
        final int[] h = new int[n+1];
        final StringTokenizer st = new StringTokenizer(br.readLine(), " ");
        for(int i = 1; i<=n; i++){
            h[i] = Integer.parseInt(st.nextToken());
        }
        buildMaxHeap(h, n);
        final StringBuilder sb = new StringBuilder();
        for(int i = 1; i<=n; i++)
            sb.append(' ').append(h[i]);
        System.out.println(sb);
    }
    private static void buildMaxHeap(int[] h, int n){
        for(int i = n>>>1; i>0; i--)
            maxHeapify(h, i, n);
    }
    private static void maxHeapify(int[] a, int i, int n){
        int learge = i;
        do{
            i = learge;
            final int l = i+i;
            final int r = l+1;
            if(l<=n&&a[i]<a[l]) learge = l;
            if(r<=n&&a[learge]<a[r]) learge = r;
            if(i!=learge){
                final int t = a[i];
                a[i] = a[learge];
                a[learge] = t;
                maxHeapify(a, learge, n);
            }
        }while(i!=learge);
    }
}

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

using ll = long long;
using P = pair<int, int>;
using edge = struct {int to; ll cost;};

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

const int di[] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int dj[] = {0, -1, 0, 1, 1, -1, 1, -1};
const int INF = 1001001001;

const int mod = 1000000007;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};
struct combination
{
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1)
  {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i)
      fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i)
      ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k)
  {
    if (k < 0 || k > n)
      return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

//long long gcd(long long a, long long b);
//long long lcm(long long a, long long b);

void solve()
{
  int n, m, x;
  cin >> n >> m >> x;
  int l=0, r=0;
  vector<int> a(m);
  rep(i, m) cin >> a[i];
  int now = x;
  while(now < n) {
    if(find(ALL(a), now) != a.end()) l++;
    now++;
  }
  now = x;
  while(now > 0) {
    if(find(ALL(a), now) != a.end()) r++;
    now--;
  }
  cout << min(l, r) << "\n";
}

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

Measured memory_bytes: 256
//#include"pch.h"
//#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<algorithm>
#include<iostream>

using namespace std;
int main() {

	string s;
	

	cin >> s;

	for (int i = 0; i < 26; i++) {
		for (int j = 0; j < s.size(); j++) {
			if (s[j] == 'a' + i)break;
			if (j == s.size() - 1) {
				cout << (char)('a' + i) << endl;
				return 0;
			}
		}
	}

	cout << "None" << endl;


	return(0);
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
	int i,a[10001],b[10001];
	for(a[0]=1,b[0]=1,i=1;a[i-1]!=0||b[i-1]!=0;i++) cin>>a[i]>>b[i];
	i--;
	for(int j=1;j<i;j++){
		for(int h=0;h<a[j];h++){
			for(int w=0;w<b[j];w++) cout<<'#';
			cout<<endl;
		}
		cout<<endl;
	}
	return 0;
}



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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int f(ll x) {
    if (x == 0) return 0;
    return f(x%__builtin_popcount(x)) + 1;
}

int main(){
    int n;
    cin >> n;
    string x;
    cin >> x;
    int pcnt = 0;
    rep(i, n) if (x[i] == '1') ++pcnt;
    vll ans(n);
    if (pcnt==0) {
        rep(i, n) cout << 1 << endl;
        return 0;
    }
    vi plus(n), minus(n);
    ll plusx = 0, minusx = 0;
    plus[0] = 1 % (pcnt+1);
    rep(i, n-1) {
        plus[i+1] = plus[i] * 2 % (pcnt+1);
    }
    rep(i, n) {
        if (x[n-i-1] == '1') plusx = (plusx + plus[i]) % (pcnt+1); 
    }
    if (pcnt-1>0) {
        minus[0] = 1 % (pcnt-1);
        rep(i, n-1) {
            minus[i+1] = minus[i] * 2 % (pcnt-1);
        }
        rep(i, n) {
            if (x[n-i-1] == '1') minusx = (minusx + minus[i]) % (pcnt-1); 
        }
    }
    rep(i, n) {
        if (x[i] == '1') {
            if (pcnt == 1) ans[i] = 0;
            else {
                ll next = (minusx - minus[n-1-i] + (pcnt-1)) % (pcnt-1);
                ans[i] = f(next) + 1;
            }
        }
        else {
            ll next = (plusx + plus[n-1-i]) % (pcnt+1);
            ans[i] = f(next) + 1;
        }
    }
    rep(i, n) {
        cout << ans[i] << endl;
    }
    return 0;
}


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

using namespace std;

int MAX = 999999999;
int MIN = 1000000009;
int N = 1000009;

int n;
string s;

int main()
{
  cin >> n >> s;
  string ss = "ABC";
  int ans = 0;
  for (int i = 0; i < n; i++)
  {
    if (ss == s.substr(i, 3))
      ans++;
  }
  cout << ans << endl;
  return 0;
}

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

long long n, m, ans;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
 	
	cin >> n >> m;

	long long tmp = min(n, m/2);
	n -= tmp;
	m -= 2*tmp;
	ans += tmp;

	cout << ans + m / 4 << '\n';
	
	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
 


public class Main {
	static int a1[]= {0,-1,0,1};
	static int b1[]= {-1,0,1,0};
	private static         Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static int K,N;
	static long mod =1000000007;
	public static void main(String[] args) {
		int N=sc.nextInt();
		int M=sc.nextInt();
		int v[]=new int[M];
		for(int i=0;i<N;i++) {
			int k=sc.nextInt();
			for(int a=0;a<k;a++) {
				v[sc.nextInt()-1]++;
			}
		}
		int ans=0;
		for(int i:v) {
			if(i==N)ans++;
		}
		p(ans);
	}

	
	//static ArrayList<Integer> cc = new ArrayList<>(10001);
	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


Measured memory_bytes: 21844
n = int(input())
robot = []
for i in range(n):
    pos, arm = map(int, input().split())
    robot.append([pos-arm, pos+arm])
robot.sort(key=lambda x: x[1])
ans =[robot[0]]
for i in range(1, n):
    if ans[-1][1] <= robot[i][0]:
        ans.append(robot[i])
print(len(ans))

Measured memory_bytes: 68184
#include <bits/stdc++.h>
using namespace std;
const int N = 2001;
int n,k,q,a[N],ans = 1e9 + 9;
vector<int>temp,b;
void add(){
	sort(temp.rbegin(),temp.rend());
	while(temp.size() >= k)b.push_back(temp.back()),temp.pop_back();
	temp.clear();
}
int main(){
	//freopen("readin.txt","r",stdin);
	scanf("%d%d%d",&n,&k,&q);
	for(int i = 0;i < n;i++)scanf("%d",a + i);
	for(int i = 0;i < n;i++){
		b.clear();temp.clear();
		for(int j = 0;j < n;j++)
			if(a[j] < a[i])add();
			else temp.push_back(a[j]);
		add();
		sort(b.begin(),b.end());
		if(b.size() >= q)ans = min(ans,b[q - 1] - b[0]);
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 256