akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3




def main():
    # Failed to predict input format
    N = int(input())
    x = [ [] for i in range(N+1)]
    for i in range(N):
        a = int(input())
        for j in range(a):
            x[i].append(list(map(int, input().split())))

    # print(x)
    ans = 0
    for i in range(1<<N):
        y = [[] for k in range(N+1)]
        for j in range(N):
            if (i>>j) &1:
                for k in range(len(x[j])):
                    a, b = x[j][k]
                    # print(a-1, b)
                    y[a].append(b)

        if all([j == [] or j.count(1) == len(j) or j.count(0) == len(j) for j in y[1:]]):
            # print('{:05b}'.format(i), y)
            # if all([(i>>idx)&1 for idx, k in enumerate(y[1:], 1) if k.count(1) == len(k)]):
            #     ans = max(ans, bin(i).count('1'))
            #     print(bin(i), y, 'ok')
            # f = True
            # for idx, k in enumerate(y[1:], 1):
            #     if k.count(0) == len(k):
            #         if not (i>>(idx-1))&0:
            #             f = False
                        

            #     elif k.count(1) == len(k):
            #         if not (i>>(idx-1))&1:
            #             f = False
            #         else:
            #             print('t')
            # if f:
            #     ans = max(ans, '{:05b}'.format(i).count('1'))
            f = True
            for idx, k in enumerate(y[1:], 1):
                if k == []:
                    continue

                elif k != [] and k[0] == 0 and not i>>(idx-1)&1:
                    continue

                elif k != [] and k[0] == 1 and i>>(idx-1)&1:
                    continue

                else:
                    f = False
            if f:
                # print('{:05b}'.format(i), y, 'ok')
                ans = max(ans, '{:05b}'.format(i).count('1'))
                





    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <stdio.h>

int main()
{
	int A, B;
	scanf("%d %d", &A, &B);
	if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) printf("Possible\n");
	else printf("Impossible\n");
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1620
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <cassert>

using namespace std;
using ll = long long;

int dist[100005][3];
const int INF = 1001001001;

int main()
{
    int n, m;
    cin >> n >> m;
    for(int i = 0; i< n; i++){
        for(int j = 0; j < 3; j++){
            dist[i][j] = INF;
        }
    }
    vector<vector<int>> to(n);
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        a--; b--; 
        to[a].push_back(b);
    }
    queue<pair<int, int>> q;
    int s, t;
    cin >> s >> t;
    s--; t--;
    q.push({s, 0});
    dist[s][0] = 0;
    while(!q.empty()){
        int v = q.front().first;
        int l = q.front().second;
        q.pop();
        for(int u : to[v]){
            int nl = (l+1)%3;
            if(dist[u][nl] != INF) continue;
            dist[u][nl] = dist[v][l] + 1;
            q.push({u, nl});
        }
    }
    int ans = dist[t][0];
    if(dist[t][0] == INF) ans = -1;
    else ans /= 3;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9860
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
V<ll>fac,rfac;void setFac(int n,int mod){fac=rfac=V<ll>(++n);fac[0]=1;FOR(i,1,n)fac[i]=fac[i-1]*i%mod;rfac[n-1]=modInv(fac[n-1],mod);FORR(i,n-1,1)rfac[i-1]=rfac[i]*i%mod;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 2001;
int DP[N][N], cb[N][N], cw[N][N];
int n, ib[N], iw[N];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  iw[0] = ib[0] = -1;
  FOR(i, 0, n*2){
    char c;
    int a;
    cin >> c >> a;
    (c=='W' ? iw : ib)[a] = i;
  }
  FOR(i, 1, n+1){
    int bb = 0, ww = 0;
    FOR(j, 0, i) bb += ib[j]>ib[i], ww += iw[j]>iw[i];
    FOR(j, 0, n+1) cb[i][j] = (bb+=iw[j]>ib[i]), cw[j][i] = (ww+=ib[j]>iw[i]);
  }
  Fill(DP, IINF);
  DP[0][0] = 0;
  FOR(i, 0, n+1)FOR(j, 0, n+1){
    if(i)mins(DP[i][j], DP[i-1][j]+cb[i][j]);
    if(j)mins(DP[i][j], DP[i][j-1]+cw[i][j]);
  }
  cout << DP[n][n] << endl;
}

Measured memory_bytes: 47232
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <utility>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vec vector
#define INF INT_MAX
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

using namespace std;


int main(){
    int n;
    cin>>n;
    vec<int> v(100010,0);
    rep(i,0,n){
        int x; cin>>x;
        v[x]++;
    }
    //以下矛盾確認
    if(n%2==0){
        for(int i=1;i<=n-1;i+=2){
            if(v[i]!=0&&v[i]!=2){
                cout<<0<<endl;
                return 0;
            }
        }
    }else {
        if(v[0]!=1){
            cout<<0<<endl;
            return 0;
        }
        for(int i=2;i<=n-1;i+=2){
            if(v[i]!=0&&v[i]!=2){
                cout<<0<<endl;
                return 0;
            }
        }
    }

    ll ans=1;
    rep(i,0,n/2){
        ans*=2;
        ans%=MOD;
    }
    cout<<ans<<endl;


    
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdlib>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<cmath>

using namespace std;
int main(){
    string s;
    cin >> s;
    
    string t;
    cin >> t;
    
    int cnt(0);
    if(s[0] == t[0])cnt++;
    if(s[1] == t[1])cnt++;
    if(s[2] == t[2])cnt++;
    
    cout << cnt << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#define o 100005
using namespace std;
int n, a[o], f[o];
inline int ab(const int &x) {
	return x > 0 ? x : -x;
}
inline int g(const int &x, const int &y) {
	return ab(a[x] - a[y]);
}
signed main(signed argc, char **argv) {
	for(int i = scanf("%d", &n); i <= n; ++i)
		scanf("%d", a + i);
	for(int i = (f[2] = g(1, 2), 3); i <= n; ++i)
		f[i] = min(f[i - 1] + g(i - 1, i),\
		           f[i - 2] + g(i - 2, i));
	return 0 & printf("%d\n", f[n]);
}

Measured memory_bytes: 896
// V solo
#include <bits/stdc++.h>

#define forn(i, a, b) for (int i = a; i <= b; ++i)
#define forr(i, a, b) for (int i = a; i >= b; --i)

using namespace std;

const int N = (int)1e5 + 7;
const int INF = 1e9 + 7;

typedef long long ll;
typedef long double ld;

typedef pair < int, int > pii;
typedef pair < ll, ll > pll;

int n, a[N];
vector < int > cnt(N);
int main (){
  scanf ("%d", &n);
  forn (i, 1, n) scanf ("%d", a + i), cnt[a[i]]++;
  int mx = 0;
  forn (i, 1, N - 2){
    mx = max(mx, cnt[i - 1] + cnt[i] + cnt[i + 1]);
  }
  printf ("%d\n", mx);
  return 0;
}


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

def main():
    N = int(readline())
    S = readline().strip()

    R = S.count("R")
    G = S.count("G")
    B = S.count("B")

    ans = R * G * B
    for i in range(N-1):
        for j in range(i+1,N):
            k = 2 * j - i
            if k < N and S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                ans -= 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9212
#include<iostream>
#include<stdio.h>
#include<vector>

using namespace std;

int main(){

    int n, w_max;
    cin>> n>> w_max;

    int dp[n+1][w_max+1];
    for(int i=0; i<n+1; i++){
        dp[i][0] = 0;
    }
    for(int j=0; j<w_max+1; j++){
        dp[0][j] = 0;
    }

    vector<pair<int, int> > item(n+1); //first:value, second:weigh
    for(int i=1; i<n+1; i++){
        cin>> item[i].first>> item[i].second;
    }

    for(int i=1; i<n+1; i++){
        for(int j=1; j<w_max+1; j++){
            if(j<item[i].second){
                dp[i][j] = dp[i-1][j];
            }else{
                dp[i][j] = max(dp[i-1][j], dp[i-1][j-item[i].second]+item[i].first);
            }
        }
    }
    cout<< dp[n][w_max]<< endl;

    return 0;
}

Measured memory_bytes: 5140
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    std::ios::sync_with_stdio(false);
    ll a;
    double b;
    cin >> a >> b;
    ll B;
    B = b * 100 + 0.5;
    cout << (ll)(a * B) / 100 << endl;
    return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
const int con=8;
int N;
int Nums[100001]={};
bool serch(long long a){
   
}
int main(void)
{
  int num[3];
  string count="No";
  for(int i=0;i<3;i++){
    cin >> num[i];
  }
  if(num[0]==num[1]&&num[2]!=num[1])count="Yes";
  if(num[2]==num[1]&&num[0]!=num[1])count="Yes";
  if(num[2]==num[0]&&num[0]!=num[1])count="Yes";
  cout <<count<< endl;
  return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

const int C_10PW9 = 1000000000;

int main()
{
	string s;
	cin >> s;
	int q;
	cin >> q;
	int tc = 0;
	for (int i = 0; i < q; i++) {
		int t;
		cin >> t;
		if (t == 1) {
			tc++;
		}
		else {
			int f;
			string c;
			cin >> f >> c;
			int iq = 2;
			if (tc % 2 == 0) {
				iq = 1;
			}
			if (f == iq) {
				s.insert(0, c);
			}
			else {
				s += c;
			}
		}
	}

	if (tc % 2 == 1) {
		reverse(s.begin(), s.end());
	}
	cout << s;
}


Measured memory_bytes: 900
N = int(input())
s_li = [input() for i in range(N)]
M = int(input())
t_li = [input() for i in range(M)]
cost_dic = {}
for i in range(N) :
    cost_dic[s_li[i]] = s_li.count(s_li[i]) - t_li.count(s_li[i])
cost_sorted = sorted(cost_dic.items(), key=lambda x:x[1],reverse=True)
print(max(0, cost_sorted[0][1]))


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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

main() {
  string a, b, c;
  cin >> a >> b >> c;

  cout << ((a.back() == b.front() && b.back() == c.front()) ? "YES" : "NO")
       << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
#include <queue>
#include <map>
using namespace std;

map< int, int > m;
int n, tmp;
int main( ) {
	scanf( "%d", &n );
	for( register int i = 1; i <= n; i++ ) { scanf( "%d", &tmp ); m[tmp]++; }
	scanf( "%d", &n );
	/*
	for( map< int, int >::iterator it = m.begin(); it != m.end(); it++ ) {
		printf( "%d %d\n", it->first, it->second );
	}*/
	for( register int i = 1; i <= n; i++ ) {
		scanf( "%d", &tmp );
		if( m.count(tmp) == 0 ) { printf( "NO\n" ); return 0; }
		else {
			if( m[tmp] == 0 ) {
				printf( "NO\n" ); return 0;
			} else m[tmp]--;
		}
	}
	printf( "YES\n" );
	return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

  int n, k, q;
  cin >> n >> k >> q;

  vector<int> v(n, k - q);
  rep(i, 0, q) {
    int a;
    cin >> a;
    v[a - 1]++;
  }

  rep(i, 0, n) {
    if (v[i] > 0)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
	int ta,ba,tb,bb;
  	cin >> ta >> ba;
    cin >> tb >> bb;
  	while(1>0){
    	tb -= ba;
      	if(tb<=0){
        cout << "Yes"<<endl;
        break;
        }
      	ta -= bb;
     	if(ta<=0){
        cout << "No"<<endl;
        break;
        }
    }
	}

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

int main() {
	int N, K;
	cin >> N >> K;
	vector<int> v(N);
	rep(i, N) {
		cin >> v.at(i);
	}

	if (K > 40) {
		rep(i, N) {
			std::cout << N << ' ';
		}
		std::cout << endl;
		return 0;
	}

	bool f = true;
	vector<int> w(N);
	vector<int> n(N);
	int a=0, b=0, c=0, x, y, z;
	rep(i, K) {
		rep(j, N) {
			if (f) {
				x = max(0, j-v.at(j));
				y = min(N-1, j+v.at(j));
				w.at(x)++;
				if (y+1<N) w.at(y+1)--;
			} else {
				x = max(0, j-w.at(j));
				y = min(N-1, j+w.at(j));
				v.at(x)++;
				if (y+1<N) v.at(y+1)--;
			}
		}
		rep1(j, N) {
			if (f) {
				w.at(j) += w.at(j-1);
			} else {
				v.at(j) += v.at(j-1);
			}
		}
		rep(j, N) {
			if (f) {
				v.at(j) = 0;
			} else {
				w.at(j) = 0;
			}
		}
		f = !f;
	}

	if (f) {
		rep(i, N) {
			std::cout << v.at(i) << ' ';
		}
	} else {
		rep(i, N) {
			std::cout << w.at(i) << ' ';
		}
	}
	std::cout << endl;
}


Measured memory_bytes: 5624
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n, a, b; cin >> n >> a >> b;

    ll ans = n / (a + b) * a;
    ll res = n % (a + b);

    if(res >= a){
        ans += a;
    }
    else{
        ans += res;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;

int main() {
  
  int a,b,c,d;
  string s,ss,sss;
  
  int ans = 0;
  string anss = "";
  
  int ab [] = {0 , 1 , 3 , 1 , 2 , 1 , 2 , 1 , 1 , 2 , 1 , 2 , 1};
  
  cin >> a >> b;

  if (a+b >= 10) cout << "error" << endl;
  else cout << a+b << endl;
  
  //cout << anss << endl;

}

Measured memory_bytes: 256
#include <math.h>

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define PI 3.14159265358979323846264338327950L
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

char toupr(char c) { return (c - 0x20); }

int main() {
  string A, B, C;

  cin >> A >> B >> C;

  cout << toupr(A[0]) << toupr(B[0]) << toupr(C[0]) << endl;
}


Measured memory_bytes: 256
n = int(input())
s = input()
bag = []
cnt = 0
for i in s:
    if i == "I":
        cnt += 1
        bag.append(cnt)
    else:
        cnt -= 1
        bag.append(cnt)
ans = max(bag)
if ans < 0:
    print(0)
else:
    print(ans)

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

ifstream in ("test.in" );
ofstream out("test.out");

const int DIM = 2e5 + 5;
const int INF = 0x3f3f3f3f;

map<int, bool> mmp[DIM];

int main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(); cout.tie();
    
    long long k;
    cin >> k;
    
    for (int i = 2; i <= 50; ++i) {
        long long mnm, mxm;
        
        if (k % i == 0)
            mnm = mxm = (i - 1) + (k / i);
        else {
            mnm = (i - 1) + (k / i) - (k % i);
            mxm = (i - 1) + (k / i) - (k % i - 1) + i;
        }
        
        if (mnm >= 0 && mxm <= 1e16 + 1e3) {
            cout << i << endl;
            for (int j = 1; j <= k % i; ++j)
                cout << mxm << " ";
            for (int j = k % i + 1; j <= i; ++j)
                cout << mnm << " ";
            
            break;
        }
    }
    
    
    
    return 0;
}


Measured memory_bytes: 9600
n = int(input())
d = {}
for i in range(1, n+1):
    a = int(input())
    d[i] = a

i = 1
visited = set()
steps = 0
while i!= 2 and i not in visited:
    visited.add(i)
    i = d[i]
    steps += 1

if i == 2:
    print(steps)
else:
    print(-1)




Measured memory_bytes: 22360
#include <stdint.h>
#include <stdio.h>
using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using s8 = int8_t;
using s16 = int16_t;
using s32 = int32_t;
using s64 = int64_t;
// using float
// using double

#include <algorithm>
#include <map>
#include <vector>

typedef pair<s32,s32> pairRecord;

int main() {
  s32 N;
  scanf("%d", &N);
  vector<pairRecord> vRecords(N); //pair(出席番号, 記録)

  s32 record;
  for(s32 i=0; i < N; i++){
    scanf("%d", &record);
		vRecords[i] = make_pair(i+1,record);
	}
  sort(vRecords.begin(), vRecords.end(), [](const pairRecord &a, const pairRecord &b){return a.second<b.second;});

  // 出力
  for(auto record : vRecords){
    printf("%d ", record.first);
	}
}


Measured memory_bytes: 1664
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
#define ll long long
ll ans;
int a[8];
int main()
{
	for(int i=1;i<=7;++i)scanf("%d",&a[i]);
	ans+=a[2];ans+=2*(a[1]>>1);ans+=2*(a[4]>>1);ans+=2*(a[5]>>1);
	if((a[1]&1)&&(a[4]&1)&&(a[5]&1))ans+=3;
	else if((a[1]&1)&&(a[4]&1)&&(!(a[5]&1))&&a[5])ans+=1;
	else if((a[1]&1)&&(!(a[4]&1))&&(a[5]&1)&&a[4])ans+=1;
	else if((!(a[1]&1))&&(a[4]&1)&&(a[5]&1)&&a[1])ans+=1;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
def is_correct(disabled, val):
  for c in str(val):
    if c in disabled:
      return False
  return True

def main():
  n, k = [int(x) for x in raw_input().split(' ')]
  disabled = [x for x in raw_input().split(' ')]
  while not is_correct(disabled, n):
    n += 1
  print(n)

main()

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

#define lint long long

using namespace std;

//解説見た

int main() {
    int N;
    lint C;
    cin >> N >> C;
    
    vector<lint> x(N + 2), v(N), list(N + 2), ilist(N + 2);
    
    x[0] = 0; x[N + 1] = C;
    for(int i = 0; i < N; ++i){
        cin >> x[i + 1] >> v[i];
    }
    
    
    list[0] = 0; ilist[N + 1] = 0;
    for(int i = 1; i <= N; ++i){
        list[i] = list[i - 1] + v[i - 1];
        ilist[N - i + 1] = ilist[N - i + 2] + v[N - i];
    }
    
    vector<lint> f1(N + 1), f2(N + 1), g1(N + 1), g2(N + 1);
    g1[0] = 0; g2[0] = 0; f1[0] = 0; f2[0] = 0;

    for(int i = 1; i < N + 1; ++i){
        f1[i] = list[i] - x[i];
        g1[i] = max(f1[i], g1[i - 1]);
        
        f2[i] = list[i] - 2 * x[i];
        g2[i] = max(f2[i], g2[i - 1]);
    }
    
    lint ans = 0;
    for(int B = 1; B <= N + 1; ++B){
        lint cal1 = g2[B - 1] + ilist[B] - (C - x[B]);
        lint cal2 = g1[B - 1] + ilist[B] - 2 * (C - x[B]);
        ans = max(ans, max(cal1, cal2));
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 6528
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using Debug = System.Diagnostics.Debug;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;

class Ph
{
    static void Main()
    {
        string s = Console.ReadLine();
        Console.WriteLine(s.Length == 2 ? s : string.Join("", s.Reverse()));
        return;
        var nmd = Console.ReadLine().Split().Select(int.Parse).ToList();
        var a = Console.ReadLine().Split().Select(int.Parse).ToList();
        int[] swap = Enumerable.Range(0, nmd[0]).ToArray();
        for (int i = a.Count - 1; i >= 0; i--)
        {
            var tmp = swap[a[i] - 1];
            swap[a[i] - 1] = swap[a[i]];
            swap[a[i]] = tmp;
        }

        int[] res = Enumerable.Range(1, nmd[0]).ToArray();
        while (nmd[2] > 0)
        {
            if ((nmd[2] & 1) == 1) res = Operate(res, swap);
            swap = Operate(swap, swap);
            nmd[2] >>= 1;
        }
        Console.WriteLine(string.Join("\n", res));
    }

    static int[] Operate(int[] a, int [] op)
    {
        var res = a.ToArray();
        for (int i = 0; i < op.Length; i++)
        {
            res[i] = a[op[i]];
        }
        return res;
    }
}

Measured memory_bytes: 13140
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String s = sc.next();
    String t = s.substring(n/2);
    String ans = "";
    //System.out.println(t);
    if(s.startsWith(t)&&(n%2==0)){
      ans = "Yes";
    }else{
      ans = "No";
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21972
while True:
    a, op, b = [x for x in input().split()]
    a, b = int(a), int(b)
    if op == "?":
        break
    elif op == "+":
        c = a + b
    elif op == "-":
        c = a - b
    elif op == "*":
        c = a * b
    else:
        c = a // b
    print(c)

Measured memory_bytes: 7732
#include <iostream>
using namespace std;
int main(void){
    int n,a[2][101],max=0;
    cin>>n;
    for(int i=0;i<2;i++){
        a[i][0]=0;
        for(int j=1;j<=n;j++){
            cin>>a[i][j];
            a[i][j]+=a[i][j-1];
        }
    }
    
    
    
    for(int i=1;i<=n;i++){
        if(a[0][i]+a[1][n]-a[1][i-1]>=max){
            max=a[0][i]+a[1][n]-a[1][i-1];
        }
    }
    
    cout<<max<<endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atc_0031
{
    class Program
    {
        static void Main(string[] args)
        {
            double N = double.Parse(Console.ReadLine());

            Console.WriteLine(N * N * N / 27);

        }
    }
}


Measured memory_bytes: 27460
#include<bits/stdc++.h>
 
// @author : sam000013
 
#define int long long
 
#define PI 3.14159265
#define pb(x) push_back(x)
#define all(v) v.begin(), v.end()
#define endl cout<<"\n" 
#define dbg(x) cout<<#x<<" "<<x;endl;
#define bye endl;return
#define uni 1.000000
using namespace std;

const int mod = 1000000007;
template <typename T>

void debug(vector<T> x)
{
    for (auto e : x)
    {
        cout << e << " ";
    }
    cout << "\n";
}
/*


*/



void solve(){
    string s;
    cin>>s;
    int n = s.size();
    if(s[n-1] == 's'){
        s += "es";
    }else{
        s += "s";
    }
    cout<<s;endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    //    cin >> t;
    for (int i = 1; i <= t; i++)
    {
        solve();
    }
    return 0;
}


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

int main(){
  ll n,min=0;
  cin >> n;
  vector<ll> a;
  
  for(ll i=1; i<=sqrt(n); i++){
    if(n%i==0) a.push_back(i);
  }
  ll b=a.size();
  
  for(ll i=0; i<b; i++)
    min=a[i]+n/a[i]-2;
  
  cout << min << endl;
}


Measured memory_bytes: 3720
#include <iostream>
#include <stack>
#include <vector>
using namespace std;

int main(void){
  string str;
  while(getline(cin, str) && str != "."){
    string c;
    for(int i = 0; i < str.size(); i++){
      if(str[i] == ')' || str[i] == '(' || str[i] == '[' || str[i] == ']'){
        c += str[i];
      }
    }
    stack<char> s;
    bool f = true;
    for(int i = 0; i < c.length(); i++){
      if(s.empty() || c[i] == '(' || c[i] == '['){
        s.push(c[i]);
      }else if((s.top() == '(' && c[i] == ')') || (s.top() == '[' && c[i] == ']')){
        s.pop();
      }else{
        f = false;
        break;
      }
    }
    cout << (f && s.empty() ? "yes" : "no") << endl;
  }
  return 0;
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

const int limit = 50;

int n, m;
int a[limit], b[limit];

bool graph[limit][limit];
bool visited[limit];

void dfs(int v){
    visited[v] = true;
    for(int v2 = 0; v2 < n; v2++){
        if(graph[v][v2] == false) continue;
        if(visited[v2] == true) continue;
        dfs(v2);
    }
}

int main(){
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
    }
    int ans = 0;
    for(int i = 0; i < m; i++){
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;

        for(int j = 0; j < n; j++) visited[j] = false;

        dfs(0);

        bool bridge = false;
        for(int j = 0; j < n; j++)
            if(visited[j] == false) bridge = true;

        if(bridge) ans++;
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<stdio.h>
#include<time.h>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int qx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int qy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(void) {
	while(true) {
		int n, m;
		cin>>n>>m;
		if(n == 0 && m == 0) break;
		vector<int> s1(n);
		vector<int> s2(m);
		int sum1 = 0;
		int sum2 = 0;
		REP(i, n) {
			cin>>s1[i];
			sum1 +=s1[i];
		}
		REP(i, m) {
			cin>>s2[i];
			sum2 += s2[i];
		}
		int a = -1;
		int b = -1;
		int ansum = INF;
		if((sum1 - sum2) % 2 != 0) {
			cout<<-1<<endl;
			continue;
		}
		REP(i, n) {
			REP(j, m) {
				if(s1[i] - s2[j] == (sum1 - sum2) / 2 && s1[i] + s2[j] < ansum) {
					a = s1[i];
					b = s2[j];
					ansum = a + b;
				}
			}
		}
		if(ansum != INF) cout<<a<<" "<<b<<endl;
		else cout<<-1<<endl;
	}
}

Measured memory_bytes: 3076
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;

int main(){
	ll a,b,k;
	cin>>a>>b>>k;
	REP(i,k){
		if(i%2==0){
			if(a%2==1){
				a--;
			}
			b+=a/2;
			a/=2;
		}
		else{
			if(b%2==1){
				b--;
			}
			a+=b/2;
			b/=2;
		}
	}
	cout<<a<<" "<<b<<endl;
	return 0;
}

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

using namespace std;

int main()
{
    int n;
    int array[200005];
    vector<int> front, back;

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

    for (int i = 1; i <= n; i++) {
        if (i & 1) {
            front.push_back(array[i]);
        } else {
            back.push_back(array[i]);
        }
    }

    if (n & 1) {
        for (int i = front.size() - 1; i >= 0; i--) {
            cout << front[i];
            if (i) {
                cout << " ";
            }
        }

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

        for (int i = back.size() - 1; i >= 0; i--) {
            cout << back[i];

            if (i) {
                cout << " ";
            }
        }

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

    return 0;
}


Measured memory_bytes: 4084
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
	string s;
	cin >> s;

	int ans = 0;
	int cnt = 0;

	for (int i = 0; i < s.length(); i++)
	{
		if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T')
		{
			cnt++;
		}
		else
		{
			ans = max(ans, cnt);
			cnt = 0;
		}
	}
	ans = max(ans, cnt);
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct _OMAZINAI_ { _OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } __omazinai_instance__;
#define INF (1LL<<61 + 1<<29)
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
void _INPUT_IMPL_() {};
template <class T, class... Args> void _INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; _INPUT_IMPL_(args...); }
void _OUTPUT_IMPL_() {};
template <class T, class... Args> void _OUTPUT_IMPL_(T dest, Args... args) { cout<< dest << (sizeof...(Args)?" ":""); _OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; _INPUT_IMPL_(__VA_ARGS__)
#define out(...) _OUTPUT_IMPL_(__VA_ARGS__)

int main() {
	in(ll, n, a);
	out(n*n - a);
}

Measured memory_bytes: 256
//Volume0-0084
import java.util.Scanner;

public class Main {

	public static void main(String[] args){

		String[] ward;
		boolean  flg = false;

        Scanner sc = new Scanner(System.in);
        ward = sc.nextLine().split("(\\.|\\s|,)");

        for(int i=0;i<ward.length;i++){
        	if(ward[i].length() >= 3 && ward[i].length() <= 6){
            	if(flg){System.out.print(" ");}
        		System.out.print(ward[i]);
            	flg = true;
        	}
        }
        System.out.println();
	}
}

Measured memory_bytes: 17144
A,B,C = [int(x) for x in input().split()]
K=int(input())
 
while(A>=B and K>0):
  B=B*2
  K-=1
 
while(B>=C and K>0):
  C=C*2
  K-=1

if B>A and C>B:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9184
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> P(M);
    vector<string> S(M);
    for(int i = 0; i < M; ++i){
        cin >> P[i] >> S[i];
    }

    int AC = 0, WA = 0;
    vector<int> ACtable(N);
    vector<int> WAtable(N);
    for(int i = 0; i < M; ++i){
        if(ACtable[P[i]-1] == 0){
            if(S[i] == "WA"){
                WAtable[P[i]-1] += 1;
            }else{
                AC++;
                ACtable[P[i]-1] = 1;
            }
        }
    }
    for(int i = 0; i < N; ++i){
        if(ACtable[i] == 1){
            WA += WAtable[i];
        }
    }
    cout << AC << " " << WA << endl;
    return 0;
}

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

int main(void){
	char str[100000];
	int i,n, count = 0;

	scanf("%d", &n);
	scanf("%s", str);
	for (i = 0; i < n-1; i++) {
		if (str[i] != str[i + 1])count++;
	}
	printf("%d", count + 1);
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
struct UF
{
	vector<int> par; // 親のインデックスを記憶する配列
	vector<int> sz; // サイズを記憶する。
	vector<int> rank;
	// 初期化
	UF(int n):par(n),sz(n),rank(n){
		for(int i = 0; i < n; i++){
			par[i] = i;sz[i] = 1;rank[i] = 0;
		}
	}
	// 親を求める
	int find(int x) {
		if (par[x] == x) return x;
		else return par[x] = find(par[x]);
	}
	// xとyの属する集合を併合
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
		if(rank[x] < rank[y]){
			par[x] = y;
			sz[y] += sz[x];
		}
		else{
			par[y] = x;
			sz[x] += sz[y];
			if(rank[x] == rank[y])rank[x]++;
		}
	}
	// xとyが同じ集合ならtrue
	bool same(int x, int y) { return find(x) == find(y); }
	// 素の集合のサイズを求める
	int size(int n){return sz[find(n)];}
};
int main()
{
	int n,m;
	std::cin>>n>>m;
	UF uf(n);
	std::vector<int>p(n);
	for(int i=0;i<n;i++)
	{
		std::cin>>p[i];
		p[i]--;
	}
	for(int i=0;i<m;i++)
	{
		int x,y;
		std::cin>>x>>y;
		x--;y--;
		uf.unite(x,y);
	}
	int ans=0;
	for(int i=0;i<n;i++)
	{
		if(uf.same(i,p[i]))
		{
			ans++;
		}
	}
	std::cout<<ans<<std::endl;
	return 0;
}

Measured memory_bytes: 1792
a,b,c = gets.split(" ").map(&:to_i)
ary =[]
a.times.each do
  ary << gets.split(" ").map(&:to_i)
end

cnt = 0
ary.each do |i,j|
  if (b <= i) && (c <= j)
  cnt += 1
  end
end
puts cnt


Measured memory_bytes: 1788
#include<iostream>
#include<fstream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<deque>
#include<set>
#include<map>
#include<bitset>
#include<ctime>
#include<queue>
using namespace std;
#define int long long
#define pii pair <int, int>
#define XX first
#define YY second

// constants:
const int mn = 200005;
const int mod = 1000000007;
const long long inf = 4444444444444444444;
const int sminf = 1111111111;
const bool is_multitest = 0;
const bool is_interactive = 0;

// i/o methods:
const bool input_from_file = 0;
const bool output_to_file = 0;
#define filename ""
#define in_extension "inp"
#define out_extension "out"

// data preprocessing: (e.g.: divisor generating, prime sieve)
void preprocess()
{
  
}

// global variables:
int n;
int A[mn], B[mn];
int cntA[mn], cntB[mn];
bool sort1(int a, int b) {
  if (cntA[a] + cntB[a] == cntA[b] + cntB[b]) return a<b;
  return cntA[a] + cntB[a] < cntA[b] + cntB[b];
}
// main solution goes here:
void execute(int test_number)
{
  cin>>n;
  // int u;
  for (int i=1; i<=n; i++) {
    cin>>A[i];
    cntA[A[i]]++;
  }
  for (int i=1; i<=n; i++) {
    cin>>B[i];
    cntB[B[i]]++;
  }

  for (int i=1; i<=n; i++) if (cntA[i] + cntB[i] > n) {
    cout<<"No\n";
    return;
  }

  cout<<"Yes\n";
  sort(A+1, A+n+1, sort1);
  sort(B+1, B+n+1, sort1);
  int ptrA = n, ptrB = n;
  vector <pii> ans;
  while (ans.size() < n) {
    if (sort1(A[ptrA], B[ptrB])) {
      int u = B[ptrB];
      while (ans.size() < n) {
        if (B[ptrB] != u) break;
        ans.push_back({0, u});
        ptrB--;
      }
    } else {
      int u = A[ptrA];
      while (ans.size() < n) {
        if (A[ptrA] != u) break;
        ans.push_back({u, 0});
        ptrA--;
      }
    }
  }

  for (int i=0; i<n; i++) {
    if (ans[i].XX == 0) {
      ans[i].XX = A[ptrA];
      ptrA--;
    } else {
      ans[i].YY = B[ptrB];
      ptrB--;
    }
  }

  sort(ans.begin(), ans.end());
  for (int i=0; i<n; i++) cout<<ans[i].YY<<" ";
}
// REMEMBER TO CHOOSE TEST METHODS
// PLEASE REMOVE cout AND cerr DEBUG LINES BEFORE SUBMITTING PROBLEMS
// Solution by low_



















signed main()
{
#ifdef lowie
    if (!is_interactive)
    {
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
#else
    if (input_from_file) freopen(filename"."in_extension, "r", stdin);
    if (output_to_file) freopen(filename"."out_extension, "w", stdout);
#endif
    if (!is_interactive)
    {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    }

    preprocess();
    int ntest;
    if (is_multitest) cin >> ntest;
    else ntest = 1;

    for (int testno = 1; testno <= ntest; testno++)
    // use for instead of while to serve facebook hacker cup test format
    {
        execute(testno); // only start coding in this function, not in main
    }
}
// Template by low_
// Contact me via mail: ttuandung1803@gmail.com
// ...or codeforces: https://www.codeforces.com/profile/low_
// ...or linkedIn: https://www.linkedin.com/in/daniel-to-83045a19a/
// I use VS Code. Here's a JSON format for my template: https://pastebin.com/xH2yRdwx


Measured memory_bytes: 13672
#https://atcoder.jp/contests/abc066/tasks/arc077_a
N = int(input())
N_List = list(map(str,input().split()))
if N % 2 == 0:
    ans = ' '.join(reversed(N_List[1::2])) + ' ' + ' '.join(N_List[::2])
else:
    ans = ' '.join(reversed(N_List[::2])) + ' ' + ' '.join(N_List[1::2])

print(ans)

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

int i;

int main(){

	cin >> i;

	if (i == 25){
		cout << "Christmas" << endl;
	}else if (i == 24){
		cout << "Christmas Eve" << endl;
	}
	else if (i == 23) {
		cout << "Christmas Eve Eve" << endl;
	}
	else if (i == 22){
		cout << "Christmas Eve Eve Eve" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned long long
#define rep(i,n,N) for(int i=n;i<=N;++i)
#define rap(i,n,N) for(int i=n;i>=N;--i)
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define ff fi.fi
#define fs fi.se
#define sf se.fi
#define ss se.se
#define lc (id<<1)
#define rc ((id<<1)|1)
#define db(x) cerr << ">>>>>> " << #x << " -> " << x << endl
#define nani(x) cerr <<  "Line " << __LINE__ << ": " << #x << " is " << x << endl
#define all(x) x.begin(),x.end()
#define pii pair<int,int> 
#define pll pair<ll,ll>
#define plll pair<ll,pll>
#define pllll pair<pll,pll>
#define piii pair<int,pii>
#define piiii pair<pii,pii>
#define psi pair<string,int>
#define endl '\n'
const int MAX = 1e5+5;
const ll MAX2 = 11;
const int MOD = 1000000007;
const ll MOD2 = 1000000006;
const ll INF = 2e18;
const int dr[]={1,0,-1,0,1,1,-1,-1,0};
const int dc[]={0,1,0,-1,1,-1,1,-1,0};
const double pi = acos(-1);
const double EPS = 1e-9;
const int block = 2000;

int k,n,q,nw,mn,mx,a,b,x[MAX],ans[MAX],tmp;
vector<int> v[MAX];
pii z[MAX];
bool mv;

int main(){
//	cout<<fixed<<setprecision(10);
//    freopen("input.txt", "r", stdin);
//	freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>k>>n;
    rep(i,1,n)cin>>x[i];
    b = mx = k;
    cin>>q;
    rep(i,1,q)cin>>z[i].fi>>z[i].se, v[lower_bound(x+1,x+1+n,z[i].fi)-x].pb(i);
    ++n;
    rep(i,1,n){
		tmp = x[i] - x[i-1];
    	if(!mv){
    		for(auto j:v[i]){
    			if(z[j].se>=mn&&z[j].se<=mx)ans[j] = max(0,z[j].se+nw-(z[j].fi-x[i-1]));
    			else if(z[j].se<=mn)ans[j] = max(0,a-(z[j].fi-x[i-1]));
    			else ans[j] = max(0,b-(z[j].fi-x[i-1]));
			}
			if(i==n)break;
			nw-=tmp;
			mn = max(mn,-nw);
			a = max(0,a-tmp);
			b = max(0,b-tmp);
		}
		else {
    		for(auto j:v[i]){
    			if(z[j].se>=mn&&z[j].se<=mx)ans[j] = min(k,z[j].se+nw+(z[j].fi-x[i-1]));
    			else if(z[j].se<=mn)ans[j] = min(k,a+(z[j].fi-x[i-1]));
    			else ans[j] = min(k,b+(z[j].fi-x[i-1]));
			}
			if(i==n)break;
			nw+=tmp;
			mx = min(mx,k-nw);
			a = min(k,a+tmp);
			b = min(k,b+tmp);
		}
    	mv^=1;
	}
	rep(i,1,q)cout<<ans[i]<<endl;
    return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int n,k;
string p[11111];
int cnt[33];

int main(){
	cin.sync_with_stdio(false);
	cin>>n>>k;
	rep(i,n)cin>>p[i];
	rep(i,n){
		cnt[p[i][0]-'A']++;
	}
	priority_queue<int> que;
	rep(i,26){
		if(cnt[i]>0)que.push(cnt[i]);
	}
	int res=0;
	while(1){
		bool ok=true;
		vector<int> save;
		rep(i,k){
			if(que.empty()){
				ok=false;break;
			}
			int t=que.top(); que.pop();
			t--;
			if(t>0)save.pb(t);
		}
		if(ok)res++;
		else break;
		rep(i,save.size())que.push(save[i]);
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 768
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import qualified Data.Map.Strict             as Map
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

main = do
  n <- getInt
  as <- getIntList
  let as' = V.fromList as

  let x1 = (sum $ zipWith (*) as (concat $ repeat [1, -1])) `div` 2

  d <- VM.new n
  VM.write d 0 x1
  VM.write d (n-1) (as' V.! (n-1) - x1)

  forM_ [(n-2),(n-3)..1] $ \j -> do
    xjp1 <- VM.read d (j+1)
    let aj = as' V.! j
        xj = aj - xjp1
    VM.write d j xj

  putStr $ show (x1*2)
  forM_ [1..(n-1)] $ \i -> do
    x <- VM.read d i
    putStr $ " " ++ show (x*2)
  putStrLn ""


Measured memory_bytes: 14076
// ref. https://cf16-final.contest.atcoder.jp/data/other/cf16-final/editorial.pdf

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n, m;
  cin >> n >> m;
  vector<ll> x(n);
  ll maxX = 0;
  rep(i, n) {
    cin >> x[i];
    chmax(maxX, x[i]);
  }

  vector<ll> cnts(maxX + 1); // cnts[i] .. counts of i
  rep(i, n) {
    ++cnts[x[i]];
  }

  vector<vector<ll>> mp(m); // { x MOD m => <cnts> }
  rep(i, maxX + 1) {
    if (cnts[i] > 0) {
      mp[i%m].push_back(cnts[i]);
    }
  }

  // For Debug
  // rep(i, m) {
  //   cout << i << ": "; printvec(mp[i]);
  // }

  ll ans = 0;
  for (int i = 1; i < (m+1)/2; ++i) { // m=7 => (m+1)/2=4, m=8 => (m+1)/2=4
    auto& s = mp[i];
    auto& t = mp[m-i];
    ll s_sum = 0; for (ll cnt : s) { s_sum += cnt; }
    ll t_sum = 0; for (ll cnt : t) { t_sum += cnt; }

    if (t_sum > s_sum) {
      swap(t_sum, s_sum);
      swap(t, s);
    }
    // Here, t_sum <= s_sum
    ans += t_sum;
    ll s_remain = (s_sum - t_sum)/2; // we can make s_remain pairs in maximum case.
    sort(all(s)); reverse(all(s)); // s i decreasing order
    for (ll cnt : s) { // check each count in s
      ll now = min(cnt/2, s_remain); // we can make "now" pairs from cnt.
      s_remain -= now;
      ans += now;
    }
  }

  // check 0-case
  {
    ll s = 0; for (ll cnt : mp[0]) { s += cnt; }
    ans += s/2;
  }

  // check m/2-case
  if (m%2 == 0) {
    ll s = 0; for (ll cnt : mp[m/2]) { s += cnt; }
    ans += s/2;
  }

  cout << ans << endl;
}


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

const int N=105; 
int n,m,Ex,Ey;
short f[N][N][N][N],ans,sr[N][N],sc[N][N];
char s[N];
inline short r_sum(int x,int l,int r){return sr[x][r]-sr[x][l-1];}
inline short c_sum(int x,int l,int r){return sc[x][r]-sc[x][l-1];}
inline void upd(short&x,const short&y){x>y?:x=y;}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;++i){
		cin>>(s+1);
		for(int j=1;j<=m;++j){
			if(s[j]=='E'){Ex=i;Ey=j;}
			sr[i][j]=sr[i][j-1];
			sc[j][i]=sc[j][i-1];
			if(s[j]=='o'){sr[i][j]++;sc[j][i]++;}
		}
	}
	for(int i=Ex;i;--i)
		for(int j=Ex;j<=n;++j)
			for(int k=Ey;k;--k)
				for(int l=Ey;l<=m;++l){
					ans=max(ans,f[i][j][k][l]);
					if(i-1>j-Ex)upd(f[i-1][j][k][l],f[i][j][k][l]+r_sum(i-1,max(k,l-Ey+1),min(k+m-Ey,l)));
					if(j<n-Ex+i)upd(f[i][j+1][k][l],f[i][j][k][l]+r_sum(j+1,max(k,l-Ey+1),min(k+m-Ey,l)));
					if(k-1>l-Ey)upd(f[i][j][k-1][l],f[i][j][k][l]+c_sum(k-1,max(i,j-Ex+1),min(i+n-Ex,j)));
					if(l<m-Ey+k)upd(f[i][j][k][l+1],f[i][j][k][l]+c_sum(l+1,max(i,j-Ex+1),min(i+n-Ex,j)));
				}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 207104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int a, b, k;

int main()
{
    cin >> a >> b >> k;
    for (int i = a; k; i--)
    {
        k -= a % i == 0 && b % i == 0;
        if (k == 0)
        {
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256