akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>
using namespace std;

#define ll long long
#define mst(a) memset(a, 0, sizeof a)

const int mod = 1e9+7;
const int maxn = 1e5+50;
const int inf = 1e9;

char s[maxn];
ll dp[maxn][3];

int main()
{
    scanf("%s", s);
    int n = strlen(s);
    ll t3 = 1;
    if (s[0] == 'A') dp[0][0] = 1;
    if (s[0] == '?')
    {
        t3 *= 3;
        dp[0][0] = 1;
    }
    for (int i = 1; i < n; ++i)
    {
        if (s[i] == '?')
        {
            dp[i][0] = (3*dp[i-1][0] + t3) % mod;
            dp[i][1] = (3*dp[i-1][1] + dp[i-1][0]) % mod;
            dp[i][2] = (3*dp[i-1][2] + dp[i-1][1]) % mod;
            t3 = t3 * 3 % mod;
        }
        else if (s[i] == 'A')
        {
            dp[i][0] = (dp[i-1][0] + t3) % mod;
            dp[i][1] = dp[i-1][1];
            dp[i][2] = dp[i-1][2];
        }
        else if (s[i] == 'B')
        {
            dp[i][0] = dp[i-1][0];
            dp[i][1] = (dp[i-1][1] + dp[i-1][0]) % mod;
            dp[i][2] = dp[i-1][2];
        }
        else 
        {
            dp[i][0] = dp[i-1][0];
            dp[i][1] = dp[i-1][1];
            dp[i][2] = (dp[i-1][2] + dp[i-1][1]) % mod;
        }
    }
    printf("%lld\n", dp[n-1][2] % mod);
    return 0;
}

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

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

int main() {
  ll n,m=0;
  cin >> n;
  ll k[n];
  r(i,n)k[i]=0;
  vector<ll> v(n);
  r(i,n){
    cin >> v[i];
    k[v[i]-1]++;//１のボールの個数は、k[0]に入っている
  }
  r(i,n){
    m+=com(k[i]);
  }
  
  r(i,n){
    ll a,b;//k[v[i]]は、添え字i番目のボールの個数
    a=com(k[v[i]-1]);
    b=com(k[v[i]-1]-1);
    cout<<m-a+b<<endl;
  }
}

Measured memory_bytes: 5760
def count(n):
    k = n.bit_length()
    res = 0
    for i in range(k):
        if (n >> i) & 1:
            res += 1
    return res

N = int(input())
X = input()

p = 0
for i in range(N):
    if X[i] == '1':
        p += 1

#Xをp+1で割ったあまり
r1 = 0
for i in range(N):
    if X[~i] == '1':
        r1 += pow(2, i, p + 1)
        r1 %= p + 1

if p > 1:
    #Xをp-1で割ったあまり
    r2 = 0
    for i in range(N):
        if X[~i] == '1':
            r2 += pow(2, i, p - 1)
            r2 %= p - 1
else:
    r2 = -1

rem = [0 for _ in range(N)]

for i in range(N):
    if X[i] == '1': #p-1
        if r2 == -1:
            r = -1
        else:
            r = r2 - pow(2, N - 1 - i, p - 1)
            r %= p - 1
    else:
        r = r1 + pow(2, N - 1 - i, p + 1)
        r %= p + 1
    rem[i] = r

res = [0 for _ in range(N)]

for i in range(N):
    k = rem[i]
    if k == -1:
        res[i] = 0
    else:
        j = 1
        while k:
            k %= count(k)
            j += 1
        res[i] = j

print('\n'.join(map(str, res)))

Measured memory_bytes: 104240
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <map>
#include <vector>
#include <string>
#include <set>

using namespace std;
typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);
    int x, y, x2, y2;
    cin >> x >> y >> x2 >> y2;
    int xd = x2 - x, yd = y2 - y;
    y2 += xd;
    x2 -= yd;
    cout << x2 << " " << y2 << " ";
    y2 -= yd;
    x2 -= xd;
    cout << x2 << " " << y2 << "\n";
}

Measured memory_bytes: 256
N=int(input())
s = [input() for _ in range(N)]
t = sum([s[i].count("AB") for i in range(N)])

p = sum([1 if s[i][-1] == "A" else 0 for i in range(N)])
q = sum([1 if s[i][0] == "B" else 0 for i in range(N)])
r = sum([1 if s[i][0] == "B" and s[i][-1] == "A" else 0 for i in range(N)])

p -= r
q -= r

ans=t
#print(t)
#print(p,q,r)

if r==0:
  ans += min(p,q)
else:
  ans += r-1
  if p>=1:
    p = p-1
    ans +=1
  if q>=1:
    q = q-1
    ans +=1
  ans += min(p,q)
print(ans)

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

int px[90001],py[90001];
int d[90001];

int main(){
    int h,w,D;
    cin>>h>>w>>D;

    rep(i,h){
        rep(j,w){
            int a;
            cin>>a;
            px[a]=i;
            py[a]=j;
        }
    }

    for(int i=D+1;i<=h*w;i++){
        d[i]=d[i-D]+abs(px[i]-px[i-D])+abs(py[i]-py[i-D]);
    }

    int q;
    cin>>q;
    
    while(q--){
        int l,r;
        cin>>l>>r;
        cout<<d[r]-d[l]<<endl;
    }

}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<int,int>;

const int MOD = 1e9 + 7;

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

    int a, b, c;
    cin >> a >> b >> c;

    int m = max(a, max(b, c));
    int sum = a + b + c;
    m *= 3;

    int ans = 0;
    if(sum % 2 == m % 2){
        ans = (m - sum) / 2;
    }else{
        ans = (m - sum + 3) / 2;
    }

    cout << ans << endl;

    return 0;
}


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

#define ll long long
#define ld long double
#define endl '\n'
#define With_the_name_of_Allah ios::sync_with_stdio(0);ios_base::sync_with_stdio(0);cin.tie(0) , cout.tie(0) ;
#define pi double(acos(-1))

using namespace std;

long long mod ;
long long Fast_pow(long long a ,long long b)
{
    if(b==0)
        return 1;

    long long z=Fast_pow(a,b/2);


    if(b%2==0)return ((z%mod)*(z%mod))%mod; else return (((z*z)%mod)*a)%mod;
}



long long gcd(long long a, long long b)
{
    if(a==0)
        return b;
    else return gcd(b%a , a);
}


bool prime[1000001];

void sieve()
{
    memset(prime , true , sizeof prime);
    prime[0]=prime[1]=0;

    for(int i=2 ; i*i<=1000000; i++)
    {
        if(prime[i]==true)
        for(int j=i*i ; j<=100000 ; j+=i)
        prime[j]=false;
    }
}

ll lcm(ll a, ll b)
{
    return (a*b)/__gcd(a,b);
}

ll n,k;
ll a[100005] , store[100005];

ll fn(int in)
{
    if(in==n-1)
        return 0;
    else if(in>=n)
        return 2e9;

    if(store[in]!=-1) return store[in];
    ll ans=2e9;
    for(int i=in+1; i<=in+k ; i++)
        ans=min(ans , abs(a[i]-a[in])+fn(i));
        store[in]=ans;
        return ans;
}
int main()
{
    cin>>n>>k;
    for(int i=0; i<n; i++)
        cin>>a[i];

        memset(store, -1 , sizeof store);

        cout<<fn(0)<<endl;
    return 0;
}


Measured memory_bytes: 6528
#include<iostream>
using namespace std;
int main()
{
	string s1, s2;
	char a = 0, b = 0;
	cin >> a >> b;
	for (int i = 0; i < a-'0'; i++)
	{
		s1 += b;
	}
	for (int i = 0; i < b-'0'; i++)
	{
		s2 += a;
	}
	if (s1 > s2)
	{
		cout << s2;
	}
	else
	{
		cout << s1;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
  #include <algorithm>
  
  using namespace std;
  
  bool isPrime[60000];
 
int main(void){
  fill(isPrime, isPrime+60000, true);
  for(int i=2;i<60000;i++){
    if(isPrime[i]){
      for(int j=2; i*j<60000;j++){
	isPrime[i*j] = false;
      }
    }
  }
 
  int n;
  while(cin >> n){
    int tmp=1;
    int mini=0, maxi = 0;
    while(1){
      if(mini == 0 && isPrime[n-tmp] == true) mini = n-tmp;
      if(maxi == 0 && isPrime[n+tmp] == true) maxi = n+tmp;
      if(mini != 0 && maxi != 0) break;
      tmp++;
    }
    cout << mini << " " << maxi << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#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);

    double t, x;
    cin >> t >> x;

    cout << fixed << setprecision(12) << t / x << "\n";
    return 0;
}

Measured memory_bytes: 256
n = int(input())
sum = [0,0,0,0]
for i in range(n):
  x = input()
  if x == 'AC':
      sum[0]+=1
  elif x == 'WA':
      sum[1]+=1
  elif x == 'TLE':
      sum[2]+=1
  elif x== 'RE':
      sum[3]+=1
print('AC x '+str(sum[0]))
print('WA x '+str(sum[1]))
print('TLE x '+str(sum[2]))
print('RE x '+str(sum[3]))

Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 
int main(){
ll int a,b,x;
cin >> a >> b >> x;
if(x == 1){
cout << b - a + 1 << endl;
return 0;
}
if(a == 0){
 cout << (b / x) - ((a-1) / x) + 1 << endl;
return 0;
}
a--;
 cout << (b / x) - (a / x) << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	LL N,A,B;
	cin >>N>>A>>B;

	LL num = N;
	LL nokori = num-A;//A個昇順でならべる。
	if( N+1 < A+B ){
		cout << -1 << endl;
		return;
	}
	if( A*B < N ){//A*(B-1) < nokori=N-A
		cout << -1 << endl;
		return;
	}
	int BIG = N;
	int SMALL = N-A;
	
	vector< vector<int> > ans(A);
	for(int i=0;i<A;++i){
		ans[A-1-i].push_back( BIG );
		--BIG;
		for(int j=0;SMALL>=1 && j<B-1;++j){//B-1個並べる。
			ans[A-1-i].push_back( SMALL );
			--SMALL;
		}
	}
	//output
	bool flag = false;
	for(int i=0;i<A;++i){
		int size = ans[i].size();
		for(int j=0;j<size;++j){
			if( flag ){
				cout << " ";
			}else{
				flag = true;
			}
			cout << ans[i][j];
		}
	}
	cout << endl;
}
#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 16640
#include<bits/stdc++.h>
using namespace std;int x[150][150][2],n,m,l,a,b,c,d,i,j,k,o,minx,INF=1<<25,dp[150][150];int DP(int p,int v){memset(dp,127,sizeof(dp));dp[0][v]=0;for(i=0;i<p;i++){for(j=0;j<n;j++){for(k=0;k<n;k++){if(x[j][k][0]<INF){for(o=0;o<=v;o++){if(dp[j][o]<INF){dp[k][o]=min(dp[k][o],dp[j][o]+x[j][k][1]);if(o>=x[j][k][0]){dp[k][o-x[j][k][0]]=min(dp[k][o-x[j][k][0]],dp[j][o]);}}}}}}}minx=INF;for(i=0;i<=v;i++){minx=min(minx,dp[p-1][i]);}return minx;}main(){while(1){memset(x,127,sizeof(x));cin>>n>>m>>l;if(!n){break;}for(i=0;i<m;i++){cin>>a>>b>>c>>d;a--;b--;x[a][b][0]=c;x[a][b][1]=d;x[b][a][0]=c;x[b][a][1]=d;}cout<<DP(n,l)<<endl;}}

Measured memory_bytes: 3280
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <limits>

using namespace std;

#define ll long long

#define in(x) cin >> x
#define out(x) cout << x << endl

#define PI acos(-1)
#define pp push_back

#define Yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define No cout << "No" << endl
#define NO cout << "NO" << endl

#define vec2(type) vector<vector<type>>
#define vec3(type) vector<vector<vector<type>>>

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

template<typename T> void input(T *data, int n){
	For(i, n){
		cin >> data[i];
	}
}

template<typename T> void input(vector<T> &vec, int n){
	T temp;
	For(i, n){
		cin >> temp;
		vec.push_back(temp);
	}
}

template<typename T> void sort(vector<T> &ary){
	sort(ary.begin(), ary.end());
}

template<typename T> void rsort(vector<T> &ary){
	sort(ary.rbegin(), ary.rend());
}

void rstring(string &str){
	string temp = str;

	For(i, (int)str.size()){
		str[i] = temp[(str.size() - 1) - i];
	}
}

struct Vec{
	int x, y;
	Vec():
	x(0), y(0){}
	Vec(int _x, int _y):
	x(_x), y(_y){}
};

template<typename T> void print(T *x, int n){
	For(i, n){
		cout << x[i] << " ";
	}
	cout << endl;
}

template<typename T> void print(vector<T> &x){
	For(i, (int)x.size()){
		cout << x[i] << " ";
	}
	cout << endl;
}

int gcd(int n, int m){
	if(n % m == 0){
		return m;
	}
	else{
		return gcd(m, n % m);
	}
}

unsigned ll func(unsigned ll n, unsigned ll i){

	n++;
	if(n >> i == 0){
		return 0;
	}
	unsigned ll num_one = (n / (2 << i)) * (1 << i);

	if((n % (2 << i)) != 0 && (n % (2 << i)) - (1 << i) > 0){
		num_one += (n % (2 << i)) - (1 << i);
	}

	return num_one;

}

int main(){

	string s;
	in(s);

	int count_one = 0;
	int count_zero = 0;

	For(i, (int)s.size()){
		if(s[i] == '0'){
			count_zero++;
		}
		else{
			count_one++;
		}
	}

	out(min(count_one, count_zero) * 2);

	return 0;

}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
using namespace std;

int main()
{
	int N, T;
	cin >> N >> T;
	auto cost = 10000;
	for (auto i = 0; i < N; ++i)
	{
		int c, t;
		cin >> c >> t;
		if (t > T)
		{
			continue;
		}

		cost = min(cost, c);
	}

	if (cost >= 10000)
	{
		cout << "TLE" << endl;
	}
	else
	{
		cout << cost << endl;
	}

	return 0;
}


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

#define MAX_INT 0x3f3f3f3f 
#define precision(x) setprecision(x)
#define boost ios_base::sync_with_stdio(false); 	cin.tie(NULL);

int main()
{
	boost;
	int k;
	cin >> k;
	int a,b;
	cin >> a >> b;
	for(int i=k;i<=b;i+=k)
	{
		if(i>=a && i<=b)
		{
			cout << "OK\n";
			return 0;
		}
	}
	cout << "NG\n";
	return 0;
}

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

double n, m, d;

signed main()
{
    cin >> n >> m >> d;
    if(d == 0) printf("%.10lf\n", (m - 1) / n);
    else printf("%.10lf\n", (m - 1) * 2 * (n - d) / (n * n));


    return 0;
}


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

int A, B, C, D, E, F;

int suger_max(int water) {
	return E * (water / 100);
}

int main() {
	cin >> A >> B >> C >> D >> E >> F;	

	int ans_w = 0;
	int ans_s = 0;

	double max_d = - 1.0;

	for (int a = 0; a <= F; a += 100 * A) {
		for (int b = 0; a + b <= F; b += 100 * B) {
			int water = a + b;

			int suger = 0;
			for (int c = 0; c <= min(F - water, suger_max(water)); c += C) {
				int buf = c;
				while (water + buf + D <= F && buf + D <= suger_max(water)) {
					buf += D;
				}
				if (suger < buf) suger = buf;
			}

			if (water > 0 && max_d < (long double)suger / (water + suger)) {
				max_d = (long double)suger / (water + suger);
				ans_w = water, ans_s = suger;
			}
		}
	}


	cout << ans_w + ans_s << " " << ans_s << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>		//UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>		//do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define ALL(u) (u).begin(),(u).end()

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

typedef pair<int, int> PII;

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;

const int MR = 1010;
const int MS = 5010;
const int inf = 1e9;

int X[MR], best[MR], V[2][MS];

vector<int> g[MR];

void go(int nr)
{
	for (int i : g[nr])
		go(i);

	if (g[nr].empty())
		return;

	// wyznacz minimalna pare dla utworzenia X[nr]
	V[0][0] = 0;
	FOR(v, 1, X[nr] + 1)
		V[0][v] = inf;
	bool sel = 0;
	for (int i : g[nr])
	{
		sel = !sel;
		REP(v, X[nr] + 1)
			V[sel][v] = inf;
		// jedz wartoscia X i best dla dziecka
		vector<int> tmp = { best[i], X[i] };
		REP(j, 2)
		{
			int vc = tmp[j], nvc = tmp[!j];
			FORD(v, X[nr] + 1, vc)
				if (V[!sel][v - vc] != inf)
					V[sel][v] = min(V[sel][v], V[!sel][v - vc] + nvc);
		}
	}

	best[nr] = inf;

	REP(v, X[nr] + 1)
		best[nr] = min(best[nr], V[sel][v]);
}

int main()
{
	int N;
	scanf("%d", &N);

	REP(i, N - 1)
	{
		int p;
		scanf("%d", &p); p--;
		g[p].push_back(i + 1);
	}

	REP(i, N)
		scanf("%d", &X[i]);

	go(0);

	if (best[0] == inf)
		printf("IMPOSSIBLE\n");
	else
		printf("POSSIBLE\n");

	return 0;
}

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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define endl '\n'

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 998244353;

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

  ll n;
  cin >> n;
  vector<ll> h(n);
  REP(i, n) cin >> h[i];

  vector<ll> dp(n, LLINF);
  dp[0] = 0;
  REP(i, n) {
    if(i+1 < n) chmin(dp[i+1], dp[i] + abs(h[i] - h[i+1]));
    if(i+2 < n) chmin(dp[i+2], dp[i] + abs(h[i] - h[i+2]));
  }
  cout << dp[n-1] << endl;

  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,x,n) for(ll i=x;i<n;i++) 
#define sort(v) sort(v.begin(),v.end());
const ll mod = 1E9+7;

int main()
{
   ll t=1;
//    cin>>t;
   while(t--){
      ll n,m;
      cin>>n>>m;
      vector<ll> v[n+1];
      vector<bool> vis(n+1,false);
      loop(i,0,m){
         ll a,b;
         cin>>a>>b;
         v[a].push_back(b);
         v[b].push_back(a);
      }
      ll graphsct = 0;
      queue<ll> q;
      ll ans = 1;
      loop(i,1,n+1){
         ll ct = 0;
         if(!vis[i]){
            graphsct++;
            vis[i] = 1;            
            q.push(i);
         } 
         else continue;
         while(!q.empty()){
            ct++;
            ll top = q.front();
            q.pop();
            loop(j,0,v[top].size()){
               if(!vis[v[top][j]]){
                  vis[v[top][j]] = 1;
                  q.push(v[top][j]);
               }
            }
         }
         ans  = (ans%mod*ct%mod)%mod;
      }
      cout<<graphsct-1;

   }
}

Measured memory_bytes: 9612
#include <iostream>
#include <cmath>
#include <unordered_map>
#include <map>
#include <set>
#include <vector>

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

using namespace std;
typedef unsigned long long ul;
typedef long long ll;
typedef pair<int, int> PAIR;

int main() {
  int n;
  cin >> n;
  vector<PAIR> balls;
  REP(i, n) {
      int x, y;
      cin >> x >> y;
      balls.push_back(PAIR(x, y));
  }
  map<PAIR, int> dist_pairs;
  REP(i, n) {
      REP(j, n) {
          if (i == j) continue; 
          PAIR a = balls[i];
          PAIR b = balls[j];
          PAIR dist = PAIR(a.first - b.first, a.second - b.second);
          dist_pairs[dist] ++;
      }
  }
  int n_max = 0;
  for (auto itr = dist_pairs.begin(); itr != dist_pairs.end(); ++itr) {
    //   printf("(%d, %d): %d\n", itr->first.first, itr->first.second, itr->second);
      n_max = n_max > itr->second ? n_max : itr->second;
  }
  cout << n - n_max;
  return 0;
}


Measured memory_bytes: 384
def q_b():
    k = int(input())
    a = map(int, input().split())
    a = list(a)

    is_finished = False
    for i in a:
        if i == 0:
            print(0)
            is_finished = True
            break

    if is_finished:
        return

    answer = 1
    for i in a:
        answer *= i
        if answer > 10 ** 18:
            print(-1)
            is_finished = True
            break

    if is_finished is False:
        print(answer)


if __name__ == '__main__':
    q_b()


Measured memory_bytes: 21708
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    S = ST()
    d = defaultdict(int)
    for s in S:
        d[s] += 1
    for i in range(26):
        if d[chr(i + ord("a"))] == 0:
            print(chr(i + ord("a")))
            exit()
    print("None")

            
if __name__ == '__main__':
    main()

Measured memory_bytes: 39792
//#include<iostream>
//#include<vector>
//using namespace std;
//
//
//
//int main() {
//
//	int n;
//
//	cin >> n;
//	int a[105];
//	for (int i = 0; i < n; i++) {
//		cin >> a[i];
//	}
//
//	int sum = 0;
//
//	int i = 0;
//	while (i <= n - 1) {
//		for (int j = n - 1; j > i ; j--) {
//			if (a[j] < a[j - 1]) {
//				int tmp = a[j];
//				a[j] = a[j-1];
//				a[j - 1] = tmp;
//				sum++;
//			}
//		}
//
//		i++;
//	}
//
//	for (int i = 0; i < n; i++) {
//		if(i!=n-1)cout << a[i] << " ";
//		if (i == n - 1)cout << a[i] << endl;
//	}
//	cout << sum << endl;
//}
//


//Bubble sort
#include<iostream>
using namespace std;

int bublleSort(int A[], int N) {
	int flag = 1;
	int cnt = 0;

	while (flag) {
		flag = 0;
		for (int j = N - 1; j >= 1; j--) {
			if (A[j] < A[j - 1]) {
				int tmp = A[j];
				A[j] = A[j - 1];
				A[j - 1] = tmp;
				flag = 1;
				cnt++;
			}

		}
	}
	return cnt;
}


int main() {
	int n;

	cin >> n;
	int A[105];

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

	int ans = bublleSort(A, n);

	for (int i = 0; i < n; i++) {
		if (i == n - 1)cout << A[i] << endl;
		else cout << A[i] << " ";
	}
	cout << ans << endl;

}


Measured memory_bytes: 3096
import java.util.*;
class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int k = scan.nextInt();
        int[] ary = new int[n+1];
        int ans = 0;
        for (int i = 1; i < k+1 ; i++){
            for(int d = scan.nextInt(); d>0 ; d--){
                ary[scan.nextInt()] ++;
            }
        }
        for (int i = 1; i<=n ; i++){
            if (ary[i]==0){
                ans ++;
            }
        }
        System.out.println(ans);
            }
        }

Measured memory_bytes: 46028
#include<iostream>
#include<fstream>
#include<algorithm>
#include<string>
#include<cstring>
#include<unordered_map>
#include<unordered_set>
#include<tuple>
#include<vector>
#include<cmath>


using namespace std;

unordered_set <int> Good;

const int MAXN = 100000 + 10;
int cnt[MAXN];


const int MAXK = 500;
int board[MAXK][MAXK];

int main() {
	int N;
	cin >> N;
	
	for (int i = 1; i < 500; i++) {
		Good.insert(i * (i + 1) / 2);
	}

	if (!Good.count(N)) cout << "No" << endl;
	else {
		cout << "Yes" << endl;
		int K = (int)sqrt(N * 2) + 1;
		int Q = N * 2 / K;
		int cur = 1;
		cout << K << endl;
		for (int i = 0; i < K; i++) {
			cout << Q << " ";
			for (int j = 0; j < i; j++) {
				cout << board[j][i - 1] << " ";
				board[i][j] = board[j][i - 1];
			}

			for (int k = i; k < Q; k++) {
				cout << cur << " ";
				board[i][k] = cur++;
			}
			cout << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 2304
#include <cstdio>
#include <algorithm>
using namespace std;

struct Node
{
    int par,sibling,left,right;
    int deg,depth,height;
};

Node G[100001];

int dfs(int n, int m)
{
    G[n].depth = m;
    G[n].deg = 0;
    G[n].sibling = -1;
    G[n].height = 0;
    if(G[n].left != -1){
        ++G[n].deg;
        G[n].height = max(G[n].height, dfs(G[n].left, m + 1));    
    }
    
    if(G[n].right != -1){
        ++G[n].deg;
        G[n].height = max(G[n].height, dfs(G[n].right, m + 1));
    }
    
    if(G[n].deg == 2){
        G[G[n].left].sibling = G[n].right;
        G[G[n].right].sibling = G[n].left;
    }
    
    return G[n].height + 1;
}

int main()
{
    int n,id,left,right;
    scanf("%d", &n);
    
    for(int i = 0; i < n; ++i){
        G[i].par = -1;
    }
    
    for(int i = 0; i < n; ++i){
        scanf("%d%d%d", &id, &left, &right);
        G[id].left = left;
        G[id].right = right;
        if(left != -1)G[left].par = id;
        if(right != -1)G[right].par = id;
    }
    
    int root;
    for(int i = 0; i < n; ++i){
        if(G[i].par == -1){
            root = i;
            break;
        }
    }
    dfs(root, 0);
    
    for(int i = 0; i < n; ++i){
        printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s\n", 
        i, G[i].par, G[i].sibling, G[i].deg, G[i].depth, G[i].height, i == root ? "root" : G[i].deg == 0 ? "leaf" : "internal node");
    }
}

Measured memory_bytes: 1028
#include <iostream>

using namespace std;

int main(void) {
  int A, B;
  cin >> A >> B;
  if(1 <= A && A <= 9 && 1 <= B && B <= 9) {
    cout << A*B << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}




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

int main() {
    string S;
    cin >> S;
    rep(i, 1<<3) {
        bitset<3> op(i);
        int x = S[0] - '0';
        rep(j, 3){
            if(op[j]) {
                x += S[j+1] - '0';
            } else {
                x -= S[j+1] - '0';
            }
        }
        if(x == 7) {
            string H;
            rep(j, 3) {
                if(op[j]) {
                    H += '+';
                } else {
                    H += '-';
                }
            }
            rep(j, 3){
                cout << S[j] << H[j];
            }
            cout << S[3] << "=7" << endl;
            break;
        }
    }
}

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


int main(){
	int a,b;

	cin >> a >> b;

	int tempa=0,tempb=0;
	int temp=1;

	for(int i=0;i<a;i++){
		tempa += (temp*b);
		temp=temp*10;
	}
	temp=1;
	for(int i=1;i<=b;i++){
		tempb += (temp*a);
		temp=temp*10;
	}
//	cout << tempa << " " << tempb;
	string out;
	if(to_string(tempa)<to_string(tempb)){
		out = to_string(tempa);
	}else{
		out = to_string(tempb);
	}
	cout << out;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

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

    int n, m;
    cin >> n >> m;
    int d[51][51];
    rep(i, n) rep(j, n) d[i][j] = INF;
    rep(i, n) d[i][i] = 0;
    vector<int> a(m), b(m);
    rep(i, m)
    {
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
        d[a[i]][b[i]] = d[b[i]][a[i]] = 1;
    }
    int ans = 0;
    rep(i, m)
    {
        int tmp[51][51];
        rep(j, n) rep(k, n) tmp[j][k] = d[j][k];
        tmp[a[i]][b[i]] = tmp[b[i]][a[i]] = INF;
        rep(l, n) rep(j, n) rep(k, n) tmp[j][k] = min(tmp[j][k], tmp[j][l] + tmp[l][k]);
        if (tmp[a[i]][b[i]] == INF)
            ans++;
    }
    cout << ans << endl;
}


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

using namespace std;
const int N = 100010;
int arr[N];
int main()
{
    int n;
    scanf("%d",&n);
    vector<int> vec;
    for(int i = 0;i<n;i++) {
        int x;
        scanf("%d",&x);
        arr[x]++;
        if(arr[x]>1)
            vec.push_back(x);
    }
    int removed = 0;
    while(vec.size()>2)
        vec.pop_back(), vec.pop_back(), removed += 2;
    if(vec.size())
        removed += 2;
    printf("%d",n-removed);
    return 0;
}


Measured memory_bytes: 1276
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll eraseOverlapIntervals(vector<vector<ll>>& intervals) {
          if(intervals.size()==0) return 0;
          //sort based on earliest finishing time -- most optimal approach for scheduling problem
          sort(intervals.begin(), intervals.end(), [](vector<ll> x, vector<ll> y) {
              return x[1]<y[1];
          });
          ll remove = 0, j = 0;
          vector<vector<ll>> accepted;
          accepted.push_back(intervals.front()); //first interval
          for(int i=1; i<intervals.size(); i++) {
              if(accepted[j][0] < intervals[i][1] && intervals[i][0] < accepted[j][1]) {
                  remove++;
              }
              else {
                  accepted.push_back(intervals[i]);
                  j++;
              }
          }
          return remove;
    }
int main()
{
    ll n,max1=0,ans=0;
    cin>>n;
    vector<vector<ll>>vv;
    for(int i=0;i<n;i++)
    {
        ll a,b;
        cin>>a>>b;
        vector<ll>v;
        
        v.push_back(a-b);
        v.push_back(a+b);
        vv.push_back(v);
    } 
    cout<<n-eraseOverlapIntervals(vv);
}

Measured memory_bytes: 11824
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    int a[3*n]; for (int i = 0; i < 3*n; i++) cin >> a[i];
    long long ans = 0;
    sort(a, a+3*n);
    for (int i = 1; i <= n; i++) ans += a[3*n-2*i];
    cout << ans << endl;
}


Measured memory_bytes: 1408
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int main(){
  int i;
  int N;
  int x = 0;
  int y;
  rd(N);
  while(x*(x+1)/2 < N){
    x++;
  }
  y = x*(x+1)/2 - N;
  for(i=(1);i<(x+1);i++){
    if(i!=y){
      wt_L(i);
      wt_L('\n');
    }
  }
  return 0;
}
// cLay varsion 20191123-1

// --- original code ---
// {
//   int N, x = 0, y;
//   rd(N);
//   while(x*(x+1)/2 < N) x++;
//   y = x*(x+1)/2 - N;
//   rep(i,1,x+1) if(i!=y) wt(i);
// }


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int r, d, x;
    cin >> r >> d >> x;
    int pre = x;
    for(int i = 1; i <= 10; i++){
        int ans = r * pre - d;
        cout << ans << endl;
        pre = ans;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdbool.h>

void heisei(int year, int month, int day);
void showa(int year, int month, int day);
void taisho(int year, int month, int day);
void meiji(int year, int month, int day);
void pre_meiji(void);
void era_name_transformer(int year, int month, int day);

int main(void)
{
    int year, month, day;

    while(scanf("%d %d %d", &year, &month, &day) != EOF) {
        era_name_transformer(year, month, day);
    }        
    return 0;
}

void era_name_transformer(int year, int month, int day)
{
    if (year > 1989) {
        heisei(year, month, day);
    } else if (year == 1989) {
        if (month > 1) {
            heisei(year, month, day);
        } else if (month == 1) {
            if (day >= 8) {
                heisei(year, month, day);        
            } else {
                showa(year, month, day);        
            }          
        }
    } else if (year > 1926) {
        showa(year, month, day);
    } else if (year == 1926) {
        if (month == 12) {
            if (day >= 25) {
                showa(year, month, day);     
            } else {
                taisho(year, month, day); 
            }          
        } else {
            taisho(year, month, day);
        }
    } else if (year > 1912){
        taisho(year, month, day);
    } else if (year == 1912) {
        if (month > 7) {
            taisho(year, month, day);
        } else if (month == 7) {
            if (day >= 30) {
                taisho(year, month, day);     
            } else {
                meiji(year, month, day); 
            }          
        } else {
            meiji(year, month, day);
        }
    } else if (year > 1868) {
        meiji(year, month, day);
    } else if (year == 1868) {
        if (month > 9) {
            meiji(year, month, day);
        } else if (month == 9) {
            if (day >= 8) {
                meiji(year, month, day);     
            } else {
                pre_meiji(); 
            }          
        } else {
            pre_meiji();
        }
    } else {
        pre_meiji();
    }
}

void heisei(int year, int month, int day)
{
    printf("heisei %d %d %d\n", year - 1988, month, day);
}

void showa(int year, int month, int day)
{
    printf("showa %d %d %d\n", year - 1925, month, day);
}

void taisho(int year, int month, int day)
{
    printf("taisho %d %d %d\n", year - 1911, month, day);
}

void meiji(int year, int month, int day)
{
    printf("meiji %d %d %d\n", year - 1867, month, day);
}

void pre_meiji(void)
{
    printf("pre-meiji\n");
}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, M;
ll A[1005], Key[1005], DP[1005][(1<<12)];
Pll P[1005];

int main(){
  cin >> N >> M;
  for (int i = 1; i <= M; i++){
    int B;
    cin >> A[i] >> B;
    for (int j = 0; j < B; j++){
      int C; cin >> C;
      Key[i] += (1 << (C - 1));
    }
    P[i] = {Key[i], A[i]};
  }
  sort(P, P + M);
  fill((ll*)DP, (ll*)(DP + M + 1), 1e18);

  DP[0][0] = 0;
  for (int i = 1; i <= M; i++){
    for (int j = 0; j < (1<<N); j++){
      DP[i][j] = DP[i-1][j];
    }

    ll val = P[i].se, key = P[i].fi;
    for (int j = 0; j < (1<<N); j++){
      DP[i][(j|key)] = min(DP[i][(j|key)], DP[i-1][j] + val);
    }
  }
  ll ans = DP[M][(1<<N)-1];
  if (ans == 1e18) ans = -1;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 35640
#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

constexpr ll INF = 1e16;
constexpr ll MOD = 1000000007;

#define rep(i, N) for(ll i=0; i<(N); ++i)

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


ll max(ll a, ll b) {return a < b ? b : a; }
ll min(ll a, ll b) {return a > b ? b : a; }
double maxf(double a, double b) { return a < b ? b : a; }

template<typename T> inline string toString(const T &a) {
  ostringstream oss; oss << a; return oss.str();
}

ll gcd(ll x, ll y) { return x % y ? gcd(y, x % y) : y; }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

int main() {
  vector<int> n(10);
  int A, B, C;
  cin >> A >> B >> C;
  n[A] ++;
  n[B] ++;
  n[C] ++;
  rep(i, 10) {
    if(n[i] == 2) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  
  cout << "No" << endl;
}


Measured memory_bytes: 256
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using ll = long long;
using P = pair<ll,ll>;

int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
ll n;
cin >> n;
string s;
cin >> s;
vector<ll> black_sum(n + 1,0),white_sum(n + 1,0);
rep(i,n){
    black_sum[i + 1] = black_sum[i] + (s[i] == '#' ? 1 : 0);
    white_sum[i + 1] = white_sum[i] + (s[i] == '#' ? 0 : 1);
}
ll ans = 1145141919810;
rep(i,n + 1){
    ans = min(black_sum[i] + n - i - (black_sum[n] - black_sum[i]),ans);
}

cout << ans << endl;
}

Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
#define ri register int
typedef long long ll;
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	// input a signed integer
	template <class I>
	inline void gi (I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = (x << 1) + (x << 3) + (c & 15); x *= f;
	}
	// print a signed integer
	template <class I>
	inline void print (I x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
	}
	//no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: gi;
using io :: putc;
using io :: print;
const int N=3005;
int s[N][N],c[N][N],power[N],pk[N];
inline int fpow(ri a,ri b,ri mod){
	ri ans=1;
	for(;b;b>>=1,a=(ll)a*a%mod)
		if(b&1) ans=(ll)ans*a%mod;
	return ans;
}
inline int _add(ri x,ri y,ri mod){
	return (x+=y)>=mod?x-mod:x;
}
int main(){
	ri n,mod,i,j,k,ans,res,now;
	scanf("%d%d",&n,&mod);
	s[0][0]=1;
	for(i=1;i<=n;++i)
		for(j=1;j<=i;++j)
			s[i][j]=((ll)s[i-1][j]*j+s[i-1][j-1])%mod;
	for(i=0;i<=n;++i){
		c[i][0]=1;
		for(j=1;j<=i;++j)
			c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;
	}
	power[0]=1;
	for(i=1;i<=n;++i) power[i]=_add(power[i-1],power[i-1],mod);
	ans=0;
	for(i=0;i<=n;++i){
		pk[0]=1;
		for(k=1;k<=i;++k) pk[k]=(ll)pk[k-1]*power[n-i]%mod;
		now=fpow(2,fpow(2,n-i,mod-1),mod);
		for(k=0;k<=i;++k){
			res=(ll)s[i][k]*pk[k]%mod;
			if(k) res=(res+(ll)s[i][k]*k%mod*pk[k-1])%mod;
			ans=(ans+(i&1?-1ll:1ll)*c[n][i]*now%mod*res)%mod;
		}
	}
	ans=ans<0?ans+mod:ans;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 70656
#include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;


int main()
{
    int n;
    cin >> n;
    int order[n];
    int a[n];
    for (int i=0; i<n; i++) {
        cin >> a[i];
        order[a[i]-1] = i+1;
    }
    for (int i=0; i<n; i++) {
        cout << order[i] << ' ';
    }
   
    return 0;
}

Measured memory_bytes: 4400
#include <bits/stdc++.h>
#define int long long
using namespace std;

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

    int n;
    cin>>n;
    int a[n];
    int cnt=0;
    for (int i = 0; i < n; ++i) {
        cin>>a[i];
        if(a[i]!=i+1)
            cnt++;
    }

    if(cnt==0||cnt==2)
    {
        cout<<"YES";
    } else
        cout<<"NO";
}

Measured memory_bytes: 256
#pragma GCC optimize (3)
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<algorithm>
#include<unordered_map>
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#include<ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>*/
//#include<ext/rope>
#define ll long long
#define ull unsigned long long
#define INFI 2147483647
#define INFL 9223372036854775807
#define INFU 18446744073709551615
using namespace std;
//using namespace __gnu_pbds;
//using namespace __gnu_cxx;
const double PI=acos(-1.0);
const double eps=1e-6;
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 a[150];
signed main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
    int n=read();
    for(int i=1;i<=n;i++) a[i]=read();
    if(n<3) cout<<0<<endl;
    else{
        int ans=0;
        for(int i=1;i<=n-2;i++){
            for(int j=i+1;j<=n-1;j++){
                for(int k=j+1;k<=n;k++){
                    if(a[i]!=a[j] && a[i]!=a[k] && a[j]!=a[k] && a[i]+a[j]>a[k] && a[i]+a[k]>a[j] && a[j]+a[k]>a[i]){
                        ans++;
                    }
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


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

int main(){
  ll n,sum1=0,sum2=0;
  cin >> n;
  vector<vector<ll>> v(n,vector<ll>(3,0));
  vector<ll> v2(n);
  r(i,n)cin >> v[i][1];
  r(i,n){
    cin >> v[i][2];
    v[i][0]=v[i][1]-v[i][2];
    sum1+=v[i][1]; sum2+=v[i][2];
  }
  if(sum1<sum2)cout<<-1<<endl;//絶対むり
  else{
  sort(v.begin(),v.end());
    r(i,n)v2[i]=v[i][0];
  ll i=0,j=n-1;
  while(v[i][0]<0){
    if(v[j][0]+v[i][0]<0){
      v[i][0]+=v[j][0];
      v[j][0]=0;
    }
      else {
        v[j][0]+=v[i][0];
        v[i][0]=0;
      }     
    if(v[j][0]==0)j--;
    if(v[i][0]>=0)i++;
  }
    ll ans=0;
    r(i,n)if(v[i][0]!=v2[i])ans++;
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
int main(){
   string a,b;
   cin>>a>>b;
   int dp[a.length()+1][b.length()+1];
   char d[a.length()+1][b.length()+1];
   for(int i=0;i<=a.length();i++){
   	for(int j=0;j<=b.length();j++){
   		if(i==0||j==0){
   		    dp[i][j]=0;
   		    d[i][j]='o';
		   }
		else{
			if(a[i-1]==b[j-1]){
				dp[i][j]=dp[i-1][j-1]+1;
				d[i][j]='d';
			}
			else{
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
				if(dp[i-1][j]>dp[i][j-1]){
					d[i][j]='u';
				}
				else{
						d[i][j]='l';
				}
			}
		}
	   }
   }
   string ans="";
   int i=a.length(),j=b.length();
   while(i!=0&&j!=0){
   	    if(d[i][j]=='d'){
   	    	ans=a[i-1]+ans;
   	    	i--;
   	    	j--;
   	    	continue;
		   }
		else if(d[i][j]=='l'){
		   	j--;
		   	continue;
		}
		else{
			i--;
		}
   }
   cout<<ans<<"\n";
}


Measured memory_bytes: 44288
fun main(args: Array<String>) {
    val (H, W) = readInputLine().split(" ").map { it.toInt() }
    
    val a = Array(H, { readInputLine().toCharArray() })
    
    val printRows = mutableListOf<Int>()
    val printCols = mutableListOf<Int>()
    
    // 出力行判定
    for (i in 0 until H) {
        var print = false
        for (j in 0 until W) {
            if (a[i][j] == '#') {
                print = true
                break
            }
        }
        if (print) {
            printRows.add(i)
        }
    }

    // 出力列判定
    for (j in 0 until W) {
        var print = false
        for (i in 0 until H) {
            if (a[i][j] == '#') {
                print = true
                break
            }
        }
        if (print) {
            printCols.add(j)
        }
    }
    
    for (row in printRows) {
        for (col in printCols) {
            print(a[row][col])
        }
        println()
    }
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 37996
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;

//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define RES(a,i,j) a.resize(i);rep(ii,i)a[ii].resize(j); 
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout<<a<<" "<<b<<" "<<c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll) 
#define gre(n) greater<n>()

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
const int INF = 1000000000;
const double dINF = 1000000000;
const ll INF64 = 922337203685477580ll;
const ll MOD = 1000000007ll;
const dou pi=3.141592653589793;
//メモ
//二次元配列のresizeのしかた
//vv.resize(n);
//for(size_t i=0; i<n; i++){
// vv[i].resize(n);
//}

//メモ
//負の辺を持つ最短経路問題では到達不可経路でも初期化値より小さくなりうるので注意しよう！
int main(){
    ll x;
    std::cin >> x;
    ll i=0;
    ll n=100;
    for(i=0;n<x;i++){
        n=n*1.01;
    }
    std::cout << i << std::endl;
}

Measured memory_bytes: 3624