akhauriyash/Code-Regression huggingface dataset:
n = int(input())
# Recursion!
def detector(str):
  # Stop the operation if the number is bigger than n.
  if int(str) > n:
    return 0
  else:
    count = 0
    # Add 7, 5, or 3 after the number. 
    # Eliminate numbers that do not consist of only 3, 5, and 7.
    for i in "753":
      count += detector(str+i)
    # Check if the number has all 3, 5, and 7.
    if "3" not in str or "5" not in str or "7" not in str:
      return count
    else:
      return count + 1
# Start from 0 and do the operation until the number exceeds n.
print(detector("0"))

Measured memory_bytes: 2940
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

long long cumuXor(long long A) {
  if(A == 0) return 0;

  int nbits = 0;
  long long nE = A+1;

  while(A != 0) {
    A /= 2;
    nbits++;
  }

  long long ans = 0;
  if((nE/2) % 2 != 0) ans = 1;

  for(int i = 1;i < nbits;i++) {
    long long x = nE & ((1LL << i)-1);
    if(x == 0) continue;

    long long y = nE & ((1LL << (i+1))-1);
    if(x == y) continue;

    if(x % 2 != 0) {
      ans |= (1LL << i);
    }
  }

  return ans;

}


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

  long long A, B;
  cin >> A >> B;
  if(A == 0) cout << cumuXor(B) << endl;
  else cout << (cumuXor(B)^cumuXor(A-1)) << endl;

  return 0;
}


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

using namespace std;

int main()
{
    int n, a, Su=10000000;
    cin >> n;
    int S[n+1];
    S[0] = 0;
    for (int i = 1; i <= n; i++)
    {
        cin >> a;
        S[i] = S[i-1] + a;
    }
    for (int i = 1; i < n; i++)
    {
        Su = min(Su, abs(S[i] - (S[n]-S[i])));
    }
    cout << Su;
    return 0;
}


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

using namespace std;

int main () {
    int n = 0;
    cin >> n;
    vector<long long> a(n);
    long long min = 1000000001;
    for (int i=0; i<n; i++) {
        cin >> a.at(i);
        if (a.at(i) < min) min = a.at(i);
    }
    bool flag = true;
    while (flag) {
        flag = false;
        long long mod = 0;
        for (long long x : a) {
            mod = x % min;
            if ((mod > 0) && (mod < min)) {
                min = mod;
                flag = true;
                break;
            }   
        }
    }
    cout << min << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
int32_t main()
{
    int n, m;
    cin>>n>>m;
    vector<int> s(n);
    vector<int> t(m);
    for(int i=0; i<n; i++) cin>>s[i];
    for(int i=0; i<m; i++) cin>>t[i];
    vector<vector<int> > dp(n+1, vector<int>(m+1, 1));
    // int dp[n+1][m+1];
    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++){
            // if(i == 0 || j == 0){ dp[i][j] = 1; continue; }
            if(s[i-1] == t[j-1])
                dp[i][j] = (dp[i-1][j] + dp[i][j-1])%mod;
                else
            dp[i][j] = (dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1] + mod) % mod;
            // if(s[i-1] == t[j-1])
            //     dp[i][j] = (dp[i][j]  +  1)%mod;
        }
    }
    cout<<dp[n][m];
}


Measured memory_bytes: 31616
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT    \
    cin.tie(0); \
    ios::sync_with_stdio(false);

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

ll const INF = 1LL << 60;
ll const MOD = 1000000007;

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

    ll ans = 0;
    ll start = 0;

    rep(i, SZ(s) - 2) {
        if (s[i] != 'A') start = i + 1;

        char c1 = s[i];
        char c2 = s[i + 1];
        char c3 = s[i + 2];

        if (c1 == 'A' && c2 == 'B' && c3 == 'C') {
            ans += i - start + 1;
            s[start] = 'B';
            s[start + 1] = 'C';

            ll cnt = 0;
            for (ll j = i + 2; j >= start + 2; j--) {
                s[j] = 'A';
                cnt++;
                if (cnt >= 3) break;
            }

            start += 2;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3768
#include <bits/stdc++.h>
#define MOD 1000000007

using namespace std;


int expo(int num, int n){
    if (n == 1) return num;
    if (n == 0) return 1;
    
    long long res = expo(num, n >> 1);
    res = (res * res) % MOD;
    if(n & 1)
        res = (res * num) % MOD;
        
    return res;

}

int inverse(int n){

    // calc a^(MOD-2)
    long long res = expo(n, MOD-2);
    
    return res;

}


int fact(int n){

    int x = 2;
    long long soma = 1;
    
    while(x <= n){
        soma = (soma * (x % MOD)) % MOD;
        x++;
    }
    
    return soma;
}

int aCb(int a, int b){

    int factA = fact(a);
    int factB = fact(b);
    int factAB = fact(a-b);
    long long invb = inverse(factB);
    long long invab = inverse(factAB);
    
    return (((factA * invb)%MOD) * invab) % MOD;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int x,y;
    cin >> x >> y;
    
    if((x+y) % 3 != 0){
        cout << 0 << endl;
        return 0;
    }
    
    int b = (2*y-x) / 3;
    int a = y - 2*b;
    
    if(a<0 || b<0){
        cout << 0 << endl;
        return 0;
    }
    
    cout << aCb(a+b, b) << endl;

    
}   

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

int main()
{
    int N, K;
    vector<int> h;
    vector<long long> cost;

    cin >> N >> K;
    h.resize(N);
    cost.resize(N);
    for (int i = 0; i < N; i++)
    {
        cin >> h[i];
        cost[i] = 1LL << 60;
    }

    cost[0] = 0;

    for (int i = 1; i < N; i++)
    {
        for (int j = 1; j <= K; j++){
            if(i-j >= 0){
                cost[i] = min(cost[i], cost[i - j] + abs(h[i] - h[i - j]));
            }
        }
    }

    cout << cost[N - 1] << endl;
}

Measured memory_bytes: 1408
#include<cstdio>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>
#include<deque>

using namespace std;
typedef long long int ll;

#define C cout<<
#define E <<endl

ll n,m,a,b,c,x,y,z,aa[200010],ab[200010];
bool r,ra,rb,rc;
string s,sa,sb,sc[100];
char ca,cb,cc,cd[1000][1000];
vector<ll> va,vb,vc;

void wi107(ll &nq){
    nq=nq%1000000007;
}

ll pow(ll target,ll repeat){
    ll result=1;
    for(int i=0;i<repeat;i++){
        result*=target;
        wi107(result);
        
    }
    return result;
}

int main(){
    cin>>n;
    
    for(int i=0;i<n;i++){
        cin>>aa[i];
        ab[aa[i]]++;
    }
    r=true;
    if(n%2)r=r and ab[0]==1;
    for(int i=(n%2 ? 2:1);i<n;i+=2){
        r=r and ab[i]==2;
    }
    
    if(r){
        C pow(2,n/2) E;
    }
    else{
        C 0 E;
    }
    
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#define PI acos(-1)
typedef long long ll;
typedef pair<int, int> pii;
#define INF 0x3f3f3f3f
const int N = 100010;
int mod = 1000000007;
pii rec[N];
bool vis[N];
int sum[N];
int main()
{
//	freopen("in.txt", "r", stdin);
	int n, m, d;
	while (~scanf("%d%d%d", &n, &m, &d))
	{
		memset(vis, 0, sizeof(vis));
		memset(sum, 0, sizeof(sum));
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < m; j++)
			{
				int x;
				scanf("%d", &x);
				rec[x] = pii(i, j);
			}
		}
		int all = n*m;
		for (int i = 1; i <= all; i++) if (!vis[i])
		{
			sum[i] = 0;
			for (int j = i + d; j <= all; j += d)
			{
				sum[j] = sum[j-d] + abs(rec[j-d].first - rec[j].first) 
					+ abs(rec[j-d].second - rec[j].second);
				vis[j] = true;
			}
		}
		int q;
		scanf("%d", &q);
		while (q--)
		{
			int l, r;
			scanf("%d%d", &l, &r);
			printf("%d\n", sum[r] - sum[l]);
		}
	}
   	return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1e9+7;
typedef pair<int, int> P;

vector<P> prime_factorize(int N){
	vector<P> ans;
	for(int a = 2; a*a <= N; a++){
		if(N%a == 0){
			int ex = 0;
			while(N%a == 0){
				ex++;
				N /= a;
			}
			ans.push_back(P(a, ex));
		}
	}
	if(N != 1) ans.push_back(P(N, 1));
	return ans;
}

signed main(){
    int N; cin >> N;
    vector<int> a(N); vector<P> num1(1000000), num, num2;
    for(int i = 0; i < N; i++){
        cin >> a[i];
        vector<P> vec = prime_factorize(a[i]);
        for(int i = 0; i < vec.size(); i++){
            num1[vec[i].first].second = max(num1[vec[i].first].second, vec[i].second); 
        }
    }
    for(int i = 0; i < 1000000; i++){
        if(num1[i].second != 0) num.push_back(P(i, num1[i].second));
    }
    for(int i = 0; i < num.size(); i++) num2.push_back((num[i]));

    int ans = 0;
    for(int i = 0; i < N; i++){
        vector<P> vec = prime_factorize(a[i]);
        for(int i = 0; i < vec.size(); i++){
            for(int j = 0; j < num.size(); j++){
                if(vec[i].first == num[j].first) num[j].second -= vec[i].second;
            }
        }
        int ans1 = 1;
        for(int i = 0; i < num.size(); i++){
            ans1 *= pow(num[i].first, num[i].second);
            ans1 %= MOD;
        }
        ans += ans1;
        ans %= MOD;
        for(int i = 0; i < num.size(); i++) num[i] = num2[i];
     }
    cout << ans << endl;
}

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

int main(){
	int n;
	cin>>n;
	int min=1000000,max=-1000000,x;
	long int sum=0;
	for(int i=0;i<n;i++){
		cin>>x;
		sum += x;
		min = min >= x ? x:min;
		max = max <= x ? x:max;
	}
	cout<<min<<" "<<max<<" "<<sum<<endl;
	return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <limits.h>
#include <cstring>
#include <tuple>
#include <cassert>
#include <numeric>
using namespace std;
// type alias
typedef long long LL;
typedef vector < int > VI;
typedef unordered_map < int, int > MAPII;
typedef unordered_set < int > SETI;
typedef pair< int , int > II;
typedef tuple< int, int, int > III;
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// minmax
#define SMAX(a,b) a = max(a,b)
#define SMIN(a,b) a = min(a,b)
// debug cerr
#define TRACE true
#define dump(x) if(TRACE) { cerr << #x << " = " << (x) << endl; }
#define dump2(x,y) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << endl; }
#define dump3(x,y,z) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl; }
#define dump4(x,y,z,a) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << ", " << #a << " = " << (a) << endl; }
#define dumpAR(ar) if(TRACE) { FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }

/*
 
 6/11/2018
 
 14:35-15:15 give up
 15:30-16:00 read editorials
 18:45-19:04 pause
 
 Editorials:
  - https://youtu.be/6ZP8JyGsQBs?t=1094
  - http://agc007.contest.atcoder.jp/data/agc/007/editorial.pdf
 
 Summary:
  - bucket or inversion... => bucket
 
 */

// $ g++ -std=c++11 -Wall -O2 -D_GLIBCXX_DEBUG x.cpp && ./a.out
// 14:35-15:15 give up
const int MAX_N=2e4+1;
int N;
LL P[MAX_N];
LL A[MAX_N],B[MAX_N];

LL BU=MAX_N+10;
void test() {
  int prev=-1e9;
  REP(i,N) {
    if(i>0) assert(A[i]>A[i-1]&&B[i]<B[i-1]);
    LL a=A[P[i]],b=B[P[i]],x=a+b;
    assert(1<=a&&a<=1e9);
    assert(1<=b&&b<=1e9);
    assert(prev<x);
    prev=x;
  }
}

void solve() {
  REP(i,N) A[i]=i*BU+1,B[N-i-1]=i*BU+1;
  REP(i,N) A[P[i]]+=i;
  /*
  int i,j,k,l,r,x,y; string s;
  
  REP(i,N) {
    A[i]=30000*(i+1);
    B[i]=30000*(N+1-i);
  }
  REP(i,N) {
    A[P[i]]+=i;
    B[P[i]]+=i;
  }*/
   
  test();
  REP(i,N) cout<<A[i]<<(i==(N-1)?"\n":" ");
  REP(i,N) cout<<B[i]<<(i==(N-1)?"\n":" ");
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  cin>>N;
  REP(i,N) {
    int x;
    cin>>x;
    --x;
    //P[x]=i;
    P[i]=x;
  }
    
  solve();
  return 0;
}


Measured memory_bytes: 1152
#!/usr/bin/env python

n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
ma = a[-1]

dup = [0 for _ in range(ma+1)]
div = [0 for _ in range(ma+1)]

for i in range(n):
    dup[a[i]] += 1
#print('dup =', dup)

for i in range(n):
    for j in range(a[i], ma+1, a[i]):
        div[j] += 1
#print('div =', div)

ans = 0 
for i in range(n):
    if div[a[i]] == 1:
        ans += 1
print(ans)


Measured memory_bytes: 35916
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    map<int, int> mp;
    ll res = 0;
    rep(i, N) {
        cin >> A[i];
        mp[A[i]]++;
        res += A[i];
    }
    int Q;
    cin >> Q;
    vector<int> B(Q), C(Q);
    rep(i, Q) {
        cin >> B[i] >> C[i];
        res -= mp[B[i]] * B[i] - mp[B[i]] * C[i];
        mp[C[i]] += mp[B[i]];
        mp[B[i]] = 0;
        cout << res << endl;
    }

    return 0;
}

Measured memory_bytes: 8796
#include <stdio.h>
#include <string.h>
char str[3000000];
int main(){
    scanf("%s",str);
    int l,r;
    int i;
    int rr;
    for(i=0;str[i] != '\0'; i++) {
        rr = i;
        if( str[i] == 'Z' ) r = i ;
    }
    for(i=rr; i>=0; i--){
        if(str[i] == 'A') l = i;
    }
    printf("%d\n",r - l + 1);
    return 0;
 
 
}

Measured memory_bytes: 512
#include <stdio.h>

int find_min(int a[], int start, int end)
{
    int min = a[start];
    for(int i=start; i<=end; i++){
        if(a[i] <= min)
            min = a[i];
    }
    return min;
}

int find_max(int a[], int start, int end)
{
    int max = a[start];
    for(int i=start; i<=end; i++){
        if(a[i] >= max)
            max = a[i];
    }
    return max;
}

int max_of(int a, int b){
    return (a>=b) ? a:b;
}

int min_of(int a, int b){
    return (a<=b) ? a:b;
}

int find_max_diff(int a[], int start, int end, int left_min[], int right_max[])
{
    int i,j;
    int max = -1000000000;
    if((end - start) == 2){
        max = max_of(max_of(a[end-1]-a[end-2], a[end]-a[end-2]), a[end]-a[end-1]);
        left_min[end] = find_min(a, start, end);
        right_max[end] = find_max(a, start, end);
        return max;
    }
    else if((end-start)==1){
        if((a[end]-a[start]) <= 0){
            left_min[end] = a[end]; 
            right_max[end] = a[start];
        }
        else{
            left_min[end] = a[start]; 
            right_max[end] = a[end];
        }
        return a[end] - a[start];
    }
    else{
        int mid = (start+end)/2;
        int left_diff = find_max_diff(a, start, mid, left_min, right_max);
        int right_diff = find_max_diff(a, mid+1, end, left_min, right_max);
        int all_diff = right_max[end] - left_min[mid];
        right_max[end] = max_of(right_max[mid], right_max[end]);
        left_min[end] = min_of(left_min[mid], left_min[end]);
        return max_of(max_of(left_diff, right_diff), all_diff);
    }
}

int main(){
    
    int data_num, arr[250000];
    scanf("%d", &data_num);
    
    for(int i=0; i<data_num; i++){
        scanf("%d", &arr[i]);
    }

    int left_min[250000], right_max[250000];
    int ans = find_max_diff(arr, 0, data_num-1, left_min, right_max);
    printf("%d\n", ans);
}



Measured memory_bytes: 4128
#include<bits/stdc++.h>
    #include<iostream>
    using namespace std;
    int main()
    {
    	string s;
    	cin>>s;
    	int c1=0,c2=0,c3=0;
     
    	for(int i=0;i<2;i++)
    	{
    		if(s[i]=='R' && s[i+1]=='R')
    		{
    			c1++;
    		}
    	}
    		for(int i=0;i<3;i++)
    	{
    		 if(s[i]=='R')
    		{
    			c2++;
    			break;
    			
    		}
    		else
    		{
    			c3++;
    		}
    	}
    	
    	if(c1==1)
    	{
    		cout<<c1+1<<endl;
    	}
    	else if(c1==2)
    	{
    		cout<<c1+1<<endl;
    	}
    		else if(c2==1)
    	{
    		cout<<c2<<endl;
    	}
    	else
    	{
    			cout<<"0"<<endl;
    	}
    	return 0;
    }

Measured memory_bytes: 3624
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int main()
{
    string s1,t,s;
    while(cin >> s1 >> t)
    {
        int a[55]= {0};
        int b[55]= {0};
        int len1=s1.size();
        int len2=t.size();
        if(len2>len1)
        {
            cout << "UNRESTORABLE" << endl;
            continue;
        }
        for(int i=0; i<len1-len2+1; i++)
        {
            int flag=1;
            for(int j=0; j<len2; j++)
            {
                if(s1[i+j]!=t[j]&&s1[i+j]!='?')
                {
                    flag=0;
                    break;
                }
                if(s1[i+j]=='?'&&t[j]!='a')
                    flag=2;
                else if(s[i+j]=='?'&&t[j]=='a'&&flag==1)
                    flag=3;
            }
            if(flag==1)
                a[i]=1;
            else if(flag==0)
                a[i]=2;
            else if(flag==2)
                a[i]=3;
            else
                a[i]=4;
        }
        for(int i=0; i<len1-len2+1; i++)
            b[i]=a[i];
        sort(b,b+len1-len2+1);
        if(b[0]==1)
        {
            for(int i=0; i<len1; i++)
            {
                if(s1[i]!='?')
                    cout << s1[i];
                if(s1[i]=='?')
                    cout << 'a';
            }
            cout << endl;
        }
        else if(b[len1-len2]==3)
        {
            int i;
            for(i=len1-len2; i>=0; i--)
                if(a[i]==3)
                    break;
            for(int j=0; j<i; j++)
            {
                if(s1[j]!='?')
                    cout << s1[j];
                if(s1[j]=='?')
                    cout << 'a';
            }
            cout << t;
            for(int j=i+len2; j<len1; j++)
            {
                if(s1[j]!='?')
                    cout << s1[j];
                if(s1[j]=='?')
                    cout << 'a';
            }
            cout << endl;
        }
        else if(b[len1-len2]==4)
        {
            int i;
            for(i=len1-len2; i>=0; i--)
                if(a[i]==4)
                    break;
            for(int j=0; j<i; j++)
            {
                if(s1[j]!='?')
                    cout << s1[j];
                if(s1[j]=='?')
                    cout << 'a';
            }
            cout << t;
            for(int j=i+len2; j<len1; j++)
            {
                if(s1[j]!='?')
                    cout << s1[j];
                if(s1[j]=='?')
                    cout << 'a';
            }
            cout << endl;
        }
        else
            cout << "UNRESTORABLE" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
//! 尺卂乃卂.卂ﾌ乇乇ㄒ
#include<bits/stdc++.h>
//#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
//Using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> Ordered_set;

#define ll              long long
#define int             long long
#define ld             long double
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define vii             vector<vi>
#define vip            vector<pii>
#define mii             map<int,int>
#define mip             map<pair<int,int>,int>
#define mic             map<char,int> 
#define all(v)          v.begin(),v.end()  
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define lb(x)           (x&(-x))
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define itr(it,v)          for(auto it:v)
#define show(arr,n)     for(int i=0;i<n;i++) cout<<arr[i]<<" "; cout<<"\n";
#define fi(i,n)         for(int i=0;i<n;i++)
#define fir(i,k,n)       for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ff               first 
#define ss               second
#define deb(x) cout << #x << "=" << x << endl
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define check(x) (x && cout<<"Yes\n")||(cout<<"No\n");
#define fin(s)          freopen(s,"r",stdin);  
#define fout(s)         freopen(s,"w",stdout);

const ld pi = 3.141592653589793238462643383279502884;
const int xd[]={-1,0,1,0};
const int yd[]={0,-1,0,1};
int XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[] = { -1, 0,  1, -1, 1, -1, 0, 1 };

int expo(int a,int b,int m);
int mmi(int a,int m);
void ipgraph(int m);

const int N=5*(1e5)+10;
vii adj(N);
int a[N];

void  solve(){

}
int32_t main()
{
    FIO
    int n; cin>>n;
    cout<<n+(n*n)+(n*n*n)<<"\n";
    return 0;

}

void ipgraph(int m){
    int i, u, v;
    while(m--){
          cin>>u>>v;
         u--, v--;
    adj[u].pb(v);
    adj[v].pb(u);
    }
}
int expo(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return a;
    int val=(expo(a,b/2,m)*expo(a,b/2,m))%m;
    if(b & 1) return (val*a)%m;
    else return val;
}
int mmi(int a,int m){
    return expo(a,m-2,m);
}


Measured memory_bytes: 15048
def main():
	H, W = map(int, input().split())
	a = [["." for _ in range(W)] for _ in range(H)]
	ans = []
	is_column_white = [True]*H
	is_row_white = [True]*W
	for i in range(H):
		row = input()
		for j in range(W):
			a[i][j] = row[j]
			if row[j] == "#":
				is_column_white[i]=False
				is_row_white[j] = False

	for i in range(H):
		if is_column_white[i]:
			continue
		ans_row = ""
		for j in range(W):
			if is_row_white[j]:
				continue
			ans_row += a[i][j]
		print(ans_row)

if __name__ == '__main__':
    main()

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  ll X; cin >> X;
  ll a = 100; int ans = 0;
  while(a < X) {
    a += a / 100;
    ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int n,a;
	cin >> n >> a;
	cout << n*n - a <<endl;
	return 0;
}

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

class SCC {
private:
  const int N;
  vector<vector<int>> G;
  vector<vector<int>> R;
  vector<int> ord, low;
  stack<int> st;
  void dfs(const int u, int &tm) {
    ord.at(u) = low.at(u) = tm++, st.push(u);
    for (int v : G.at(u)) {
      if (ord.at(v) < 0) {
        dfs(v, tm);
        low.at(u) = min(low.at(u), low.at(v));
      } else if (cmp.at(v) < 0) {
        low.at(u) = min(low.at(u), ord.at(v));
      }
    }
    if (ord.at(u) == low.at(u)) {
      R.push_back(vector<int>{});
      while (true) {
        const int v = st.top();
        st.pop();
        cmp.at(v) = cnt;
        R.back().push_back(v);
        if (v == u) break;
      }
      cnt++;
    }
  }

public:
  vector<vector<int>> graph;
  vector<int> cmp;
  int cnt;
  SCC(const int n) : N(n), G(n), ord(n, -1), low(n), cmp(n, -1), cnt(0) {}
  void add(const int from, const int to) { G.at(from).push_back(to); }
  vector<vector<int>> solve() {
    int tm = 0;
    for (int i = 0; i < N; i++) {
      if (ord.at(i) < 0) dfs(i, tm);
    }
    for (int i = 0; i < N; i++) cmp.at(i) = cnt - 1 - cmp.at(i);
    reverse(R.begin(), R.end());
    return R;
  }
  vector<vector<int>> build() {
    graph.resize(cnt);
    for (int i = 0; i < N; i++) {
      for (int j : G.at(i)) {
        if (cmp.at(i) != cmp.at(j)) {
          graph.at(cmp.at(i)).push_back(cmp.at(j));
        }
      }
    }
    return graph;
  }
};

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

  int N, M;
  cin >> N >> M;
  SCC SC(N);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    SC.add(a, b);
  }

  auto G = SC.solve();
  cout << G.size() << "\n";
  for (int i = 0, h = G.size(); i < h; i++) {
    cout << G.at(i).size();
    for (int j = 0, w = G.at(i).size(); j < w; j++) {
      cout << " " << G.at(i).at(j);
    }
    cout << "\n";
  }
}

Measured memory_bytes: 87232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
int main(){
  int A,B;
  cin>>A>>B;
  if(A<B){
    cout << 0 << endl;
  }
  else{
    cout << 10 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
/* HARE KRSNA HARE KRSNA KRSNA KRSNA HARE HARE
    HARE RAMA HARE RAMA RAMA RAMA HARE HARE  */

#include <bits/stdc++.h>
using namespace std;

#define nl "\n"
#define ff first
#define ss second
#define pp pop_back
#define pf pop_front
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define b_s binary_search
#define all(x) x.begin(),x.end()
#define test ll t; cin>>t; while(t--)
#define loop(i,s,n) for(ll i=s;i<n;i++)
#define rloop(i,s,n) for(ll i=s;i>=n;i--)
#define fill(a,value) memset(a,value,sizeof(a))

#define debug2(a)  for(auto x : a)  cout<<x<<" ";  cout<<nl;
#define debug4(a)  for(auto x : a)  cout<<x.ff<<" "<<x.ss<<nl;
#define debug1(a,n) loop(i,0,n)  cout<<a[i]<<" ";  cout<<nl;
#define debug3(a,n,m)  loop(i,0,n){ loop(j,0,m)	cout<<a[i][j]<<" ";	cout<<nl; }

typedef long long ll;
typedef long double ld;

typedef stack<ll> sll;
typedef queue<ll> qll;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<string> vs;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef pair<ll, pll> ppll;
typedef vector<vector<ll>> vvll;
typedef priority_queue<ll> pqll;

const ll mod = 998244353; //1000000007;
const ld pi =  acos((ld) - 1);	//3.1415926535;

ll num_generator() 		{   return rand() % 1000;	}
void array_generator(ll a[], ll n)
{  loop(i, 0, n)	a[i] = rand() % 100;  }

void solve()
{
	ll l, r, d;	cin >> l >> r >> d;
	ll cnt = 0;
	loop(i, l, r + 1)	if (i % d == 0)		cnt++;
	cout << cnt << nl;
}

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

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	// test
	solve();

	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define pii pair <int, int>
#define fi first
#define sc second
#define ALL(x) x.begin(), x.end()
#define RALL(X) x.begin(), x.end()
#define FOR(i, n, k) for(i=0; i<n; i+=k)
#define FO(i, n, k) for(i=1; i<=n; i+=k)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define N 100005
#define mid ((l+r)/2)
#define dbg(x) (cerr << #x << " : " << x << endl)
#define endl "\n"
#define MOD 100000009
#define gcd __gcd

using namespace std;

typedef long long int lli;

int main(){
	ios_base::sync_with_stdio(false);
	lli a, b, c, d;
	cin >> a >> b >> c >> d;

	lli range = b-a+1;

	// first handle c
	lli l =  a + c - (a % c ? a % c : c);
	lli r = b - (b % c);
	lli ran = (r - l)/c + 1;
	range -= ran;
	

	l =  a + d - (a % d ? a % d : d);
	r = b - (b % d);
	ran = (r - l)/d + 1;
	range -= ran;

	lli lcm = c*d/gcd(c,d);
	l =  a + lcm - (a % lcm ? a % lcm : lcm);
	r = b - (b % lcm);
	ran = (r - l)/lcm + 1;
	range += ran;

	cout << range;

	return 0;
}

Measured memory_bytes: 256
from functools import lru_cache
from itertools import product

# 入力
N = int(input())

# 3文字のACGT文字列のリスト
T = [''.join(t) for t in product(('A', 'C', 'G', 'T'), repeat=3)]


# ACGT文字列が問題の条件にマッチするならば真となる述語
@lru_cache(maxsize=None)
def p(s):
    return all(
        'AGC' not in s[:i] + s[i + 1:i + 2] + s[i] + s[i + 2:]
        for i in range(len(s))
    )


# 長さがi、かつ、末尾3文字がs、かつ、問題の条件にマッチする文字列の個数を返す
@lru_cache(maxsize=None)
def f(i, s):
    return (
        0 if i == 3 and not p(s) else
        1 if i == 3 and p(s) else
        sum(f(i - 1, t) for t in T if t[1:] == s[:2] and p(t + s[-1]))
    )


# 解は、すべての長さ3のACGT文字列tに対して、f(N, t) の和である。
ans = sum(f(N, t) for t in T) % (10**9 + 7)

# 出力
print(ans)


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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(_v) for(auto _x:_v){cout<<_x<<" ";}cout<<endl
#define printVS(vs) for(auto x : vs){cout << x << endl;}
#define printVV(_vv) for(auto _v:_vv){for(auto _x:_v){cout<<_x<<" ";}cout<<endl;}
#define printP(p) cout << p.first << " " << p.second << endl
#define printVP(vp) for(auto p : vp) printP(p);
#define readV(_v) rep(j, _v.size()) cin >> _v[j];
#define readVV(_vv) rep(i, _vv.size()) readV(_vv[i]);
#define output(_x) cout << _x << endl;

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;

int fact(int x) {
    if (x == 0) return 1;
    return x * fact(x - 1);
}

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

    int n;
    while (cin >> n, n) {
        vector<string> s(n);
        rep(i, n) cin >> s[i];

        map<char, int> mp;
        rep(i, n) {
            for (auto c : s[i]) {
                mp[c] = 0;
            }
        }

        int kind = 0;
        for (auto& p : mp) {
            p.second = kind++;
        }

        vector<bool> nonZero(kind);
        rep(i, n) {
            if (s[i].size() > 1) nonZero[mp[s[i][0]]] = true;
        }

        vi coef(kind);
        rep(i, n) {
            rep(j, s[i].size()) {
                coef[mp[s[i][j]]] += (i == n - 1 ? -1 : +1) * pow(10, (int)s[i].size() - j - 1);
            }
        }

        int ans = 0;
        vi perm(10); // kind to digit
        iota(all(perm), 0);
        do {
            int t = 0;
            bool flag = true;
            rep(i, kind) {
                if (nonZero[i] && perm[i] == 0) {
                    flag = false;
                    break;
                }
                t += coef[i] * perm[i];
            }
            if (flag && t == 0) {
                ans++;
            }
        } while (next_permutation(all(perm)));

        cout << ans / fact(10 - kind) << endl;
    }
}

Measured memory_bytes: 3364
#include <stdio.h>

int main(void){
    int n,n1,n2,change;

    if(((scanf("%d",&n))!=1)||((n<0 || 10000<n))) {return -1;}

    if(n%1000 == 0) {printf("0");}
    else{
        n1 = n / 1000;
        n2 = (n1+1)*1000;
        change = n2 - n;
        printf("%d",change);
    }
return 0;
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int tx[]={0,0,1,-1};
const int ty[]={1,-1,0,0};
int getd(int a,int b,int x,int y){
	return abs(a-x)+abs(b-y);
}
char getc(int &a,int &b,int d,int x,int y){
	int Mn=2e9,op=-1;
	for (int i=0;i<4;i++){
		int xx=a+tx[i]*d,yy=b+ty[i]*d;
		int dis=getd(xx,yy,x,y);
		if (dis<Mn) {Mn=dis; op=i;}
	}
	a=a+tx[op]*d; b=b+ty[op]*d;
	if (op==0) return 'U';
	if (op==1) return 'D';
	if (op==2) return 'R';
	return 'L';
}
int x[1111],y[1111],d[222],cnt[2],m;
signed main(){
	int T; scanf("%lld",&T);
	for (int i=1;i<=T;i++){
		scanf("%lld%lld",&x[i],&y[i]);
		cnt[(x[i]+y[i])%2]++;
	}
	if (cnt[1]&& cnt[0]) return puts("-1"),0;
	for (int i=0;i<=30;i++) d[i+1]=1<<(30-i);
	if (cnt[0]) d[32]=1,m=32; else m=31;
	printf("%lld\n",m);
	for (int i=1;i<=m;i++) printf("%lld ",d[i]); puts("");
	for (int i=1;i<=T;i++){
		int a=0,b=0;
		for (int j=1;j<=m;j++)
			putchar(getc(a,b,d[j],x[i],y[i]));
		puts("");
	}
	return 0;
}
	

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

bool prime(int x)
{
	for(int i=2;i*i<=x;i++)
		if(x%i==0)
			return false;
	return true;
}

int main()
{
	int n,ans=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int t;
		scanf("%d",&t);
		if(prime(t)) ans++;
	}
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;

typedef long long ll;

const int MAXN = 200005;

struct State
{
	int a, b;	
	
	State() {}
	State(int a, int b) : a(a), b(b) {}
};

bool operator <(const State &x, const State &y)
{
	return x.a < y.a;	
}

int A[MAXN], B[MAXN];

priority_queue<State> pq;

vector<State> S;

ll sum = 0, res = 0;

int n;

void check()
{
	bool ch = 1;	
	for (int i = 1; i <= n; i++)
		ch &= (A[i] == B[i]);
	if (ch)
	{
		cout << 0 << endl;
		exit(0);	
	}
}

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> A[i] >> B[i];
	check();
	for (int i = 1; i <= n; i++)
	{
		if (A[i] <= B[i])
			res += A[i], sum += B[i] - A[i];
		else
			S.push_back(State(B[i], A[i] - B[i]));
	}
	sort(S.begin(), S.end());
	int sz = S.size();
	for (int i = 1; i < sz; i++)
	{
		res += S[i].a + S[i].b;
		sum -= S[i].b;
	}
	res += sum;
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
constexpr int MOD = 1000000007;
int main()
{
    int X;
    cin >> X;
    FOR(i, 1, 1001) {
        if(i*100 <= X && X <= i*105) {
            cout << 1 << endl;
            return 0;
        }
    }
    cout << 0 << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(n):
    b.append([a[i], i])
b = sorted(b, key=lambda x: x[0], reverse=False)
for i in range(n):
    if i<n//2:
        b[i].append(b[n//2][0])
    else:
        b[i].append(b[n//2-1][0])
b = sorted(b, key=lambda x: x[1], reverse=False)
for i in range(n):
    print(b[i][2])


Measured memory_bytes: 51392
i=[int(i) for i in input().split()]
n=i[0]
x=i[1]
L=[int(i) for i in input().split()]

sum=0
res=0
for step in range(n):
    if sum<=x:
        res+=1
        sum+=L[step]
    else:
        break
    
if sum<=x:
    res+=1

print(res)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P std::pair<int,int>
#define PiP std::pair<int,std::pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp std::make_pair
#define prique(T) std::priority_queue<T,vector<T>,greater<T>>
using namespace std;
template<class T> inline void chmax(T &a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T &a, T b) {
	a = std::min(a, b);
}

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)
			return false;
	}
	return x != 1;
}
int gcd(int x, int y) {
	if (y == 0)
		return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i;
		res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)
		return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod ;
}
int get_rand(int MIN, int MAX) {
	std::random_device rnd;
	std::mt19937 mt32(rnd());
	std::uniform_int_distribution<int> engine(MIN, MAX);
	return engine(mt32);
}
/*--------Library Zone!--------*/

signed main() {
	int n;
	cin>>n;
	if(n%2)cout<<0<<endl;
	else {
		int ans=0;
		while(n){
			ans+=n/10;
			n/=5;
		}
		cout<<ans<<endl;
	}
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{
	long long n;

	scanf("%lld", &n);

	if (n % 2)
	{
		printf("0\n");
	}

	else
	{
		long long temp;
		long long sol = 0;

		temp = n;

		while (temp)
		{
			sol += temp / 10;

			temp /= 5;
		}

		printf("%lld\n", sol);
	}

	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
ll A[100000];
int main( void )
{
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  for( int i=0; i<N; i++ ){
    cin >> A[i];
  }
  sort( A, A+N );
  ll s = 0;
  int ret = 0;
  for( int i=0; i<N; i++ ){
    if( s*2 < A[i] ){
      ret = 1;
    } else {
      ret++;
    }
    s += A[i];
  }
  cout << ret << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n); for(int i = 0;i < (n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
long double pi = acos(-1);
const int INF = 1001001001;
const int N_MAX = 100001;
const int modint = 1000000007;

// 最小公倍数を求める
int euqlid (int a, int b){
  int temp;
  temp = a % b;
  if(temp == 0)return b;
  return euqlid(b,temp);
}
ll conbination(ll a,ll b){
  ll u = 1;
  ll d = 1;
  while(b != 0){
    u *= a;
    d *= b;
    a--;
    b--;
  }
  return u / d;
}
int strtoint(char s){
  return (int(s-'0'));
}
char changeS(char alpha){
  if(0x41 <= alpha and alpha <= 0x5A)return (alpha + 0x20);
  else if(0x61 <= alpha and alpha <= 0x7A)return (alpha - 0x20);
  return alpha;
}
int fact(int n){
  if(n == 1)return 1;
  return n * fact(n-1);
  }


int main() {
  string n;
  cin >> n;
  int ans  = 0;
  rep(i,n.length()){
    ans += strtoint(n[i]);
  }
  if(ans % 9 == 0){
    cout << "Yes"<<endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3740
data = input().split()

k, n = int(data[0]), int(data[1])
data = input().split()
tab = []
for i in range(n):
    tab.append(int(data[i]))
tab.append(k + tab[0])
biggest = 0
for i in range(1, n+1):
    if (tab[i] - tab[i-1] > biggest):
        biggest = tab[i] - tab[i-1]


print(k - biggest)



Measured memory_bytes: 26444
#include <bits/stdc++.h>
using namespace std;
int dp[1010][8];
int main()
{
    const int mod=10007;
    int n;
    string s; 
    cin>>n>>s;
    int a[128]; a['J']=1, a['O']=2, a['I']=4;
    dp[0][1]=1;
    for(int i=0;i<n;++i) {
        for(int j=0;j<8;++j) if (a[s[i]]&j)
            for(int k=0;k<8;++k) if (j&k)
                (dp[i+1][j]+=dp[i][k])%=mod;
    }
    int res=0;
    for(int i=0;i<8;++i) (res+=dp[n][i])%=mod;
    cout<<res<<endl;
}

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

int n,a[205],L,R,now;
ll cnt;

inline void solve(){
	int i=40; L=101,R=L-1;
	for(;!((1ll<<i)&cnt);i--);
	for(i--;i>=0;i--){
		a[++R]=++now;
		if((1ll<<i)&cnt) a[--L]=++now;
	}
	
	n=R-L+1;
	for(int i=1;i<=n;i++) a[i]=a[i+L-1];
	for(int i=n+1;i<=n*2;i++) a[i]=i-n;
	n<<=1;
}

int main(){
	scanf("%lld",&cnt),cnt++;
	solve(),printf("%d\n",n);
	for(int i=1;i<=n;i++) printf("%d ",a[i]);
	puts("");
	return 0; 
}

Measured memory_bytes: 256
H, W = gets.split.map(&:to_i)
board = H.times.map { gets.chomp.chars.take(W) }
board = board.reject { |row| row.all? { |c| c == '.'} }
board = board.transpose.reject { |row| row.all? { |c| c == '.'} }
ans = board.transpose.map { |row| row.join('') }.join("\n")
puts ans


Measured memory_bytes: 4476
#include <iostream> 
#include <cstdio>
#include <cstring> 
#include <cmath>
using namespace std;

int a[2010];

int main() {
	int n, z, w; cin >> n >> z >> w;
	for (int i = 0; i < n; i ++) cin >> a[i];
	int answer = 0;
//	for (int i = 0; i < n; i ++) {
//		int x = 0, y = -1;
//		x = a[i];
//		for (int j = i+1; j < n; j ++)
//			if (y == -1) y = a[j];
//			else if (abs(x - a[j]) < abs(x - y)) y = a[j];
//		if (y == -1) y = w;
//		if (abs(x - y) > answer) answer = abs(x - y);
//	}
	if (n > 1)
		answer = max(abs(a[n-1]-w), abs(a[n-1]-a[n-2]));
	else 
		answer = abs(a[0]-w);
	cout << answer << endl;
	return 0;
}

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


int main() {
    int n;
    cin >> n;
    vector<ll> a(n),b(n);
    rep(i,n) {
        cin >> a[i];
        ++b[a[i]-1];
    }
    ll ans=0;
    rep(i,n) {
        ans+=b[i]*(b[i]-1)/2;
    }
    rep(i,n) {
        ll tans=ans-b[a[i]-1]*(b[a[i]-1]-1)/2+(b[a[i]-1]-1)*(b[a[i]-1]-2)/2;
        cout << tans << endl;
    }
}

Measured memory_bytes: 5760
import numpy as np
from scipy.sparse import csr_matrix
s = np.array(list(input()), dtype='U1')
n = len(s)
child = np.ones(n, dtype=np.int32)
rows = np.arange(n)
cols = np.where(s == 'R', rows+1, rows-1)
x = csr_matrix((np.ones(n, dtype=np.int32), (rows, cols)), (n, n))


def power(x, n):
    if n == 1:
        return x
    y = power(x, n//2)
    y = y*y
    return x*y if n & 1 else y


x = power(x, 10**100)
print(*(child*x))

Measured memory_bytes: 23344
import java.util.HashMap;
import java.util.Scanner;




public class Main {
    //static int a=new int[100005];
    static int [] vis=new int[105];
   // static Long [] dp=new Long[505];

    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        String s=in.next();
        
        int n=in.nextInt();
        int x;
        for(int i=0;i<=9;i++)
        	vis[i]=0;
        for(int i=1;i<=n;i++)
        {
        	x=in.nextInt();
        	vis[x]++;
        }
        int min=1;
        for(int j=1;j<=9;j++)
		{
			if(vis[j]==0)
			{
				min=j;
				break;
			}
		}
        String ans="";
        int flag=0;
        int fflag=0;
        for(int i=0;i<s.length();i++)
        {
        	if(flag==0)
        	{
        		x=Integer.parseInt(s.charAt(i)+"");
        		if(vis[x]==0) 
        		{
        			ans+=s.charAt(i);
        			continue;
        		}
        		int flag1=0;
        		for(int j=x+1;j<=9;j++)
        		{
        			if(vis[j]==0)
        			{
        				ans+=String.valueOf(j);
        				flag1=1;
        				break;
        			}
        		}
                if(flag1==0)
                {
                	
                		//System.out.println("ss:"+ans);
                		while(true)
                		{
                			if(ans=="")
                        	{
                        		ans+=String.valueOf(min);
                        		fflag=1;
                        		break;
                        	}
                			
                			int temp=Integer.parseInt(ans);
                			int weizhi=temp%10;
                			if(temp/10==0)
                				ans="";
                			else
                    		ans=String.valueOf(temp/10);
               
                    		int flag2=0;
                    		for(int j=weizhi+1;j<=9;j++)
                    		{
                    			if(vis[j]==0)
                    			{
                    				ans+=String.valueOf(j);
                    				flag2=1;
                    				break;
                    			}
                    		}
                    		if(flag2==1) 
                    		{
                    	     break;
                    		}
                		}
                }
        		break;
        	}
        	
        	
        }
        int min1=0;
        for(int j=0;j<=9;j++)
		{
			if(vis[j]==0)
			{
				min1=j;
				break;
			}
		}
        int pos=ans.length();
        if(fflag==0)
        {
        	
        	for(int i=pos;i<s.length();i++)
        		ans+=String.valueOf(min1);
        }
        else
        {
        	for(int i=pos;i<=s.length();i++)
        		ans+=String.valueOf(min1);
        }
        	
      
        System.out.println(Integer.parseInt(ans));
         
         System.gc();
     }
 }


Measured memory_bytes: 35412
//#include <tourist>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
struct edge {
    int to, cost;
};
int n;
vector<vector<ll> > a(16);
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        for(int j=0;j<n;j++){
        ll tempa;
        cin >> tempa;
        a[i].push_back(tempa);
        }
    }
    vector<ll> g((1<<16)+1,0);//bitが立ってる物を一つのグループにしたときの点
    for(int i=0;i<(1<<n);i++){
        for(int j=0;j<n-1;j++){
            for(int k=j+1;k<n;k++){
                if(!(i&1<<j))continue;
                if(!(i&1<<k))continue;
                g[i]+=a[j][k];
            }
        }
    }
    vector<ll> dp(1<<16,0);
    //O(16*2^16)
    for(int i=0;i<(1<<n);i++){
        //(j-1)&iはjの下からbitが立つまで繰り下がりする->下から一つbitが立たなくなる
        ll m=0;
        for(int j=i;j>0;j=(j-1)&i){
            m=max(m,dp[i-j]+g[j]);
            //集合jを1グループにする
        }
        dp[i]=max(dp[i],m);
    }
    cout << dp[(1<<n)-1] << "\n";
}

//bitDPで各状態について部分集合について更新を行うやり方はO(3^N)で行う方法がある。->知らない

Measured memory_bytes: 1408