akhauriyash/Code-Regression huggingface dataset:
s = input()
t = input()


def search(s, t):
    l_s = len(s)
    l_t = len(t)
    for i in range(l_s):
        if s[i] == t[0] or s[i] == '?':
            for j in range(l_t):
                if i+j < l_s:
                    if s[i+j] == t[j] or s[i+j] == '?':
                        if j == l_t-1:
                            return i
                        continue
                    else:
                        break
    return -1


s = s[::-1]
t = t[::-1]
ret = search(s, t)
if ret == -1:
    ans = 'UNRESTORABLE'
    print(ans)
else:
    ans = []
    for k in range(len(s)):
        if ret <= k <= ret+len(t)-1:
            ans.append(t[k-ret])
        else:
            if s[k] == '?':
                ans.append('a')
            else:
                ans.append(s[k])
    print(''.join(map(str, ans[::-1])))


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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    ll L, R;
    cin >> L >> R;
    for(ll x = L; x <= R; x++) {
        if (x % 2019 == 0) {
            cout << 0 << endl;
            return;
        }
    }
    ll ans = 2019 * 2019;
    for(ll x = L; x <= min(R, L + 2019); x++) {
        for(ll y = x + 1; y <= min(R, L + 2019); y++) {
            ans = min(ans, x * y % 2019);
        }
    }
    cout << ans << endl;
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

ll dp[100002];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N = getint(), M = getint();
	if (M > N / 2) printf("0");
	else {
		rep(i, M) {
			dp[getint() + 1] = 1;
		}

		dp[0] = 0;
		dp[1] = 1;
		const ll mod = 1e9 + 7;
		int meyasu = 0;
		rep1(i, N) {
			if (!dp[i + 1]) {
				dp[i + 1] = dp[i] + dp[i - 1];
				meyasu++;
				if (meyasu >= 30) {
					dp[i] %= mod;
					dp[i + 1] %= mod;
					meyasu = 0;
				}
			}
			else dp[i + 1] = 0;
		}
		printf("%lld", dp[N + 1] % mod);
	}

	Would you please return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#define rep(i,n) for (int i=0; i<(n);i++)
using namespace std;
using ll = long long;

ll choose2(ll n){
    return n*(n-1)/2;
}

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

    int n;
    cin >> n;
    vector<int> a(n);

    rep(i,n) cin >> a[i];
    rep(i,n) a[i]--;
    vector<int> cnt(n);
    rep(i,n) cnt[a[i]]++;

    ll sum = 0;
    rep(i,n){
        sum += choose2(cnt[i]); 
    }

    ll anssum;
    rep(i,n){
        anssum = sum;
        anssum -= choose2(cnt[a[i]]);
        anssum += choose2(cnt[a[i]]-1); 
         cout << anssum << "\n";
    }
}


Measured memory_bytes: 4224
import sys
sys.setrecursionlimit(100000)

def find(tab, a):
    if tab[0][a]==a:
        return a
    tab[0][a] = find(tab, tab[0][a])
    return tab[0][a]

def union(tab, a, b):
    p1, p2 = (find(tab, a), find(tab, b))
    if p1 != p2:
        tab[0][p1] = p2
        tab[1][p2] += tab[1][p1]

def size(tab, a):
    return tab[1][a]

N, M = [int(a) for a in input().split(" ")]
ABs = [[int(a) for a in input().split(" ")] for i in range(M)]
tab = [[i for i in range(N)], [1 for i in range(N)]]
arr = []

for a, b in reversed(ABs):
        a, b = (a-1, b-1)
        pa, pb = (find(tab, a), find(tab, b))
        na, nb = (size(tab, pa), size(tab, pb))
        if pa!=pb:
            dn = ((na+nb)*(na+nb-1)//2)-(na*(na-1)//2)-(nb*(nb-1)//2)
            arr.append(dn)
            union(tab, a, b)
        else:
            arr.append(0)

acc = 0
for cp in reversed(arr):
    acc += cp
    print(acc)


Measured memory_bytes: 42920
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int n,m;
    cin>>n>>m;
    pair<pair<int,int>,int> edge[m];
    int dp[n][n];
    fill(dp[0],dp[n],INF);
    for(int i=0;i<m;i++){
        int a,b,c;
        cin>>a>>b>>c;
        --a,--b;
        edge[i]={{a,b},c};
        dp[a][b]=dp[b][a]=c;
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            for(int k=0;k<n;k++){
                dp[j][k]=min(dp[j][k],dp[j][i]+dp[i][k]);
            }
        }
    }
    int ans=0;
    for(int i=0;i<m;i++){
        int a=edge[i].first.first;
        int b=edge[i].first.second;
        int c=edge[i].second;
        if(dp[a][b]!=c)ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1001001001
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

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

    ll a,b,c,d,m,n,maxi=0,f=0,mini=INF,sum=0;
    string str;
    cin>>a>>b;
    if(b%2) {
        No;
        return 0;
    }
    if(a*2<=b&&b<=a*4){
        Yes;
    }else{
        No;
    }
    return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N, D;
ll a[300050];
int main() {
    cin >> N >> D;
    ll Grundy = 0;
    for(int i = 1; i <= N; i++) {
        cin >> a[i];
        a[i] = a[i] + D;
        a[i] = a[i] % (D + 1);
        //cout << a[i] << endl;
        Grundy = Grundy ^ a[i];
    }
    if(Grundy == 0) cout << "Second" << endl;
    else cout << "First" << endl;
    return 0;
}


Measured memory_bytes: 5068
import sys

a=input()
b=input()
c=[]
d=[]
for i in range(len(a)):
    c.append(a[i])
for i in range(len(b)):
    d.append(b[i])
c.sort()
d.sort()
d.reverse()
for i in range(min([len(a),len(b)])):
    if(c[i]<d[i]):
        print("Yes")
        sys.exit()
if(len(a)<len(b)):
    if(a==b[0:len(a)]):
        print("Yes")
        sys.exit()
print("No")

Measured memory_bytes: 3064
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	var s, t []byte
	fmt.Scan(&s, &t)

	for i := 0; i < n; i++ {
		fmt.Print(string([]byte{s[i]}))
		fmt.Print(string([]byte{t[i]}))
	}
	fmt.Println()
}


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

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

    int tmp;
    while(true){
        if(a < b){
            tmp = a;
            a = b;
            b = tmp;
        }
        if(b < c){
            tmp = b;
            b = c;
            c = tmp;
        }

        if(a >= b && b >= c)
            break;
    }
    cout << a*10 + b + c << endl;
}

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

int main() {
  int n;
  cin >> n;
  while (n) {
    if (n % 10 == 7) {
      cout << "Yes" << endl;
      return 0;
    }
    n /= 10;
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define FOR(i,a,b) for(ll i=a; i<=b; ++i)
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
using namespace std;
using ll=long long;
using pll=pair<ll,ll>;
using vl=vector<ll>;
using vp=vector<pll>;
const ll INF=1e18;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n;
    cin>>n;
    char c[n+5];
    cin>>c;
    ll l=0,r=n-1;
    ll cnt=0;
    while(1){
        while(l<r && c[l]=='R') ++l;
        while(l<r && c[r]=='W') --r;
        if(l<r){
            ++l;
            --r;
            ++cnt;
        }
        else break;
    }
    cout<<cnt;
    return 0;
}

Measured memory_bytes: 3768
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 1000

enum Type{
	Undefined,
	Jiro,
	Taro_or_Hanako,
};

int V,E;
int num_Jiro;
Type type[NUM];
vector<int> G[NUM],ANS;

//グラフを2色で塗れるか
bool recursive(int node_id){

	for(int i = 0; i < G[node_id].size(); i++){
		if(type[node_id] == Jiro){

			switch(type[G[node_id][i]]){ //隣接ノード
			case Jiro:
				return false;

			case Taro_or_Hanako:
				continue;

			case Undefined:
				type[G[node_id][i]] = Taro_or_Hanako;
				if(!recursive(G[node_id][i])){
					return false;
				}
			}

		}else{ //type[node_id] == Taro_or_Hanako

			switch(type[G[node_id][i]]){ //隣接ノード
			case Jiro:
				continue;

			case Taro_or_Hanako:
				return false;

			case Undefined:
				type[G[node_id][i]] = Jiro;
				num_Jiro++;
				if(!recursive(G[node_id][i])){
					return false;
				}
			}
		}
	}
	return true;
}

void init(){

	for(int i = 0; i < V; i++){
		type[i] = Undefined;
	}
}

void func(){

	for(int i = 0; i < V; i++)G[i].clear();
	ANS.clear();

	int from,to;

	for(int loop = 0; loop < E; loop++){
		scanf("%d %d",&from,&to);
		from--;
		to--;
		G[from].push_back(to);
		G[to].push_back(from);
	}

	//ノード0が次郎の場合
	init();
	type[0] = Jiro;
	num_Jiro = 1;
	bool FLG = false;

	if(recursive(0) == true){ //グラフを2色で塗れる場合

		FLG = true;
		if((V-num_Jiro)%2 == 0){ //Taro or Hanakoノードが偶数個ある場合
			ANS.push_back((V-num_Jiro)/2);
		}
	}

	if(FLG == true && num_Jiro%2 == 0){ //★★2色で塗れる場合→次郎ノードと、太郎or花子ノードを入れ替える★★
		ANS.push_back(num_Jiro/2);
	}

	sort(ANS.begin(),ANS.end());
	ANS.erase(unique(ANS.begin(),ANS.end()),ANS.end());

	printf("%lld\n",ANS.size());

	if(ANS.size() == 0)return;

	for(int i = 0; i < ANS.size(); i++){
		printf("%d\n",ANS[i]);
	}
}

int main(){

	while(true){
		scanf("%d %d",&V,&E);
		if(V == 0 && E == 0)break;

		func();
	}

	return 0;
}



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

int main()
{
        int x, y, z;
        cin >> x >> y >> z;

        cout << z << " " << x <<  " " << y << endl;

        return 0;
}

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

using namespace std;

const int INF = 1000000000;

int main()
{
  int h, n; cin >> h >> n;
  
  int dp[10005]; dp[0] = 0;
  for (int i = 1; i <= h; ++i) dp[i] = INF;
  
  for (int i = 0; i < n; ++i) {
    int a, b; cin >> a >> b;
    for (int j = 0; j < h; ++j) {
      int nh = min(h, j+a);
      dp[nh] = min(dp[nh], dp[j]+b);
    }
  }
  
  cout << dp[h] << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std; //or std::cin et al.

int main() {
	int n,a;
	long long minValue = 1000000;
    long long maxValue = -1000000;
	long long sum = 0;
	
	cin >> n;
	
	for ( int i = 0; i < n; i++ ) {
		cin >> a;
		sum += a;
        if (minValue > a) minValue = a;
        if (maxValue < a) maxValue = a;
 	}
	cout << minValue << " " << maxValue << " " << sum << endl;
	
	return 0;
}



Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007
typedef long long ll;

int main() {
    int n, r;
    cin >> n >> r;
    if(n >= 10){
        cout << r << endl;
    }else{
        cout << r + 100 * (10-n) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#define EPS 1e-10
using namespace std;

double add(double a,double b){
	if(abs(a + b) < EPS * (abs(a) + abs(b))) return 0;
	return a + b;
}

struct vect{
	double x,y;
	vect(){}
	vect(double x,double y) : x(x),y(y){}
	vect operator + (vect v){
		return vect(add(x,v.x),add(y,v.y));
	}
	vect operator - (vect v){
		return vect(add(x,-v.x),add(y,-v.y));
	}
	vect operator * (double d){
		return vect(x * d,y * d);
	}
	double dot(vect v){
		return add(x * v.x,y * v.y);
	}
	double det(vect v){
		return add(x * v.y,-y * v.x);
	}
};

bool comp_vect(const vect& v1,const vect& v2){
	if(v1.x != v2.x) return v1.x < v2.x;
	return v1.y < v2.y;
}

vector<vect> convex(vect* ps,int n){
	sort(ps,ps + n,comp_vect);
	int k = 0;
	vector<vect> qs(n * 2);
	for(int i = 0;i < n;i++){
		while(k > 1 && (qs[k - 1] - qs[k - 2]).det(ps[i] - qs[k - 1]) <= 0.0) k--;
		qs[k++] = ps[i];
	}
	for(int i = n - 2,t = k;i >= 0;i--){
		while(k > t && (qs[k - 1] - qs[k - 2]).det(ps[i] - qs[k - 1]) <= 0.0) k--;
		qs[k++] = ps[i];
	}
	qs.resize(k - 1);
	return qs;
}

int main(){
	int n;
	while(cin >> n,n){
		vect ps[100];
		for(int i = 0;i < n;i++){
			double x,y;
			scanf("%lf,%lf",&x,&y);
			ps[i] = vect(x,y);
		}
		vector<vect> conv = convex(ps,n);
		cout << n - conv.size() << endl;
	}
	return 0;
}

Measured memory_bytes: 3304
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N,M;
	cin >> N >> M ;
	int num[N+1];
	bool red[N+1];
	for(int i=1;i<=N;i++){
		num[i] = 1;
		red[i] = 0;
	}
	red[1] = 1;
	for(int i=0;i<M;i++){
		int x,y;
		cin >> x >> y;
		if(red[x]){
			red[y] = 1;
		}
		num[x]--;
		num[y]++;
		if(num[x]==0)red[x]=0;
	}
	int ans = 0;
	for(int i=1;i<=N;i++)if(red[i])ans++;
	cout << ans << endl;
}

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

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

int main(){
    int n, m;
    int a[110], b[110];
    while(cin >> n >> m, n+m){
        int asum=0, bsum=0;
        for(int i=0; i< n ; i++){cin >> a[i]; asum += a[i];}
        for(int i=0; i< m ; i++){cin >> b[i]; bsum += b[i];}
        pair<int, int> ans;
        int diff = 10000;
        for(int i=0; i< n; i++){
            for(int j=0; j< m; j++){
                if(asum - a[i] + b[j] == bsum - b[j] + a[i] && a[i]+b[j] < diff){
                    diff = a[i]+b[j];
                    ans.first = a[i]; ans.second = b[j];
                }
            }
        }
        if(diff == 10000) cout << -1 << endl;
        else cout << ans.first << " " << ans.second << endl;
    }
}

Measured memory_bytes: 1160
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 10


int main(){
	int a[N][N];
	f(i, N){
		f(j,N)a[i][j] = 0;
	}
	bool v = true;
	int x, y, xx, yy;
	f(i,3){
		f(j, 3){
			scanf("%d", &a[i][j]);
		}
	}
	x = a[0][1] - a[0][0];
	y = a[0][2] - a[0][0];
	xx = a[1][0] - a[0][0];
	yy = a[2][0] - a[0][0];
	f(i, 3){
		if ((a[i][1] - a[i][0]) != x)v = false;
		if ((a[i][2] - a[i][0]) != y)v = false;
		if ((a[1][i] - a[0][i]) != xx)v = false;
		if ((a[2][i] - a[0][i]) != yy)v = false;
	}


	if(v)printf("Yes\n");
	else printf("No\n");


	return 0;
}

Measured memory_bytes: 128
N = 52  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)

for i in range(2, N + 1):
    fact.append(fact[-1] * i)

def cmb(n, r):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return (fact[n] // fact[r]) // fact[n-r] 

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

cnt = [0,0]
for i in range(N):
    cnt[A[i]%2] += 1

ans = 2**(cnt[0])
mm = 0
if P==0:
    for i in range(0,cnt[1]+1,2):
        mm += cmb(cnt[1],i)
else:
    for i in range(1,cnt[1]+1,2):
        mm += cmb(cnt[1],i)

print(ans*mm)

Measured memory_bytes: 3064
using System;

using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace NotFounds
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve();
        }

        public void Solve()
        {
            var cin = new MyInputStream();
            var s = cin.Read();
            PrintYN(s == Reverse(s));
        }

        private static void PrintYN(bool b)
        {
            //WriteLine(b ? "YES" : "NO");
            WriteLine(b ? "Yes" : "No");
        }

        private static string Reverse(string s)
        {
            return string.Join("", s.Reverse());
        }
    }

    public class MyInputStream
    {
        private char separator = ' ';
        private Queue<string> inputStream;
        public MyInputStream(char separator = ' ')
        {
            this.separator = separator;
            inputStream = new Queue<string>();
        }

        public string Read()
        {
            if (inputStream.Count != 0) return inputStream.Dequeue();
            string[] tmp = Console.ReadLine().Split(separator);
            for (int i = 0; i < tmp.Length; ++i)
                inputStream.Enqueue(tmp[i]);
            return inputStream.Dequeue();
        }
        public string ReadLine() { return Console.ReadLine(); }
        public int ReadInt() { return int.Parse(Read()); }
        public long ReadLong() { return long.Parse(Read()); }
        public double ReadDouble() { return double.Parse(Read()); }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read(); return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt(); return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong(); return ret;}
    }
}                                 

Measured memory_bytes: 13396
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <cstdlib>
#include <math.h>

using namespace std;

typedef long long ll;
#define rep(i, n) for(long (i) = 0; (i) < (long) (n); (i)++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,a,b) for(long i=(a);i<(b);i++)
#define rrep1(i,a,b) for(long i=(a);i<=(b);i++)
#define rrrep(i,a,b) for(long i=(a);i>=(b);i--)
#define define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define X first
#define Y second
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int> >
#define vpl vector<pair<long, long> >
#define vppl vector<pair<long, pair<long, long> > >

const int INF = 100100100;
const long LONG_INF = 2147483647;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const ll LINF = 1e18;


int pow(int x) {
	if (x == 0) {
		return 1;
	}
	else {
		return pow(x - 1) * 2;
	}
}

int main(int argc, char const *argv[])
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int a,n;
    cin >> n;
    cin >> a;
    n--;
    while (n!=0)
    {
        n--;
        int b;
        cin >> b;
        if(a+1<=b) a=b-1;
        else if(a==b);
        else {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
using namespace std;
using P = pair<int, int>;
using ll = long long;

int main()
{
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i,n) cin >> s[i];
    int ac=0;
    int wa=0;
    int tle=0;
    int re=0;
    rep(i,n){
        if(s[i] == "AC") ac++;
        if(s[i] == "WA") wa++;
        if(s[i] == "TLE") tle++;
        if(s[i] == "RE") re++;
    }

    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
    return 0;
}

Measured memory_bytes: 6424
using System;

namespace ABC083_C_Multiple_Gift
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			string[] input = Console.ReadLine().Split(' ');
			long x = long.Parse(input[0]);
			long y = long.Parse(input[1]);

			int count = 0;
			long beforeNumber = x;
			while (beforeNumber <= y)
			{
				count++;
				beforeNumber *= 2;
			}
			
			Console.WriteLine(count);
		}
	}
}

Measured memory_bytes: 11092
#include <stdio.h>
int main()
{
    int n,a[101],i,grey=0,brown=0,green=0,aqours=0,blue=0,yellow=0,orange=0,
    red=0,colour=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
        if(a[i]<400){
            grey=1;
        }else if(a[i]<800){
            brown=1;
        }else if(a[i]<1200){
            green=1;
        }else if(a[i]<1600){
            aqours=1;
        }else if(a[i]<2000){
            blue=1;
        }else if(a[i]<2400){
            yellow=1;
        }else if(a[i]<2800){
            orange=1;
        }else if(a[i]<3200){
            red=1;
        }else{
            colour++;
        }
    }
    if(grey+brown+green+aqours+blue+yellow+orange+red==0){
        printf("1 %d",colour);
    }else{
    printf("%d %d",grey+brown+green+aqours+blue+yellow+orange+red,
    grey+brown+green+aqours+blue+yellow+orange+red+colour);}
    return 0;
}


Measured memory_bytes: 128
<?php
fscanf(STDIN,"%d",$n);
$a=explode(" ", rtrim(fgets(STDIN)));
$nums=array_count_values($a);
$result=0;
foreach ($nums as $k => $v)
{
	if($v<$k)
		$result+=$v;
	elseif($v>$k)
		$result+=$v-$k;
}
echo($result);

Measured memory_bytes: 19188
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
using namespace std;
signed main(){
    string a;
    cin >> a;
    (a[0] == a[2])? cout << "Yes" : cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int o=0;
	int n;
	string s;
	int i;
	cin>>n>>i;
	if(n<=i){
		cout<<0<<endl;
	}
	else cout<<n-i<<endl;
}
//伊勢田=sanadayukimura"73"
//伊勢田=48
//73=48
//両方から23を引いて
//50=25
//2=1


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

int main() {
    int a, b;
    char op;

    cin >> a >> op >> b;
    if (op == '+')
        cout << a + b << endl;
    else if (op == '-')
        cout << a - b << endl;

}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <list>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    string s;
    cin >> s;
    string t = "hi";
    string k;
    rep(i,5){
        k += t;
        if(s == k){
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
}


Measured memory_bytes: 256
/*
    Author: Alam Khan
    AUST CSE 40th Batch

*/

#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;

typedef long long ll;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
#define pb     push_back
#define inf     1e18
#define low     -2e18
#define PI        acos(-1.0)
#define endl  "\n"
#define FAST  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr freopen("input.txt","r",stdin)
#define fw freopen("output.txt","w",stdout)
const int sz = 1e5+9;
ll n;

int main()
{
    ll i,t,k,j,x=0,y=0,m;
    cin>>n;
    if(n%2==0)
    {
        cout<<-1<<endl;
        return 0;
    }
    ll mod = 0;
    while(1)
    {
        mod  = mod*10+7;
        x++;
        if(x>1e7)
            break;
        if(mod%n==0)
            break;
        mod = mod%n;
    }

    if(x<=1e7)
        cout<<x<<endl;
    else cout<<-1<<endl;
    return 0;
}



Measured memory_bytes: 3592
#include <bits/stdc++.h>
#include <iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vi vector <ll> 
#define qu queue <ll>
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;

/*
Decimal Places: cout << fixed << setprecision(n) << ans << endl;
*/

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}


void solve()
{
    int n; cin >> n;
    set <string> s; string temp;
    for (int i = 0; i < n; i++)
    {
        cin >> temp; s.insert(temp);
    }
    nout(s.size());
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 19136
import java.io.*;
import java.util.*;
/**
 * @author Rick
 *
 */
public class Main{

	public static void main(String[] args) throws Exception {
		//System.setIn(new FileInputStream("T03LightCandles.txt"));
		java.io.BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int N=Integer.parseInt(st.nextToken().trim());
		int K=Integer.parseInt(st.nextToken().trim());
		int[] Candles=new int[N];
		int NegativeCount=0, ZeroCount=0;
		int MinStep=999999999;
		
	    st = new StringTokenizer(br.readLine());
		for(int i=0;i<N;i++)
		{
			int candle=Integer.parseInt(st.nextToken().trim());
			Candles[i]=candle;
			if(candle==0)
			{
				ZeroCount=1;
			}
			else if(candle<0)
			{
				NegativeCount++;
			}
		}
		
		int i=0,Endi=0;
		if(NegativeCount+ZeroCount>=K)
			i=NegativeCount+ZeroCount-K;
		else
			i=0;
		if(NegativeCount+ZeroCount==0)
			Endi=1;
		else
			Endi=N-K+1;

		for(;i<Endi;i++)
		{
			int Step=CaclStep(Candles[i],Candles[i+K-1]);
			if(MinStep>Step)
				MinStep=Step;				
		}
	     System.out.println(MinStep);
	}
	
	private static int CaclStep( int i, int j)
	{
		if(i<0 && j>0)
		{
			if(i*-1 >= j)
				return i*-1 + j*2;
			else
				return i*-2 +j;
		}
		else if(i<0 && j<=0)
		{
			return i*-1;
		}
		else if (i>=0 && j>0)
		{ 
			return j;
		}
		else
		{ 
			return j;
		}
	}
}

Measured memory_bytes: 35796
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  int n, t, a;
  cin >> n >> t >> a;
  vector<int> h(n);
  for (int i = 0; i < n; ++i) {
    cin >> h[i];
  }
 
  vector<double> ave(n);
  for (int i = 0; i < n; ++i) {
    ave[i] = abs((t - h[i] * 0.006) - a);
  }
  int ans = 0;
  for (int i = 1; i < n; ++i) {
    if (ave[i] < ave[ans]) ans = i;
  }
  cout << ans + 1 << "\n";
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define re register
#define inc(i,j,k) for(re int i=j;i<=k;i++)
#define ll long long
using namespace std;
const int mod=1e9+7;
const int N=2e3+5;
int n,k;
ll fac[N*N],inv[N*N],dp[N][N];
ll c(int n,int m){return fac[n]*inv[m]%mod*inv[n-m]%mod;}
int main(){
	scanf("%d%d",&n,&k);
	if(k==1) return puts("1"),0;
	fac[0]=1;
	inc(i,1,n*k) fac[i]=fac[i-1]*i%mod;
	inv[0]=inv[1]=1;
	inc(i,2,n*k) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
	inc(i,2,n*k) inv[i]=inv[i]*inv[i-1]%mod;
	inc(i,0,n) dp[0][i]=1;
	inc(i,1,n){
		inc(j,i,n){
			dp[i][j]=(dp[i][j-1]+dp[i-1][j]*(n-i+1)%mod*c(n*k-(k-1)*(i-1)-j-1,k-2))%mod;
		} 
	}
	printf("%lld",dp[n][n]);
}

Measured memory_bytes: 94464
#include<bits/stdc++.h>
#define MN 18
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*f;
}
int n,f[MN+5][MN+5];long long ans;
char q[MN+5],s[MN*2+5];
int main()
{   
    n=read();scanf("%s",s+1);
    for(int j=0;j<1<<n;++j)
    {
        int l=1,r=n;
        for(int k=0;k<n;++k) if(j&(1<<k)) q[l++]=s[k+1]; else q[r--]=s[k+1];
        memset(f,0,sizeof(f));f[0][0]=1;--l;r=n-l;
        for(int i=1;i<=n;++i) for(int j=0;j<=r;++j) if(f[i-1][j])
        {
            if(l+j+1<=n&&s[i+n]==q[l+j+1]) f[i][j+1]+=f[i-1][j];
            if(l-(i-1-j)>0&&s[i+n]==q[l-(i-1-j)]) f[i][j]+=f[i-1][j];
        }
        ans+=f[n][r];
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define ENDL '\n'
#define sz(a) (int)(a.size())
#define all(a) begin(a), end(a)
#define deb(a) cout << #a << ": " << a << ENDL
#define fore(i, a, b) for(int i(a), ThkMk(b); i < ThkMk; ++i)
#define _ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli> ii;
typedef vector<lli> vi;

int main()
{   _
    lli a, b, c, d; cin >> a >> b >> c >> d;
    cout << max({a * c, b * c, a * d, b * d}) << ENDL;;
    return 0;
}


Measured memory_bytes: 3648
#include<iostream>
using namespace std;
//Minimum Cost Flow O(FE log V)
#include<algorithm>
#include<utility>
#include<vector>
#include<queue>
#include<limits>
template<typename T>
struct MCF{
	struct edge{
		int to,rev,cap;
		T cost;
	};
	vector<vector<edge> >G;
	vector<T>h,d;
	vector<int>pv,pe;
	MCF(int n_=0):G(n_),h(n_,0),d(n_),pv(n_),pe(n_){}
	void add_edge(int from,int to,int cap,T cost)
	{
		G[from].push_back({
			to,(int)G[to].size(),cap,cost
		});
		G[to].push_back({
			from,(int)G[from].size()-1,0,-cost
		});
	}
	T min_cost_flow(int s,int t,int f)//ans or -1
	{
		T ret=0;
		while(f>0)
		{
			priority_queue<pair<T,int>,vector<pair<T,int> >,greater<pair<T,int> > >P;
			fill(d.begin(),d.end(),numeric_limits<T>::max());
			d[s]=0;
			P.push(make_pair(0,s));
			while(!P.empty())
			{
				pair<T,int>p=P.top();P.pop();
				if(d[p.second]<p.first)continue;
				for(int i=0;i<G[p.second].size();i++)
				{
					edge&e=G[p.second][i];
					if(e.cap>0&&d[e.to]>d[p.second]+e.cost+h[p.second]-h[e.to])
					{
						d[e.to]=d[p.second]+e.cost+h[p.second]-h[e.to];
						pv[e.to]=p.second;
						pe[e.to]=i;
						P.push(make_pair(d[e.to],e.to));
					}
				}
			}
			if(d[t]==numeric_limits<T>::max())return -1;
			for(int u=0;u<G.size();u++)h[u]+=d[u];
			int d=f;
			for(int u=t;u!=s;u=pv[u])d=min(d,G[pv[u]][pe[u]].cap);
			f-=d;
			ret+=d*h[t];
			for(int u=t;u!=s;u=pv[u])
			{
				G[pv[u]][pe[u]].cap-=d;
				G[u][G[pv[u]][pe[u]].rev].cap+=d;
			}
		}
		return ret;
	}
};
main()
{
	int N,E,F;
	cin>>N>>E>>F;
	MCF<int>mf(N);
	for(int i=0;i<E;i++)
	{
		int u,v,c,d;cin>>u>>v>>c>>d;
		mf.add_edge(u,v,c,d);
	}
	cout<<mf.min_cost_flow(0,N-1,F)<<endl;
}


Measured memory_bytes: 3228
#include<iostream>
#define ll long long
#define inf 1e9 + 1

using namespace std;


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

  ll weight[N+1];
  int value[N+1];

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

  ll max_val = N*1000;

  ll dp[N+1][max_val+1];

  for(int i = 0 ; i<=max_val ; i++)
    dp[1][i] = inf;

  dp[1][0] = 0;
  dp[1][value[1]] = weight[1];

  for(int i = 2 ; i<=N ; i++)
  {
    for(int v = 0 ; v<=max_val ; v++)
    {
      dp[i][v]= dp[i-1][v];
      if(value[i] <= v)
        dp[i][v] = min(dp[i][v],weight[i] + dp[i-1][v - value[i]]);
    }
  }

  ll ans = 0;

  for(ll v = 0 ; v<=max_val ; v++)
  {
    if(dp[N][v] <= W)
      ans = max(ans,v);
  }

  cout<<ans;
  
  /*for(int i = 0 ; i<=N ; i++)
  {
    for(int j = 0 ; j<=W; j++)
    {
      cout<<dp[i][j]<<" ";
    }

    cout<<endl;
  }*/


  //cout<<endl;
  
  return 0;
}

Measured memory_bytes: 78336
#include <stdio.h>

/* ÏXsÂ */
#define N_MAX 10
#define S_MAX 330

int num[10]={1,2,3,4,5,6,7,8,9,0}, dp[N_MAX+1][S_MAX+1];
#define exch(A,B) {int t; t=A, A=B, B=t;}

/* k¶Úðßé, sÉÍ»Ì_ÅÌað */
void solve(int k, int s){
     int i, j, ts;

     for(i=k; i<10; i++){
	  exch(num[i],num[k]);

	  /* n=kÅÌsðL^ */
	  ts=s;
	  ts+=num[k]*(k+1);
	  dp[k+1][ts]++;

	  if(k<9) solve(k+1,ts);

	  exch(num[i],num[k]);
     }
}

int main(int argc, char *argv[]){
     int n, s;

     solve(0,0);
     
     while(~scanf("%d %d",&n,&s))
	  printf("%d\n",(n>N_MAX||s>S_MAX)?0:dp[n][s]);

     return 0;
}

Measured memory_bytes: 296
#include<iostream>
#include<vector>
#include<cstring>
#include<queue>
#include<algorithm>
#include<cassert>
#include<tuple>
#include<unordered_map>

using namespace std;
#define int ll

#define REP(i, n) for(int i=0;i<(int)n;i++)
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define reep(i, s, t) for(int i=s;i<(int)t;i++)
#define irep(i, n) for(int i=(int)n-1;i>=0;i--)
#define ireep(i, n, s) for(int i=(int)n-1;i>=s;i--)
#define all(v) v.begin(), v.end()
#define vc vector
#define eb emplace_back
#define pb push_back

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<ll, ll> pil;
typedef vector<ll> vi;
const ll INF = (1ll<<60) + 10;

struct BIT{
	int n;
	vi vs;
	
	BIT(int size=0):n(size), vs(n){}
	void add(int k, int a){
		for(int i=k;i<n;i |= i+1) vs[i] += a;
	}
	int sum(int s, int t){
		if(s > 0) return sum(0, t) - sum(0, s);
		int res = 0;
		for(int i=t-1;i>=0;i=(i&(i+1))-1) res += vs[i];
		return res;
	}
};

template<typename T=int>
struct Zipper{
	vector<T> dec;
	unordered_map<T, int> enc;
	Zipper(){}
	void add(T t){dec.pb(t);}
	size_t size(){return dec.size();}
	void compile(){
		sort(all(dec)); dec.erase(unique(all(dec)), dec.end());
		REP(i, dec.size()) enc[dec[i]] = i;
	}
	T operator[](int i){return dec[i];}
	T operator()(T i){
		assert(enc.find(i) != enc.end());
		return enc[i];
	}
	int lb(T t){return lower_bound(all(dec), t) - dec.begin();}
};


int n, m;

vector<ll> ijk(const vector<vector<pil>> &g, int s){
	vector<ll> d(g.size(), INF);
	d[s] = 0;
	priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
	pq.emplace(0, s);
	while(!pq.empty()){
		int u; ll c; tie(c, u) = pq.top(); pq.pop();
		if(d[u] < c) continue;
		for(auto &e : g[u]){
			if(d[e.first] > c + e.second){
				d[e.first] = c + e.second;
				pq.emplace(c + e.second, e.first);
			}
		}
	}
	
	return d;
}

signed main(){
	scanf("%lld%lld", &n, &m);
	vector<vector<pil>> g(n);
	REP(i, m){
		int u, v, w;
		scanf("%lld%lld%lld", &u, &v, &w);
		g[u].eb(v, (ll)w);
		g[v].eb(u, (ll)w);
	}
	auto d1 = ijk(g, 0);
	auto d2 = ijk(g, n-1);
	vector<pll> vs;
	Zipper<ll> zip;
	zip.add(0);
	zip.add(INF);
	REP(i, n){
		assert(d1[i] < INF && d2[i] < INF);
		vs.eb(d1[i], d2[i]);
		zip.add(d2[i]);
	}
	vector<tuple<ll, ll, int>> query;
	scanf("%lld", &m);
	REP(i, m){
		ll a, b;
		scanf("%lld%lld", &a, &b);
		query.eb(a, b, i);
		zip.add(b);
	}
	zip.compile();
	vs.eb(INF, 0);
	sort(all(vs));
	sort(all(query));
//	rep(i, vs.size()) cout << vs[i].first << " " << vs[i].second << endl;cout << endl;
	int j=0;
	vi ans(m);
	BIT bit(zip.size());
	REP(i, vs.size()){
		while(j < m && get<0>(query[j]) < vs[i].first){
//			cout << a << ", " << b << ", " << qi << endl;
			ans[get<2>(query[j])] = bit.sum(zip(get<1>(query[j])), zip.size());
//			cout << "ans[" << get<2>(query[j]) << " = " << bit.sum(zip.lb(get<1>(query[j])), zip.size()) << endl;
			j ++;
		}
		bit.add(zip(vs[i].second), 1);
//		cout << "add " << vs[i].second << ", " << zip(vs[i].second) << endl;
		// add vs[i].second
	}
	assert(j >= m);
	for(int v : ans) printf("%lld\n", v);
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> button(n);
  for (int i = 0; i < n; i++)
    cin >> button.at(i);
  
  int i;
  bool meetTwo = false;
  int num = button.at(0);
  for (i = 0; i < n; i++){
    if (num == 2){
      meetTwo = true;
      break;
    }
  	num = button.at(num - 1);
  }
  if (meetTwo == true)
    cout << i + 1 << endl;
  else
    cout << -1 << endl;
}

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

#define mod 1000000007LL

ll mod_pow(ll a,ll n){
  ll res=1;
  while(n>0){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll n;
string s;
ll dp[5005][5005];

int main(){
  cin>>n>>s;
  ll l=s.size();
  dp[0][0]=1;
  rep(i,n)rep(j,n+1){
    if(j>0){
      (dp[i+1][j-1]+=dp[i][j])%=mod;
    }else{
      (dp[i+1][j]+=dp[i][j])%=mod;
    }
    (dp[i+1][j+1]+=dp[i][j]*2)%=mod;
  }
  cout<<dp[n][l]*mod_pow(mod_pow(2LL,l),mod-2)%mod<<endl;
	return 0;
}


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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 1e5 + 5;

int v[MAXN];
vi to[MAXN];
vi from[MAXN];

ll get_dis(int m, int from, int to) {
	if (from < to) {
		return to - from;
	} else {
		return 1 + (m - from) + (to - 1);
	}
}

void solve(){
	int n, m;
	scanf("%d%d", &n, &m);
	ll sum = 0ll;
	ll cur = 0ll;
	ll cnt = 0ll;
	REP(i, 0, n) {
		scanf("%d", &v[i]);
		if (i) {
			from[v[i]].pb(v[i - 1]);
			to[v[i - 1]].pb(v[i]);
			sum += get_dis(m, v[i - 1], v[i]);
			if (v[i - 1] > v[i]) {
				cur += 1 + (m - v[i - 1]);
				cnt++;
			}
		}
	}
	ll mn = sum - cur + cnt;
	int mini = 0;
	
	//printf("%d %lld %lld %lld\n", 0, cur, cnt, sum - cur + cnt);
	
	REP(i, 1, m) {
		REP(j, 0, SZ(from[i])) {
			cnt--;
			cur -= get_dis(m, from[i][j], i);
		}
		cur += cnt;
		REP(j, 0, SZ(to[i])) {
			cnt++;
			cur++;
		}
		if (sum - cur + cnt < mn) {
			mn = sum - cur + cnt;
			mini = i;
		}
		
		//printf("%d %lld %lld %lld\n", i, cur, cnt, sum - cur + cnt);
	}
	printf("%lld\n", mn);
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 9984
#include<stdio.h>

int main(void){
	int n;
	scanf("%d",&n);
	int fib[45];
	int i;
	fib[0]=1;
	fib[1]=1;
	for(i=2;i<=n;i++){
		fib[i]=fib[i-1]+fib[i-2];
	}
	printf("%d\n",fib[n]);
	return 0;
}

Measured memory_bytes: 596
#include <stdio.h>

int main(void){

	int n;
	int h[101];
	int m[101] = {};
	int c[101] = {};
	int check;
	int i;
	int cnt = 0;

	scanf("%d", &n);

	for(i = 1; i <= n; i++){
		scanf("%d", &h[i]);
	}

	while(1){
		check = 0;
		for(i = 1; i <= n; i++){
			if(h[i] == m[i]){
				c[i] = 0;
			}else{
				c[i] = 1;
			}
		}
		for(i = 1; i <= n; i++){
			if(c[i] == 1){
				m[i]++;
				check = 1;
			}
			if(c[i-1] == 0 && c[i] == 1){
				cnt++;
			}
		}
		if(check == 0) break;
	}

	printf("%d", cnt);

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <deque>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <iomanip>
#include <map>
#include <stack>
#include <queue>
#include <functional>
#include <climits>
#include <numeric>
#include <bitset>
#include <random>
#include <tuple>
#include <initializer_list>
#include <fstream>
#include <cctype>
#include <string>

struct Restaurant {
	int id, score;
};
int main() {
	int n; std::cin >> n;
	std::unordered_map<std::string, std::vector<Restaurant>> map;
	for (auto i = 0; i < n; ++i) {
		std::string s; int p; std::cin >> s >> p;
		map[s].push_back(Restaurant{ i + 1, p });
	}
	std::vector<std::pair<std::string, std::vector<Restaurant>>> restaurants;
	for (auto p : map) {
		std::sort(p.second.begin(), p.second.end(), [](const Restaurant a, const Restaurant b) {return a.score > b.score; });
		restaurants.push_back(std::move(p));
	}
	std::sort(restaurants.begin(), restaurants.end(), [](const std::pair<std::string, std::vector<Restaurant>>& a, const std::pair<std::string, std::vector<Restaurant>>& b) {return a.first < b.first; });
	for (const auto& pair : restaurants) {
		for (const auto& r : pair.second) {
			std::cout << r.id << '\n';
		}
	}
}


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

using namespace std;

int main(void)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n;
	cin >> n;
	map<int, int> a;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		a[x]++;
	}
	int res = n;
	for (auto &p : a) {
		res -= p.second - 1;
	}
	res -= 1 - res % 2;
	cout << res << '\n';

	return 0;
}



Measured memory_bytes: 4992
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	@SuppressWarnings("unused")
	public static void main(String[] args) throws IOException {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(); // 県の個数
		int m = in.nextInt(); // 市の個数

		int city[][] = new int[m + 1][4]; // id, pref, year, number in pref

		// 県、年でソート
		for ( int id = 1; id <= m; id++ ) {
			city[id][0] = id;
			city[id][1] = in.nextInt();
			city[id][2] = in.nextInt();
		}
		Arrays.sort(city, new Comparator<int[]>() {

			@Override
			public int compare(int[] o1, int[] o2) {
				if ( o1[1] != o2[1] ) {
					return o1[1] - o2[1];	// １．prefでソート
				} else {
					return o1[2] - o2[2];	// ２．yearでソート
				}
			}
		});

		// 年を見てナンバリング
		DecimalFormat df = new DecimalFormat("000000");
		String result[] = new String[m];
		int pref = 0;
		int num = 0;
		for ( int i = 1; i <= m; i++ ) {
			int p = city[i][1];
			if ( pref != p ) {
				pref = p;
				num = 1;
			} else {
				num++;
			}
			result[city[i][0] - 1] = padding(pref) + padding(num); // df.format(pref) + df.format(num);
		}

		StringBuilder sb = new StringBuilder(100000 * 13);
		for ( String s : result ) {
			sb.append(s).append("\n");
		}
		System.out.println(sb);
		in.close();
	}

	private static String padding(int n) {
		String padded = "";
		if ( n < 10 ) {
			padded = "00000" + n;
		} else if ( n < 100 ) {
			padded = "0000" + n;

		} else if ( n < 1000 ) {
			padded = "000" + n;

		} else if ( n < 10000 ) {
			padded = "00" + n;

		} else if ( n < 100000 ) {
			padded = "0" + n;

		} else {
			padded = String.valueOf(n);
		}
		return padded;
	}
}


Measured memory_bytes: 96912
#include <bits/stdc++.h>
using namespace std;
int main()
{

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output14.txt", "w", stdout);
#endif
	//ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, W;
	cin >> n >> W;
	long long w[n], p[n];
	for (int i = 0; i < n; i++)
		cin >> w[i] >> p[i];
	vector<vector<long long>> dp(n + 1, vector<long long> (W + 1, 0));
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= W; j++)
		{
			if (w[i - 1] <= j)
			{
				//cout << dp[i - 1][j - w[i - 1]] << "\n";
				dp[i][j] = max(dp[i - 1][j], p[i - 1] + dp[i - 1][j - w[i - 1]]);
			}
			else
				dp[i][j] = dp[i - 1][j];
			///cout << dp[i][j] << "\n";
		}

	}
	cout << dp[n][W] << "\n";
//cout << "\n";
}

Measured memory_bytes: 83076
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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;
} 

template <class T>
class SegTree {
    int n;// 葉の数
    vector<T> data;// データを格納するvector
    T def; // 初期値かつ単位元
    function<T(T, T)> operation; // 区間クエリで使う処理
    function<T(T, T)> update;// 点更新で使う処理

    // 区間[a,b)の総和。ノードk=[l,r)に着目している。
    T _query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) return def; // 交差しない
        if (a <= l && r <= b)
            return data[k]; // a,l,r,bの順で完全に含まれる
        else {
            T c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子
            T c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子
            return operation(c1, c2);
        }
    }

    public:
    // _n:必要サイズ, _def:初期値かつ単位元, _operation:クエリ関数,
    // _update:更新関数
    SegTree(size_t _n, T _def, function<T(T, T)> _operation,
        function<T(T, T)> _update)
        : def(_def), operation(_operation), update(_update) {
        n = 1;
        while (n < _n) {
            n *= 2;
        }
        data = vector<T>(2 * n - 1, def);
    }

    // 場所i(0-indexed)の値をxで更新
    void change(int i, T x) {
        i += n - 1;
        data[i] = update(data[i], x);
        while (i > 0) {
            i = (i - 1) / 2;
            data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]);
        }
    }

    // [a, b)の区間クエリを実行
    T query(int a, int b) {
        return _query(a, b, 0, 0, n);
    }

    // 添字でアクセス
    T operator[](int i) {
        return data[i + n - 1];
    }
};

int main(){
    ll n,q;cin >> n >> q;
    SegTree<ll> st(
        n+1,0,[](ll a,ll b){return a+b;},[](ll a,ll b){return a+b;}
    );
    while(q--){
        ll t;cin >> t;
        if(t){
            ll a;cin >> a;
            cout << st.query(0,a) <<endl;
        }
        else{
            ll a,b,c;cin >> a >> b>>c;a--;
            st.change(a,c);
            st.change(b,-c);
        }
    }
}


Measured memory_bytes: 4964