akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
    string s , t ;
    cin >> s  ;
    cin >> t ;
    size_t n = s.length() ;
    bool flag = false ;
    int count = 0;
    char a ,b ;
    for(int i = 0 ; i < n ; i++){
         for(int j = 0 ; j < n ; j++){
           if(j + i < n ){
               a = s[j] ;
               b = t[j+i] ;
             if(a ==b){
                 count++ ;
                 
             }
           }else{
               a = s[j] ;
               b = t[j+i -n] ;
             if(a==b){
                 count++ ;
                
             }
           }
         }
         if(count == n){
             flag = true ;

         }
         count = 0 ;
         

    }

    if(flag == true){
        cout <<"Yes" << endl;

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int const nax = 1e4;
constexpr int mod = 1e9 + 7;
int n, a[nax];
void plusle(int &a, int b){
    if((a += b) >= mod) a -= mod;
}
int mul(int a, int b){
    return 1LL * a * b % mod;
}
int power(int a, int b){
    int res = 1;
    for(; b > 0 ; b >>= 1, a = mul(a, a))
        if(b & 1) res = mul(res, a);
    return res;
}
int const bs = 1e6 + 10;

int id[bs];
int pr[bs];
bool vis[bs];
int st[bs];

int main(){
    int tomul = 0;
    int now = 0;
    for(int i = 2 ;i < bs; i ++ ){
        if(!vis[i]){
            id[i] = ++ now;
            pr[now] = i;
        }
        for(int j = i ;j < bs ; j += i){
            vis[i] = true;
        }
    }
    scanf("%d", &n);
    for(int i = 1 ;i <= n ; i ++){
        int x;
        scanf("%d", &x);
        plusle(tomul , power(x , mod - 2));
        int g = sqrt(x);
        for(int j = 2 ; j <= g ;j ++){
            if(x % j == 0){
                int f = 0;
                while(x % j == 0){
                    x /= j;
                    f ++;
                }
                st[id[j]] = max(st[id[j]], f);
            }
        }
        if(x > 0) st[id[x]] = max(st[id[x]], 1);
    }
    int ans = 1;
    for(int i = 1 ; i < bs ; i ++){
        ans = mul(ans, power(pr[i], st[i]));
    }
    printf("%d\n", mul(ans, tomul));
}
/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 12672
local n,x,y=io.read("n","n","n")

local ma=math.abs
local t={}
for i=1,n do
    for j=i+1,n do
        local mindist=math.min(ma(j-i),ma(x-i)+1+ma(j-y),ma(y-i)+1+ma(j-x))
        t[mindist]=(t[mindist] or 0)+1
    end
end

for i=1,n-1 do
    print(t[i] or 0)
end

Measured memory_bytes: 760
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
int n, ans;
vector<int> to[maxn];
bool inlink[maxn];
int son[maxn];
vector<int> link;
void build_link () {
    int d[maxn];
    queue<int> q;
    memset (d, -1, sizeof (d));
    d[n] = 0;
    q.push (n);
    while (!q.empty()) {
        int u = q.front(); q.pop();
        for (int i = 0; i < to[u].size(); i++) {
            int v = to[u][i];
            if (d[v] != -1) continue;
            d[v] = d[u]+1;
            q.push (v);
        }
    }
    int p = 1;
    while (1) {
        link.push_back (p);
        inlink[p] = true;
        if (p != n) {
            for (int i = 0; i < to[p].size(); i++) {
                int v = to[p][i];
                if (d[v] != d[p]-1) continue;
                p = v;
                break;
            }
        }
        else break;
    }
}
int get_son (int u, int fa) {
    for (int i = 0; i < to[u].size(); i++) if (to[u][i] != fa) {
        son[u] += get_son (to[u][i],u)+1;
    }
    //printf ("son%d: %d\n", u, son[u]);
    return son[u];
}
void gen_son () {
    for (int i = 0; i < link.size(); i++) {
        int u = link[i];
        for (int j = 0; j < to[u].size(); j++) if (!inlink[to[u][j]]) {
            son[u] += get_son (to[u][j], u)+1;
        }
    }
}
int main () {
    scanf ("%d", &n);
    for (int i = 0; i < n-1; i++) {
        int a, b;
        scanf ("%d%d", &a, &b);
        to[a].push_back (b);
        to[b].push_back (a);
    }
    build_link();
    gen_son();

    int sz = link.size();
    //for (int i = 0; i < sz; i++) printf ("%d %d\n", link[i], son[link[i]]);
    int a = 0, b = 0;
    for (int i = 0; i <= (sz-1)/2; i++) {
        a += son[link[i]];
    }
    for (int i = sz-1; i > (sz-1)/2; i--) {
        b += son[link[i]];
    }
    if (sz % 2 == 1) {
        if (a >= b) ans = 1;
        else ans = 2;
    }
    else {
        if (b >= a) ans = 2;
        else ans = 1;
    }
    if (ans == 1) printf ("Fennec\n");
    else printf ("Snuke\n");
}


Measured memory_bytes: 6908
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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 DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

ll n, w;
vll vs, wws;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> w;
    vs.resize(n), wws.resize(n);
    for (ll i = 0; i < n; i++) cin >> vs[i] >> wws[i];
    vvll dp(n + 1, vll(w + 1, 0));

    for (ll i = 0; i < n; i++) {
        for (ll j = 1; j <= w; j++) {
            dp[i + 1][j] = dp[i][j];
            if (j - wws[i] >= 0) chmax(dp[i + 1][j], dp[i + 1][j - wws[i]] + vs[i]);
        }
    }
    cout << dp[n][w] << '\n';
    return 0;
}



Measured memory_bytes: 10804
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <iterator>
#include <algorithm>

typedef long long lint;

using namespace std;

void showIntArray(lint a[], lint n);

int main() {
  int N;
  cin >> N;
  cout << (N - 2) * 180 << endl;
  return 0;
}

void showIntArray(lint a[], lint n) {
  for (int i=0; i<n; i++) {
    cout << a[i] << ' ';
  } cout << endl;
}


Measured memory_bytes: 256
s = input()

dp = [[0 for i in range(13)] for j in range(len(s))]
mod = 10 ** 9 + 7

for i, s_i in enumerate(s):
    if i == 0:
        if s_i == "?":
            for k in range(10):
                dp[0][k] = 1
        else:
            dp[0][int(s_i)] = 1

    else:
        if s_i == "?":
            for k1 in range(10):
                for k2 in range(13):
                    dp[i][(k2 * 10 + k1) % 13] += dp[i-1][k2] % mod

        else:
            for k in range(13):
                dp[i][(k*10+int(s_i))%13] += dp[i-1][k] % mod


print(dp[-1][5] % mod)

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

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pf printf
#define sc scanf
#define sf(n) scanf("%d",&n)
#define sff(n1,n2) scanf("%d %d",&n1,&n2)
#define sfff(n1,n2,n3) scanf("%d %d %d",&n1,&n2,&n3)
#define sl(n) scanf("%lld",&n)
#define sll(n1,n2) scanf("%lld %lld",&n1,&n2)
#define slll(n1,n2,n3) scanf("%lld %lld %lld",&n1,&n2,&n3)
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,n) for(i=1;i<=n;i++)
#define reps(i,a,n) for(i=a;i<=n;i++)
#define nl puts("");
#define pb push_back
#define MOD 1000000007
#define fi first
#define se second
#define N 100005
#define mem(ara,n) memset(ara,n,sizeof(ara))
#define memb(ara) memset(ara,false,sizeof(ara))
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define sz(x) x.size()
#define pi pair<int,int>
#define pii pair<pair<int,int>,pair<int,int> >
#define line puts("-------");
#define db(x) cout<<#x<<" :: "<<x<<"\n";
#define dbb(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define fr freopen("input.txt","r",stdin);
#define fw freopen("output.txt","w",stdout);
typedef long long int ll;
using namespace std;
int main()
{
    int i,n,k;
    deque<int>dq;
    sf(n);
    rep0(i,n)
    {
        sf(k);
        if(i&1)
            dq.push_front(k);
        else
            dq.pb(k);
    }
    if(n&1)
    {
        while(!dq.empty())
        {
            cout<<dq.back()<<" ";
            dq.pop_back();
        }
    }
    else
    {
        while(!dq.empty())
        {
            cout<<dq.front()<<" ";
            dq.pop_front();
        }
    }
}


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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var << endl;
#else
#define debug(var)
#endif

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

const int N = 1e5+23;

map<int, int> h;

void solve() {
	int n; scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		int a; scanf("%d", &a);
		++h[a];
	}
	priority_queue<int> q;
	long long ans = 0;
	for (const auto &e: h) {
		if (e.second < 2) continue;
		if (e.second > 3) ans = max(ans, (long long)e.first*e.first);
		q.push(e.first);
	}
	if (q.size() < 2) printf("%lld", ans);
	else {
		long long tmp = q.top(); q.pop();
		printf("%lld", max(ans, tmp*q.top()));
	}
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 4992
import java.util.Scanner;

public class Main {

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

	public void execute() {
		Scanner sc = new Scanner(System.in);
		final int N = sc.nextInt();
		long[] T = new long[N];
		T[0] = sc.nextLong();
		long lcm = T[0];
		for (int i = 1; i < N; i++) {
			T[i] = sc.nextLong();
			lcm = lcm(lcm, T[i]);
		}
		System.out.println(lcm);
		sc.close();
	}

	private long lcm(long l1, long l2) {
		if (l1 < l2) {
			return lcm(l2, l1);
		}
		long gcd = gcd(l1, l2);
		return (l1 / gcd) * (l2 / gcd) * gcd;

	}

	private long gcd(long l1, long l2) {
		if (l1 < l2) {
			return gcd(l2, l1);
		} else if (l2 == 0) {
			return l1;
		} else {
			long r = l1 % l2;
			return gcd(l2, r);
		}

	}
}


Measured memory_bytes: 21844
from collections import deque

N, K = map(int, input().split())
T = [[] for i in range(N)]
E = []
for i in range(N-1):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    T[a].append(b)
    T[b].append(a)
    E.append([a, b])


def bfs(n):
    visited = [False] * N
    dist = [0] * N
    queue = deque([n])
    while queue:
        node = queue.pop()
        if visited[node]:
            continue
        visited[node] = True
        for n in T[node]:
            if not visited[n]:
                dist[n] = dist[node] + 1
                queue.appendleft(n)
    return dist


dist = []
for i in range(N):
    dist.append(bfs(i))

ans = float('inf')
if K % 2 == 0:
    for i in range(N):
        ans = min(ans, len([d for d in dist[i] if d > K / 2]))

else:
    for a, b in E:
        ans = min(ans, len([d for d in [min(d1, d2) for d1, d2 in zip(dist[a], dist[b])] if d> (K-1) / 2]))

print(ans)


Measured memory_bytes: 85208
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<numeric>

using namespace std;

int main(){ 
    int n, m;
    vector<int> vec;

    cin >> n >> m;
    for(int i = 0; i < n; i++){
        int v;
        cin >> v;
        vec.push_back(v);
    }    

    int ct = 0;

    int sum = accumulate(vec.begin(),vec.end(),0);

    for(int i = 0; i < n; i++){
        if(vec[i] * 4 * m >= sum ) ct++;
    }

    if(ct >= m) cout << "Yes" << endl;
    else cout << "No" << endl;

}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define ll long long int
#define N 105
using namespace std;
ll k[N];
ll gcd(ll a,ll b){
    return b?gcd(b,a%b):a;
}
int main(){
    int n;
    scanf("%d", &n);
    for(int i=1;i<=n;i++){
      scanf("%lld",&k[i]);
    }
    ll ans=k[1];
    for(int i=2;i<=n;i++){
      ans=ans/gcd(ans,k[i])*k[i];
    }
    printf("%lld\n",ans);
    return 0;
}


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

using namespace std;

int lower_bound(vector<int>& v, int istart, int iend, int value) {
  int n = v.size();
  int ng = -1;
  int ok = v.size();

  while (abs(ok - ng) > 1) {
    int mid = (ok + ng) / 2;

    if (v[mid] >= value) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  return ok;
}

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

  int n;
  cin >> n;

  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }

  int num_query;
  cin >> num_query;

  int query;
  for (int i = 0; i < num_query; i++) {
    cin >> query;
    cout << lower_bound(v, 0, v.size(), query) << endl;
  }
}




Measured memory_bytes: 3340
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>

using namespace std;

//愚直以外の解放気になる

int main(){
    int n;
    scanf("%d", &n);
    int array[101];
    for(int i=0;i<101;i++){
        array[i]=0;
    }
    for(int l=0;l<26;l++){
        for(int m=14;m>=0;m--){
            if(l*4+m*7 <= 100){
                array[l*4+m*7]=1;
            }
        }
    }
    if(array[n] == 1){
        printf("Yes");
    }
    else {
        printf("No");
    }
    return 0;
}


Measured memory_bytes: 256
//                          VIVEK UPADHYAY
//                          MANIT, BHOPAL(M.P)
/**********************************************************************************************/
/**********************************************************************************************/
//                        $$ JAB-TAK TODEGA NHI,
//                           TAB -TAK CHODEGA NHI :D
#include<iostream>
#include<algorithm>
#include<vector>
#include<list>
#include<cstdlib>
#include<unistd.h>
#include<string>
#include<cstring>
#include<stack>
#include<queue>
#include<utility>
#include<cmath>
#include<set>
#include<unordered_map>
#include<cstdio>
#include<map>
#include<numeric>
using namespace std;
#define F first
#define S second
#define mk(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define LINE cout<<"\n" ;
#define ok cout<<"ok\n" ;
#define dbg(x) cout<<#x<<" = "<<(x)<<"\n";
#define fill(A, VAL) memset(A, VAL, sizeof(A))
#define sz(a) ((int) a.size())
typedef long long ll;
const int MAXN = 2*1e5 + 10;
const int MAX = 1e7 + 1 ;
double pi = 3.1415926535897932384626433832795;
const ll inf=1e18 ;
ll mod = 998244353 ;
ll powr(ll a , ll b){ if(b==0) return 1LL ; ll x = powr(a,b/2) ; x = (x*x)%mod ; if(b%2) return ((a%mod)*x)%mod ; return x ;}
ll gcd(ll a , ll b){if(a==0) return b ; return gcd(b%a,a);}
int main () {
    int N ;
    cin >> N ;
    ll a[N] , b[N] ;
    for(int i =0 ; i < N ;i++)
        cin >> a[i] ;
    for(int i =0 ; i < N ;i++)
        cin >> b[i] ;
    vector<ll>  d2 ;
    vector<pair<ll,int>> d1 ;
    for(int i = 0 ;i < N ;i++){
        if(a[i] > b[i]) d1.pb(mk(a[i]-b[i] ,1)) ;
        else if(a[i] < b[i]) d2.pb(b[i]-a[i]) ;
    }
    sort(d1.begin(),d1.end());// available
    reverse(d1.begin(),d1.end()) ;
    sort(d2.begin(),d2.end()) ; // required
    int cnt = 0 ;
    int i = 0 , j = 0 ;
    
    while(i < d1.size() && j < sz(d2)){
        if( d2[j] <= d1[i].F ) {
            d1[i].F-=d2[j] ;
            d2[j] = 0;
            d1[i].S = 0 ;
            j++ ;
        }
        else {
            d2[j]-=d1[i].F ;
            d1[i].S = 0 ;
            i++ ;
        }
    }
    for(int i =0 ; i <d2.size();i++)
        if(d2[i]){
            cout<<"-1\n" ;
            return 0 ;
        }
    cnt+=sz(d2) ;
    for(int i =0 ; i < d1.size() ;i++) if(d1[i].S==0) cnt++ ;
    cout<<cnt<<endl;
}
//zkeyzenceszkeyence


Measured memory_bytes: 3576
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

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

    ll n;
    cin >> n;
    ll n_sum = n * (n + 1) / 2;

    ll a[n+1], a_sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a_sum += a[i];
    }
    a[n] = a[0];

    ll c;
    if (a_sum % n_sum != 0) {
        cout << "NO" << endl;
        return 0;
    } else {
        c = a_sum / n_sum;
    }

    ll count = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] + c == a[i+1]) {
            continue;
        } else if (a[i] + c < a[i+1]) {
            cout << "NO" << endl;
            return 0;
        } else {
            count += (a[i] + c - a[i+1]) / n;
            if ((a[i] + c - a[i+1]) % n != 0) {
                cout << "NO" << endl;
                return 0;
            }
        }
    }

    if (count != c) {
        cout << "NO" << endl;
        return 0;
    }

    cout << "YES" << "\n";
    return 0;
}

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

int conv(string &sex) {
  if (sex == "Male") {
    return 0;
  } else {
    return 1;
  }
}
int main() {
  int n;
  cin>>n;
  int seat[n+1];
  for (int i=0; i<=n; i++) seat[i] = -1;

  cout<<0<<endl<<flush;
  string o1;
  cin>>o1;
  if (o1 == "Vacant") {
    return 0;
  }
  seat[0] = conv(o1);
  seat[n] = seat[0];

  int male = 0;
  int female = 1;
  queue<pair<int, int> > que;
  que.push(make_pair(0, n));
  while (!que.empty()) {
    auto t = que.front();
    que.pop();
    int i_begin = t.first;
    int i_end = t.second;
    int begin = seat[i_begin];
    int end = seat[i_end];
    while (i_begin < i_end) {
      int i = (i_begin + i_end) / 2;
      cout<<i<<endl<<flush;
      string o;
      cin>>o;
      if (o == "Vacant") {
        return 0;
      }
      int sex = conv(o);
      seat[i] = sex;
      bool found = false;
      int prev_end = end;
      if (sex == begin && (i - i_begin) %  2 == 1) {
        i_end = i;
        end = sex;
        found = true;
      } else if (sex != begin && (i - i_begin) % 2 == 0) {
        i_end = i;
        end = sex;
        found = true;
      }
      if ((sex == prev_end) && ((i_end - i) % 2 == 1)) {
        if (!found) {
          i_begin = i;
          begin = sex;
        } else {
          que.push(make_pair(i, i_end));
        }
      } else if ((sex != prev_end) && (i_end - i) % 2 == 0) {
        if (!found) {
          i_begin = i;
          begin = sex;
        } else {
          que.push(make_pair(i, i_end));
        }
      }
    }
  }
}

Measured memory_bytes: 1236
#include <stdio.h>

int main(void)
{
    int a,b,d,r;
    double f;
    
    scanf("%d%d",&a,&b);
    
    d=a/b;
    r=a%b;
    f=(double)a/b;
    
    printf("%d %d %f\n",d,r,f);
    
    return 0;
}


Measured memory_bytes: 2112
import java.util.Scanner;
public class Main{
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a =new int[n];
        
        for( int i = 0; i < n; i++){
            a[i]=sc.nextInt();
        }
        for( int i = n-1; i >= 0; i--){
            System.out.print(a[i]);
            if(i > 0)
               System.out.print(" ");
        }
        System.out.println();
        sc.close();
    }
}


Measured memory_bytes: 26268
s = input()
N = len(s)
s = list(map(int, sorted(s, reverse=True)))

bl = [True for _ in range(N)]

ans = 0
left_edge = 0
a, b = 0, 1
while 0 <= a and b < N:
    if (s[a] == 0 and s[b] == 1) or (s[a] == 1 and s[b] == 0):
        ans += 2
        bl[a] = False
        bl[b] = False
        if a == left_edge:
            while a < N and not bl[a]:
                a += 1
            b = a + 1
            while b < N and not bl[b]:
                b += 1
            left_edge = a
        else:
            while 0 <= a and not bl[a]:
                a -= 1
            if a == -1: break
            while b < N and not bl[b]:
                b += 1
    else:
        a += 1
        while a < N and not bl[a]:
            a += 1
        b = a + 1
        while b < N and not bl[b]:
            b += 1
print(ans)


Measured memory_bytes: 5076
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>

#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second

using namespace std;

template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }

typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod eps=1e-11;
const lod pi=acos(-1);
const int oo=1<<30;
const ll loo=1ll<<62;
const int mods=998244353;
const int MAXN=4005;
const int INF=0x3f3f3f3f;//1061109567
/*--------------------------------------------------------------------*/
inline int read()
{
	int f=1,x=0; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
	while (c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar(); }
	return x*f;
}
int C[MAXN][MAXN],mi[MAXN],n,k;
inline int upd(int x,int y){ return x+y>=mods?x+y-mods:x+y; }
inline int Init(int n)
{
	mi[0]=1;
	for (int i=1;i<=n;i++) mi[i]=upd(mi[i-1],mi[i-1]);
	for (int i=0;i<=n;i++) C[i][0]=C[i][i]=1;
	for (int i=2;i<=n;i++)
		for (int j=1;j<i;j++) C[i][j]=upd(C[i-1][j],C[i-1][j-1]);
}
inline int getans(int num,int k,int n)
{
	int ans=0;
	for (int j=0;j<=num;j++)
		if (k+j-1>=0&&n+k-1>=k+j-1) 
			ans=upd(ans,1ll*C[num][j]*mi[j]%mods*C[n+k-1][k+j-1]%mods); 
	return ans;
}
int main()
{
	k=read(),n=read();
	Init(4000);
	for (int i=2;i<=2*k;i++)
	{
		int num=0;
		for (int j=1;j<=k;j++) if (i-j>=1&&i-j<=k) num++;
		if (i&1) printf("%d\n",getans(num>>1,k-num,n));
		else printf("%d\n",upd(getans((num-1)>>1,k-num,n),getans((num-1)>>1,k-num,n-1)));
	}
	return 0;
}


Measured memory_bytes: 61440
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    men = [0 for _ in range(len(A)+1)]
    for i in range(len(A)-1, -1, -1):
        men[A[i]-1] += 1
    for m in men:
        print(m)


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N - 2 + 1)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


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

int main() {
  char c;
  cin >> c;

  if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
    cout << "vowel" << endl;
  }

  else {
    cout << "consonant" <<endl;
  }
}




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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
#define MOD 1000000007

ll mod_inv(ll a)
{
  ll left = MOD-2;
  ll ret = 1;
  ll ks = a;
  while(left > 0)
  {
    if(left%2 == 1)
    {
      ret = ret*ks%MOD;
    }
    left /=2 ;
    ks = ks*ks%MOD;
  }
  return ret;
}

int main()
{
  ll n,m;
  cin >> n >> m;
  if(m < n) cout << 0 << "\n";
  else
  {
    int i;
    ll nck = 1;
    ll ks = 1;
    ll mpk = 1;
    ll pnk = 1;
    rep(i,n)
    {
      pnk = pnk*(m-i);
      pnk %= MOD;
    }
    ll ans = (nck*ks*mpk*pnk)%MOD*pnk%MOD;
    for(i=1;i<=n;i++)
    {
      nck = nck*(n+1-i)%MOD*mod_inv(i)%MOD;
      ks *= -1;
      mpk = mpk*(m+1-i)%MOD;
      pnk = pnk*mod_inv(m+1-i)%MOD;
      ans = ans+nck*(ks+MOD)%MOD*mpk%MOD*(pnk*pnk%MOD);
      ans %= MOD;
    }
    cout << ans << "\n";
  }
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
#define pb push_back
#define pf push_front
#define re(i , n) for(Long i = 0; i < (Long)n ; i++)
#define rer(i, a, b) for (Long i = a, to = b; i < to; i++)
 
using namespace std;
typedef long long Long;
const Long MX=3700;
const Long MOD=1000000007;
const Long MX2=9223372036854775806;
 


int main(){
    Long X;
    cin>>X;
    Long count=0;
    Long A=100;
    while(A<X){
    A+=A/100;
    count++;
    }
    cout<<count<<endl;
}

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

using namespace std;

int a = 0, b = 0, N;
char sir[1009];

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%s", sir + 1), N = strlen (sir + 1);
for (int i=1; i<=N; i++)
{
    char c = sir[i];
    if (c == 'N') a |= 1;
    else
    if (c == 'S') a |= 2;
    if (c == 'E') b |= 1;
    else
    if (c == 'W') b |= 2;
}
if (a == 1 || a == 2 || b == 1 || b == 2)
    printf ("No\n");
else
    printf ("Yes\n");
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
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; }

int main(){
  int N, Q;
  cin >> N >> Q;
  vector<int> S(N), T(N), X(N);
  rep(i, N)
    cin >> S[i] >> T[i] >> X[i];
  vector<int> D(Q);
  rep(i, Q)
    cin >> D[i];
  vector<tuple<int, int, int>> event;
  rep(i, N) {
    event.push_back(make_tuple(S[i]-X[i], X[i], 1));
    event.push_back(make_tuple(T[i]-X[i], X[i], 0));
  }
  sort(event.begin(), event.end());
  set<int> st;
  map<int, int> ans;
  int p = 0;
  rep(i, Q) {
    while(p < N*2) {
      int t, x, c;
      tie(t, x, c) = event[p];
      if(t > D[i])
        break;
      if(c)
        st.insert(x);
      else
        st.erase(x);
      p++;
    }
    if(st.empty())
      ans[D[i]] = -1;
    else
      ans[D[i]] = *(st.begin());
  }
  rep(i, Q) 
    cout << ans[D[i]] << endl;
  return 0;
}

Measured memory_bytes: 19948
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long long int llint;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int,int>
#define pl pair<ll,ll>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
const long double PI = acos(-1);
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int GCD(int x,int y){
    return y ? GCD(y,x%y) : x;
}
ll a,b,c,d;
ll gcd(ll a,ll b){
    ll r = a % b;
    while(r != 0){
        a = b; 
        b = r;
        r = a%b;
    }
    return b;
}
int main(){
    cin >> a >> b >> c >> d;
    ll ans = b-a+1;
    if(c == 1 || d == 1){
        cout << 0 << endl;
        return 0;
    }
    ll bb =  b / c - (a-1)/c;
    ll aa = b/d - (a-1)/d;
    ll G = gcd(max(c,d),min(c,d));

    ll lcm = c*d/G;
    ll abl = b/lcm-(a-1)/lcm;
    //cout << "bb=" << bb << ",aa = " << aa << ",lcm=" << lcm << ",abl=" << abl << endl;
    ans -= (bb+aa-abl);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lli long long int
#define mod 1000000007
#define pb push_back
#define pf push_front
#define ulli unsigned long long int
#define what_is(x) cerr << #x << " is " << x << endl;
#define pi 2*acos(0.0)
#define F  first
#define S  second
#define endl '\n'
#define all(x) x.begin(),x.end()
using namespace std;
const lli INF = 1e18L+5;
/*
lli power(lli x,lli y)
{
    lli res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}
*/
int main()
{
//cout.precision(10);
//cout.setf(ios::fixed,ios::floatfield);
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
	lli T=1;
    //cin>>T;
	while(T--)
	{
		lli i,a,b,n,j;
		cin>>a>>b;
		cout<<max({a+b,a-b,a*b})<<endl;
	}
}
/*
contest
tt
*/


Measured memory_bytes: 256
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <random>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

template<typename T> T gcd(T a, T b) {
    if (a < b) return gcd(b, a);
    T r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

template<typename T> T lcm(const T a, const T b) {
    return a / gcd(a, b) * b;
}

// End of template.

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

    string s;
    cin >> s;

    int n = s.length();
    int ans = 0;
    rep(i, n / 2) {
        if (s[i] != s[n - i - 1]) ans += 1;
    }

    print(ans);

    return 0;
}



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

using namespace std; 
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>; 

#define INF 100000000
#define MOD 10007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

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

  int A,B,K;
  cin>>A>>B>>K;
  vector<int>ans;
  for(int i=1;i<=min(A,B);i++){
    if(A%i==0&&B%i==0)ans.push_back(i);
  }
  sort(rrng(ans));
  cout<<ans[K-1]<<endl;

  /*
  int N,M;
  cin>>N>>M;
  vector<int>A(M),B(M);
  for(int i=0;i<M;i++)cin>>A[i]>>B[i];
  vector<bool>m(M,false);
  vector<int>ans(M);
  for(int i=M-1;i>=0;i--){
  }
  */
  return 0;
}


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

int main()
{
  string str;

  cin >> str;

  for (int i = 0; i < str.size(); i++){
    if ('A' <= str[i] && str[i] <= 'C'){
      str[i] = str[i] - 'A' + 'X';
    }
    else {
      str[i] -= 3;
    }
  }
  cout << str << endl;

  return 0;
}

Measured memory_bytes: 1184
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <stack>
#include <queue>
#include <cmath>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define llrep(i,j,k) for(long long int i=j;i<(long long int)k;i++)
#define sort(x) sort(x.begin(),x.end()); 
#define vi vector<int>
#define vvi vector<vector<int>> 
#define ll long long
int mod=1e9+7;
const int INF = 100000000;

using namespace std;

void p(int x) {
	cout << x << endl;
}

void pp(string s) {
	cout << s << endl;
}



int main() {
	int n;
	cin >> n;
	vector<int> v(n);
	int sum = 0;
	rep(i, 0, n) {
		cin >> v[i];
		sum += v[i];
	}

	int m;
	cin >> m;
	rep(i, 0, m) {
		int x, y;
		cin >> x >> y;
		x--;

		p(sum + (y - v[x]));
	}


	return 0;
}

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

int a[12][12];
int main() {
  int n,m,x;
  cin >>n>>m>>x;
  vector<int> c(n);
  rep(i,n){
    cin >> c[i];
    rep(j,m) cin>>a[i][j];
  }
  int ans = INF;
  rep(s,1<<n){
    int cost = 0;
    vector<int> d(m);
    rep(i,n){
      if(s>>i&1){
        cost+=c[i];
        rep(j,m) d[j]+=a[i][j];
      }
    }
    bool ok =true;
    rep(j,m) if(d[j]<x) ok =false;
    if(ok) ans =min(ans,cost);
  }
  if(ans==INF)cout <<-1<<endl;
  else cout <<ans<<endl;
  return 0;
}












Measured memory_bytes: 3644
/**********************************************************************************************
******************************AUTHOR:**********************************************************
****************************ASHISH RANJAN******************************************************
***********************************************************************************************/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<chrono>
#include<vector>
#include<string>
#include<cstring>
#include<iomanip>
using namespace std;
using namespace std::chrono;
/*
auto start = high_resolution_clock::now();
auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start); 
  
    cout << "Time taken by function: "
         << duration.count() << " microseconds" << endl;
*/
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long
#define mod 1000000007
#define fr(i,n) for(int i=0;i<(int)n;i++)
#define frs(i,a,b) for(int i = a;i<b;i++)
#define meme(a,b,c) memset(a,b,sizeof(c)); //works only for 0 and -1
int main(){
  fast();
  int n,x,t;
  cin>>n>>x>>t;
  int c = (int)ceil((float)n/x);
  cout<<c*t;
 return 0;
  
}




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

int N;
struct Point {
    int x, y, id;
};
vector<Point> P;

bool cmpx(Point a, Point b) {
    return a.x < b.x;
}
bool cmpy(Point a, Point b) {
    return a.y < b.y;
}

struct Edge {
    int u, v, w;
};
vector<Edge> edge;

bool cmpw(Edge a, Edge b) {
    return a.w < b.w;
}

struct DSU {
    vector<int> par, rnk;
    void init() {
        for(int i = 0; i < N; i++) {
            par.push_back(i);
            rnk.push_back(0);
        }
    }
    int f(int u) {
        if(par[u] == u) return u;
        else return par[u] = f(par[u]);
    }
    void mrg(int u, int v) {
        u = f(u);
        v = f(v);
        if(u == v) return;
        if(rnk[u] < rnk[v]) swap(u, v);
        par[v] = u;
        if(rnk[u] == rnk[v]) rnk[u]++;
    }
} dsu;

int main() {
    scanf("%d", &N);
    P.resize(N);
    for(int i = 0; i < N; i++) {
        scanf("%d %d", &P[i].x, &P[i].y);
        P[i].id = i;
    }
    sort(P.begin(), P.end(), cmpx);
    for(int i = 0; i < N - 1; i++) {
        edge.push_back( { P[i].id, P[i + 1].id, P[i + 1].x - P[i].x } );
    }
    sort(P.begin(), P.end(), cmpy);
    for(int i = 0; i < N - 1; i++) {
        edge.push_back( { P[i].id, P[i + 1].id, P[i + 1].y - P[i].y } );
    }
    sort(edge.begin(), edge.end(), cmpw);

    dsu.init();

    long long ans = 0;

    for(int i = 0; i < edge.size(); i++) {
        int u = edge[i].u;
        int v = edge[i].v;
        int w = edge[i].w;
        if(dsu.f(u) == dsu.f(v)) continue;
        ans += w;
        dsu.mrg(u, v);
    }

    printf("%lld", ans);
}


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

int main()
{
    int N;
    cin >> N;
    ll H[N];
    for(int i = 0; i < N; ++i) cin >> H[i];

    ll border = 1;
    for(int i = 0; i < N; ++i) {
        border = max(border, H[i]);
        if(H[i] >= border - 1) continue;
        else { cout << "No" << endl; return 0;} 
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    string s; cin >> s;
    int g = 0, p = 0;
    for(int i=0; i<s.size(); i++) {
        if(s[i] == 'g') g++;
        else p++;
    }

    cout << (g-p)/2 << endl;

}

Measured memory_bytes: 512
#include<stdio.h>
int main(void){
  int a,b,c,x,y,i=0;
  scanf("%d %d %d",&a,&b,&c);
  for(x=a;x<=b;x++){
    y=c%x;
    if(y==0){
      i++;
    }
  }
  printf("%d\n",i);
  return 0;
}



Measured memory_bytes: 2092
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
signed main(){
  init_io();
  ll a,b,c,k,ans=0;
  cin >> a >> b >> c>>k;
  ll di;

  di = min(a,k);
  k -= di;
  ans += di;

  di = min(b,k);
  k -= di;

  di = min(c,k);
  k -= di;
  ans -= di;
  cout << ans << endl;
}


Measured memory_bytes: 3640
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  ll k,t;cin>>k>>t;
  vl a(t);
  rep(i,t)cin>>a[i];
  ll MAX=0;
  rep(i,t)MAX=max(MAX,a[i]);
  cout<<max(0LL,MAX-(k-MAX)-1)<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        int H = sc.nextInt();
        int W = sc.nextInt();
        int D = sc.nextInt();
        HashMap<Integer, ArrayList<Integer>> map = new HashMap<>();
        int[][] A = new int[H][W];
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                A[i][j] = sc.nextInt();
                ArrayList<Integer> l = new ArrayList<>();
                l.add(i);
                l.add(j);
                map.put(A[i][j], l);
            }
        }
        int Q = sc.nextInt();
        int[][] L = new int[2][Q];
        for(int i = 0; i < Q; i++){
            L[0][i] = sc.nextInt();
            L[1][i] = sc.nextInt();
        }
        sc.close();

        int[] sum = new int[H*W+1];
        for(int i = 1; i < sum.length-D; i++){
            int dis = 0;
            int x1 = map.get(i).get(0);
            int y1 = map.get(i).get(1);
            int x2 = map.get(i+D).get(0);
            int y2 = map.get(i+D).get(1);
            dis += Math.abs(x1-x2)+Math.abs(y1-y2);
            sum[i+D] = sum[i] + dis;
        }
        for(int i = 0; i < Q; i++){
            System.out.println(sum[L[1][i]] - sum[L[0][i]]);
        }
    }
}

Measured memory_bytes: 109936
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
const int N=3005;
typedef long long ll;

int power_mod(int a,int b,ll mod) 
{
	int ans=1;
	while (b) 
	{
		if (b&1) ans=(ll)ans*a%mod;
		b>>=1;
		a=(ll)a*a%mod;
	}
	return ans;
}


int n;
ll mod;
int C[N][N],S[N][N],p2[N*N];

int main()
{
	scanf("%d%lld",&n,&mod);
	C[0][0]=S[0][0]=1;
	for (int i=1;i<=n+1;i++)
	{
		S[i][0]=C[i][0]=1;
		for (int j=1;j<=i;j++) 
		{
			C[i][j]=C[i-1][j]+C[i-1][j-1];if (C[i][j]>=mod) C[i][j]-=mod;
			S[i][j]=((ll)S[i-1][j]*(j+1)+S[i-1][j-1])%mod;
		}
	}
	p2[0]=1;
	for (int i=1;i<=n*n;i++) 
	{
		p2[i]=p2[i-1]+p2[i-1];
		if (p2[i]>=mod) p2[i]-=mod;
	}
	int ans=0,tmp=0,t=1;
	for (int i=0;i<=n;i++,t=mod-t) 
	{
		tmp=0;
		for (int j=0;j<=i;j++) tmp=((ll)S[i][j] * p2[(n-i)*j]%mod+ tmp)%mod;
		tmp=(ll)tmp*power_mod( 2,power_mod(2,n-i,mod-1) ,mod)%mod;
		ans=((ll)t*C[n][i]%mod*tmp+ans)%mod;
	}
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define sz size
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORN(i,a,b) for(int i=a;i<=b;i++)
#define FORRN(i,a,b) for (int i=(a);i>=(b);i--)
#define FORR(i,a,b) for (int i=(a);i>(b);i--)
typedef unsigned long long ull;
typedef long long ll;

void solve(){
    int n,k;
    cin >> n >> k;
    vector<int> A(n);

    for(auto &i: A)
        cin >> i;
    bool vis[100005];
    memset(vis,false,sizeof(vis));

    FORN(i,1,k){
        for(auto j: A){
            if(i>=j && !vis[i-j])
                vis[i]=true;
        }
    }
    cout << (vis[k]?"First":"Second") << endl;
}

int main(){
    ios_base::sync_with_stdio(false); //Fast I/O
    cin.tie(0);
    cout.tie(0);
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);

    int t;
    //cin >> t;
    t=1;
    while(t--){
        solve();
    }

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	int n;
	cin >> n;
	int ans=0;
	for(int i=0; i<n; i++){
		int a;
		cin >> a;
		while(a%2==0){
			a/=2;
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;
int main(){
  int n;
  cin >> n;
  int a[2][n];
  
  int sum=0;
  for(int i=0;i<2;i++){
	for(int j=0;j<n;j++){
      cin >> a[i][j];
      if((i==0)&&(j==0))sum+=a[i][j];
      if(i==1)sum+=a[i][j];
	}
  }
  //cout << sum << endl;
  int tmp_sum=sum;
  for(int i=1;i<n;i++){
    tmp_sum = tmp_sum - a[1][i-1] + a[0][i];
    if(tmp_sum>sum){
      sum=tmp_sum;
      //cout << i << endl;
    }
  }
  cout << sum << endl;
}

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

int main() {
int n;
cin >>n;
vector<string>s(n);
for(int i=0;i<n;i++){
    cin >>s.at(i);
}
int m;
cin >>m;
vector<string>t(m);
for(int i=0;i<m;i++){
    cin >> t.at(i);
}
int ans=0;
for(int i=0;i<n;i++){
    int chea =1;
    string che =s.at(i);
    for(int j=0;j<n;j++){
        if(i!=j){
            if(che==s.at(j))chea++;
        }
    }
    for(int k=0;k<m;k++){
        if(che==t.at(k))chea--;
    }
    ans =max(ans,chea);
}
cout <<ans <<endl;
}



Measured memory_bytes: 256
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include<math.h>
#define ll long long
#define pai 3.1415926535897932384626433832795028841971693
int compare(const void *a, const void *b){
  return (*(ll int *)a)- (*(ll int *)b);
}
 
 
int main(){
  ll int ans=0;
  int n,i;
  scanf("%d",&n);
  int a[(int)1e5+1]={0},d[(int)1e5+1]={0};
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    ans+=a[i];
  }
  for(i=0;i<n;i++){
    d[a[i]]++;//各数字の個数をカウント
  }
  int q;
  scanf("%d",&q);
  int b[q],c[q];
 
    for(i=0;i<q;i++){
      scanf("%d %d",&b[i],&c[i]);
       d[c[i]]+=d[b[i]];
       ans+=(c[i]-b[i])*d[b[i]]; 
       d[b[i]]=0;
 
       printf("%lld\n",ans);
    }
 
  return 0;
}

Measured memory_bytes: 3292
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iterator>
#include <set>
#include <string>
#include <vector>

using namespace std;
using ull = unsigned long long;

int main() {
    ull A, B, K;
    cin >> A >> B >> K;
    set<ull> ans;
    for (ull i = 0, p = A; i < K; ++p, ++i) {
        if (p > B) break;
        ans.insert(p);
    }
    for (ull i = 0, p = B; i < K; --p, ++i) {
        if (p < A) break;
        ans.insert(p);
    }
    for (ull p : ans) {
        cout << p << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()
template<class T>
using reverse_priority_queue = priority_queue<T, vector<T>, greater<T>>;

ll get_rangesum(const vector<ll>& cs, ll left, ll right){
    right = min((ll)cs.size(), right);
    ll ret = cs.at(right - 1);
    if(left > 0){
        ret -= cs.at(left - 1);
    }
    return ret;
}


int main(){
    ll n, k;
    cin >> n >> k;
    vector<ll> p(n), c(n);
    REP(i, n){
        cin >> p.at(i);
        p.at(i)--;
    }
    REP(i, n){
        cin >> c.at(i);
    }

    ll ans = numeric_limits<ll>::min();
    vector<bool> vis(n, false);
    REP(s, n){
        if(vis.at(s)){ continue; }

        vector<ll> c2;
        ll cur = s;
        while(!vis.at(cur)){
            vis.at(cur) = true;
            c2.push_back(c.at(cur));
            cur = p.at(cur);
        }

        // cerr << "c2=";
        // for(ll c2i : c2){
        //     cerr << c2i << " ";
        // }
        // cerr << endl;

        vector<ll> c3 = c2;
        c3.insert(c3.end(), ALL(c2));
        c3.insert(c3.end(), ALL(c2));
        assert(c3.size() == 3 * c2.size());

        vector<ll> cs(c3.size());
        REP(i, cs.size()){
            cs.at(i) = c3.at(i);
            if(i > 0){
                cs.at(i) += cs.at(i - 1);
            }
        }

        const ll m = c2.size();
        const ll total = accumulate(ALL(c2), 0LL);
        // cerr << "total=" << total << endl;
        ll cur_ans = 0;
        ll k2 = k;
        bool looped = false;
        if(total <= 0){
            k2 = min(k2, m);
        }else{
            if(k2 > 2 * m){
                looped = true;
                cur_ans += total * (k2 / m - 1);
                k2 -= m * (k2 / m - 1);
            }
        }

        ll maxval = 0;
        if(!looped){
            maxval = numeric_limits<ll>::min();
        }
        REP(i, m){
            for(ll l = 1; l <= k2; ++l){
                ll tmp = get_rangesum(cs, i, i + l);
                maxval = max(maxval, tmp);
            }
        }
        cur_ans += maxval;

        ans = max(ans, cur_ans);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3924