akhauriyash/Code-Regression huggingface dataset:
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    ls = collections.deque()
    for i, v in enumerate(a):
        if i % 2 == n % 2:
            ls.append(v)
        else:
            ls.appendleft(v)
    print(*ls)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 91216
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int N;
vector<int>h;
int memo[100010];
bool vis[100010];
int sol(int pos){
  if(pos>=N-1)return 0;
  if(vis[pos])return memo[pos];
  vis[pos]=1;
  return memo[pos]=min(sol(pos+1)+abs(h[pos]-h[pos+1]),sol(pos+2)+abs(h[pos]-h[pos+2]));
}
int main(){
		ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
		//freopen("input.txt","r",stdin);
		//freopen("output.txt","w",stdout);
    cin>>N;
    for(int i=0;i<N;i++){
      int a;
      cin>>a;
      h.push_back(a);
    }
    h.push_back(h.back());
    h.push_back(h.back());
    cout<<sol(0);
    return 0;
}

Measured memory_bytes: 5112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
const ll mo = 1000000007;
const ll INF = 1LL << 60; //MAX 9223372036854775807
ll ans = 0;

int main()
{
ll a,b;
cin >> a>>b;
if(a<=5)ans=0;
else if(a<=12)ans=b/2;
else ans=b;
cout << ans << endl;
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

constexpr int P = 998244353;

struct SegmentTree {
    struct Node {
        Node operator*(const Node& o) const {
            return { max(v, o.v) };
        }
        int v;
    };
    SegmentTree(int n) : e({ -1 }), n(n) {
        for (m = 2; m < n; m *= 2);
        t = vector<Node>(m + n + n % 2, e);
    }
    Node& operator[](int i) {
        return t[m + i];
    }
    const Node& root() const {
        return t[1];
    }
    void build() {
        for (int i = (n - 1 + m) / 2; i > 0; i--) t[i] = t[i * 2] * t[i * 2 + 1];
    }
    void update(int i, const Node& o) {
        for (t[i += m] = o; i /= 2, i > 0;) t[i] = t[i * 2] * t[i * 2 + 1];
    }
    Node query(int l, int r) {
        Node o[2] = { e, e };
        for (l += m, r += m; l < r; l /= 2, r /= 2) {
            if (r & 1) o[1] = t[--r] * o[1];
            if (l & 1) o[0] = o[0] * t[l++];
        }
        return o[0] * o[1];
    }
    void print() {
        for (int j = 1; j <= m; j *= 2) {
            int k = min(j * 2, m + n);
            for (int i = j; i < k; i++) {
                cout << t[i].v << " \n"[i == k - 1];
            }
        }
    }
    vector<Node> t;
    const Node e;
    int n, m;
};

struct R {
    bool operator<(const R& r) const {
        return x < r.x;
    }
    int x, d;
};

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

    int n;
    cin >> n;

    vector<R> r(n);
    for (int i = 0; i < n; i++) {
        int x, d;
        cin >> x >> d;
        r[i] = { x, d };
    }
    sort(r.begin(), r.end());

    SegmentTree st(n);
    vector<int> dp(n + 1);
    dp[n] = 1;

    for (int i = n - 1; i >= 0; i--) {
        int j = lower_bound(r.begin() + i + 1, r.end(), R{ r[i].x + r[i].d , 0 }) - r.begin();
        st.update(i, { j = max(j, st.query(i + 1, j).v) });
        dp[i] = dp[j] + dp[i + 1];
        if (dp[i] >= P) dp[i] -= P;
    }

    cout << dp[0] << endl;

    return 0;
}

Measured memory_bytes: 4480
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file  
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional> // for less  
using namespace         std;
#define                 int long long
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<'\n'
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)
#define all(x)          x.begin() , x.end()
#define pi pair<int,int>
#define X first
#define Y second
#define N 3009
#define  vi vector<int>
#define  v  vector
#define die exit(0)
#define alln(arr) arr+1 , arr+1+n
using namespace __gnu_pbds;  
typedef tree<int, null_type, less<int>, rb_tree_tag,  
            tree_order_statistics_node_update> oset; 

// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).

#define in input_int()
#define ins input_string()
int input_int(){int a;cin>>a;return a;}
string input_string(){string s;cin>>s;return s;}
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};



int n,m,k,a,b,c,d,x,y,arr[N][N];
string s;

int dp[N][N][4];


int get(int i,int j,int taken)
{
    if(i>n or j>m)return 0;
    int&ans=dp[i][j][taken];
    if(ans!=-1)return ans;
    ans=0;
    if(taken<3)
    {
        ans=max(ans,arr[i][j]+get(i,j+1,taken+1));
        ans=max(ans,get(i,j+1,taken));
        ans=max(ans,get(i+1,j,0));
        ans=max(ans,arr[i][j]+get(i+1,j,0));
    }
    else
    {
        ans=max(ans,get(i,j+1,taken));
        ans=max(ans,get(i+1,j,0));
    }
    return ans;

}


void solve()
{
    cin>>n>>m>>k;
    forn(i,1,k)
    {
        int a,b,c;
        cin>>a>>b>>c;
        arr[a][b]=c;
    }
    st(dp,-1);
    cout<<get(1,1,0);
}


signed main() 
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
    int t = 1;
    //cin>>t;
    forn(i,1,t)
    {
        solve();
        nl;
    }



    return 0;

}
//       clang++ c.cpp ; ./a.out < a.txt ;  

Measured memory_bytes: 357528
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define reppe(i,a,b) for(int i = (int)(a) ; i <= (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repme(i,a,b) for(int i = (int)(a) ; i >= (int)(b) ; --i)

typedef long long ll;

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

int main() {
    int N; cin >> N;
    vector<ll> L(N); repp(i, 0, N) cin >> L[i];
    sort(L.begin(), L.end());

    ll res = 0;
    repm(i, N-1, -1) {
        int a; a = L[i];
        repm(j, i-1, -1) {
            int b; b = L[j];
            repm(k, j - 1, -1) {
                int c = L[k];
                if (a < b + c &&  b <  a + c && c < a + b)  ++res;
            }
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define PI 2*acos(0)
#define ll long long
#define pii pair<int,int>
#define mx 100005
using namespace std;
ll int mod(ll int a,ll int b)
{
    ll int m=a%b;
    if(m<0){
        m=(b<0)?(m-b):(m+b);
    }
    return m;
}
char find_char(ll int n)
{
    char ch;
    ll int x=mod(n,26);
    if(x!=0){
        ch=96+x;
    }
    else ch='z';
    return ch;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s="";
    ll int n,x;
    char ch;
    cin>>n;
    while(n!=0){
        if(n%26==0) n-=26;
        x=mod(n,26);
        ch=find_char(x);
        s+=ch;
        n/=26;
    }
    for(int i=s.size()-1;i>=0;i--) cout<<s[i];
    return 0;
}


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

typedef double du ;
typedef string st ;
typedef long long ll ;
typedef long double ld ;
typedef long long int lli ;

#define vi vector <lli>
#define loop(num) for (lli i = 0 ; i < num ; i ++ )
#define loopcin(num , ar ) for (lli i = 0 ; i < num ; i ++ ) {cin >> ar [i] ;}
#define loopcout(num , ar) for (lli i = 0 ; i < num ; i ++ ) {cout << ar [i] << ' '; }

#define forr(num1 , num2) for (lli i = num1 ; i < num2 ; i ++ )
#define forrcin(num1 , num2 , ar ) for (lli i = num1 ; i < num2 ; i ++ ) {cin >> ar [i] ;}
#define forrcout(num1 , num2 , ar) for (lli i = num1 ; i < num2 ; i ++ ) {cout << ar [i] << ' '; }

#define D2forrcin(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cin >> A[i][j] ;}}
#define D2forrcout(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cout << A[i][j] << ' ' ;}cout << endl ;}

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

#define F first
#define S second

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main ()
{
    fastio
    st s ;
  cin >> s ;
  loop(s.size())
    if (s[i] == ',')
      s[i] -= 12 ;
  cout << s ;
    return 0 ;
}

/*___________________________________________________________________functions___________________________________________________________________________*/



Measured memory_bytes: 256
import Control.Applicative

main = do
    [w, h, x, y, r] <- map (read :: String -> Int) . words <$> getLine
    putStrLn $ if overWidth w x r || overHeight h y r
                 then "No"
                 else "Yes"

overWidth :: Int -> Int -> Int -> Bool
overWidth w x r = (x - r < 0) || (w < x + r)

overHeight :: Int -> Int -> Int -> Bool
overHeight h y r = (y - r < 0) || (h < y + r)

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

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

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

#define x1 gray_cat_x1
#define y1 gray_cat_y1

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define file "I1"

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

const int MAXN = 2e5 + 5;

struct state {
	ll v0, v1, v2;
	state() { v0 = v1 = v2 = 0; }
};

void merge_states(state &a, state &b) {
	ll tmp = (a.v2 * b.v0 + a.v1 * b.v1 + a.v0 * b.v2) % MOD;
	tmp = (tmp + a.v2 * b.v1 + a.v1 * b.v2) % MOD;
	tmp = (tmp + a.v2 * b.v2) % MOD;
	a.v2 = tmp;
	a.v1 = (a.v1 * b.v0 + a.v0 * b.v1) % MOD;
	a.v0 = (a.v0 * b.v0) % MOD;
}

void merge_states_deque(deque<state> &a, deque<state> &b) {
	if (SZ(a) < SZ(b)) {
		swap(a, b);
	}
	REP(i, 0, SZ(b)) {
		merge_states(a[i], b[i]);
	}
}

deque<state> states[MAXN];
state new_state;
int ind[MAXN];
int dis[MAXN];
ll st2[MAXN];
int cnt[MAXN];

vi g[MAXN];

void dfs(int s) {
	int d = 0;
	REP(i, 0, SZ(g[s])) {
		int to = g[s][i];
		dis[to] = dis[s] + 1;
		dfs(to);
		if (i == 0) {
			ind[s] = ind[to];
		} else {
			merge_states_deque(states[ind[s]], states[ind[to]]);
			d = max(d, SZ(states[ind[to]]));
			states[ind[to]].clear();
		}
	}
	
	states[ind[s]].push_front(new_state);
	
	/*printf("%d: %d\n", s, SZ(states[ind[s]]));
	REP(i, 0, SZ(states[ind[s]])) {
		printf("%lld %lld %lld\n", states[ind[s]][i].v0, states[ind[s]][i].v1, states[ind[s]][i].v2);
	}*/
	
	REPN(i, 1, d) {
		states[ind[s]][i].v0 = (states[ind[s]][i].v0 + states[ind[s]][i].v2) % MOD;
		states[ind[s]][i].v2 = 0;
	}
	
	
}

void solve(){
	int n;
	scanf("%d", &n);
	REPN(i, 1, n) {
		int p;
		scanf("%d", &p);
		g[p].pb(i);
		ind[i] = i;
	}
	
	new_state.v0 = new_state.v1 = 1;
	new_state.v2 = 0;
	
	dfs(0);
	
	st2[0] = 1;
	REPN(i, 1, n + 1) {
		st2[i] = (st2[i - 1] * 2) % MOD;
	}
	
	REPN(i, 0, n) {
		cnt[dis[i]]++;
	}
	
	ll ans = 0ll;
	REP(i, 0, SZ(states[ind[0]])) {
		ans = (ans + states[ind[0]][i].v1 * st2[n + 1 - cnt[i]]) % MOD;
	}
	cout << ans << endl;
}   

int main(){

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


Measured memory_bytes: 176128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define DEBUG(val) cout << #val << " : " << val << endl
#define MOD 1000000007

int main() {
  int n;
  cin >> n;
  vector<int> data(10000005);
  ll ans = 0;
  FOR(i, 1, n + 1) {
    for (ll j = i; j < n + 1;) {
      data[j] += 1;
      j += i;
    }
  }
  for (ll i = 1; i < n + 1; i++) {
    ans += i * data[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 42328
program exam_and_wizard
  implicit none
  integer :: n, i, num
  integer(8) :: a(100000), b(100000), c(100000), tot
  a = 0_8
  b = 0_8
  c = 0_8
  read(*,*) n
  read(*,*) a(1:n)
  read(*,*) b(1:n)
  c(1:n) = a(1:n) - b(1:n)
  num = 0
  tot = 0_8
  do i = 1, n
    if (c(i).lt.0) then
      num = num + 1
      tot = tot - c(i)
    end if
  end do
  if (num.eq.0) then
    write(*,'(i0)') 0
    stop
  end if
  call merge_sort(n,c(1:n))
  do i = n, 1, -1
    if (c(i).lt.0) exit
    tot = tot - c(i)
    num = num + 1
    if (tot.le.0_8) then
      write(*,'(i0)') num
      stop
    end if
  end do
  write(*,'(i0)') -1
  stop
contains
  subroutine merge_sort(n,c)
    implicit none
    integer, intent(in) :: n
    integer(8), intent(inout) :: c(n)
    integer :: num, lth, ubd, i
    num = n
    lth = 1
    do while (num.gt.1)
      do i = 1, num/2
        ubd = min(2*i*lth,n)
        call merge(c(2*(i-1)*lth+1:(2*i-1)*lth),c((2*i-1)*lth+1:ubd))
      end do
      lth = 2*lth
      num = (num+1)/2
    end do
    return
  end subroutine merge_sort
  subroutine merge(c1,c2)
    implicit none
    integer(8), intent(inout) :: c1(:), c2(:)
    integer(8) :: c(size(c1)+size(c2))
    integer :: i1, i2, n1, n2
    i1 = 1
    i2 = 1
    n1 = size(c1)
    n2 = size(c2)
    do while (i1.le.n1.and.i2.le.n2)
      if (c1(i1).le.c2(i2)) then
        c(i1+i2-1) = c1(i1)
        i1 = i1+1
      else
        c(i1+i2-1) = c2(i2)
        i2 = i2+1
      end if
    end do
    if (i1.le.n1) then
      c(i1+i2-1:n1+n2) = c1(i1:n1)
    else if (i2.le.n2) then
      c(i1+i2-1:n1+n2) = c2(i2:n2)
    end if
    c1 = c(1:n1)
    c2 = c(n1+1:n1+n2)
    return
  end subroutine merge
end program exam_and_wizard

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

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);


int main(void)
{
    ll x,cnt=0,i=1; cin>>x;
    while(cnt<x){
        cnt+=i;
        i++;
    }
    cout<<i-1<<endl;
    return 0;
}

Measured memory_bytes: 3580
#include <iostream>

using namespace std;

int main(){
    int n;
    cin >> n;
    long long a[200000];
    long long sum=0;
    long long ans=9223372036854775807;
    for(int i=0;i<n;i++){
        int b=0;
        cin >> b;
        if(i!=0)a[i]=b+a[i-1];
        if(i==0)a[i]=b;
    }
    sum=a[n-1];
    for(int i=0;i<n-1;i++){
        ans=min(abs(sum-a[i]*2),ans);
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
#define endl "\n"
#define test ll t; cin>>t; while(t--)
typedef long long int ll;
int main() {
    FIO;
    ll s;
    cin>>s;
    vector<ll>dp(s+1,0);
    dp[0]=1;
    for(int i=3;i<=s;i++){
        for(int j=i-3;j>=0;j--){
            dp[i]+=dp[j];
        }
        dp[i]%=mod;
    }
    cout<<dp[s]<<endl;
	return 0;
}


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

typedef long long ll;
typedef pair<int,int> P;
int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};
 
int main(){
  int d, g;
  cin >> d >> g;
  g /= 100;
  int p[d], c[d];
  for(int i=0; i<d; i++){
    cin >> p[i] >> c[i];
    c[i] /= 100;
  }
  int n = 1<<d;
  int ans = 1000000009;
  for(int i=0; i<n; i++){
    int tmp = 0, cnt = 0, ma = 0;
    for(int bit=0; bit<d; bit++){
      if(i&(1<<bit)){
        tmp += p[bit]*(bit+1) + c[bit];
        cnt += p[bit];
      }else{
        ma = max(ma, bit+1);
      }
    }
    if(g<=tmp+p[ma-1]*ma){
      if(ma>0) cnt += max(0,(g-tmp+ma-1)/ma);
      ans = min(ans, cnt);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
from bisect import bisect_left, bisect_right
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
B.sort()
C.sort()

cnt = 0
for j in range(n):
	idx_i = bisect_left(A, B[j])
	idx_k = bisect_right(C, B[j])
	cnt += idx_i * (n - idx_k)

print(cnt)

Measured memory_bytes: 105572
from numpy import cumsum

H, W, K = map(int, input().split())

field = []
for h in range(H):
    field.append(list(input().strip()))

ans = [[0 for _ in range(W)] for _ in range(H)]

idx = 1
for row in range(H):
    if '#' not in field[row]:
        continue

    conv = [1 if x == '#' else 0 for x in field[row]]
    cum = list(cumsum(conv))

    for i in range(W):
        if cum[i] == 0:
            cum[i] = 1

    for col in range(W):
        ans[row][col] = cum[col] + idx - 1

    idx += cum[-1]

for row in range(H):
    if ans[row][0] > 0:
        continue
    for r in range(row, H):
        if ans[r][0] > 0:
            ans[row] = ans[r]
            break

for row in range(H):
    if ans[row][0] > 0:
        continue
    for r in reversed(range(row)):
        if ans[r][0] > 0:
            ans[row] = ans[r]
            break

for row in ans:
    print(' '.join(map(str, row)))


Measured memory_bytes: 17264
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    ll n;
    cin >> n;
    ll ok=0;
    for(ll i=0;i<=n;i++){
        if((i*(i+1)/2)>=n){
            ok=i;
            break;
        }
    }
    ll dx=(ok*(ok+1)/2)-n;
    for(ll i=1;i<=ok;i++){
        if(i==dx) continue;
        cout << i << endl;
    }
}

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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
typedef queue<int> Q;
typedef pair<long,long> PLL;
typedef map<long,long> MLL;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
/*--------------------------------------------*/
int main(){
    int n,k;cin>>n>>k;
    //a,b,cのあまりが全て0か全てk/2のときのみ
    ll cnt=0;
    if(k%2==0){
        ll s=k/2;
        //あまり0
        ll tmp=n/k;
        cnt+=pow(tmp,3);
        //あまりs
        if(n>=s){
            ll tmp2=(n-s)/k+1;
            cnt+=pow(tmp2,3);
        }
    }else{
        ll tmp=n/k;
        cnt+=pow(tmp,3);
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 384
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
s = sum(b)
for i in range(n-1):
  if a[i]+1 == a[i+1]:
    s += c[a[i]-1]
print(s)

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


long long dp[1<<17] = {0};

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int n, W; cin >> n >> W;
  fill(dp + 1, dp + (1<<17), 1ll << 60);
  for (int i = 0; i < n; ++i) {
    int w, v; cin >> w >> v;
    for (int j = (1<<17) - 1; j >= v; --j) {
      dp[j] = min(dp[j], dp[j - v] + w);
    }
  }
  int ans = (1<<17) - 1;
  while (dp[ans] > W) --ans;
  cout << ans << '\n';
}


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

const int N = 100010;
char s[N];
int ans1 = 0, ans2 = 0;

int main() {
	scanf("%s", s);
	for (int i = 0; i < strlen(s); i += 2) 
		if (s[i] == '0') ++ ans1;
	for (int i = 1; i < strlen(s); i += 2)
		if (s[i] == '1') ++ ans1;
	for (int i = 0; i < strlen(s); i += 2) 
		if (s[i] == '1') ++ ans2;
	for (int i = 1; i < strlen(s); i += 2)
		if (s[i] == '0') ++ ans2;
	printf("%d\n", min(ans1, ans2));
	return 0;
} 

Measured memory_bytes: 384
#include <iostream>
using namespace std;
#define MAX 500000
#define Sentinel 1997032800

int L[MAX/2+2], R[MAX/2+2];
int cnt;

void merge(int A[], int n, int left, int mid, int right){
    int n1 = mid - left;
    int n2 = right - mid;
    for (int i = 0;i<n1;i++){
        L[i] = A[left+i];
    }
    for (int i = 0;i<n2;i++){
        R[i] = A[mid+i];
    }
    int i = 0,j = 0;
    L[n1] = R[n2] = Sentinel;
    for (int k = left; k<right;k++){
        cnt++;
        if(L[i]<=R[j]){
            A[k] = L[i++];
        }
        else{
            A[k] = R[j++];
        }
    }
}

void mergesort(int A[],int n,int left,int right){
    if (left+1<right){
        int mid = (right+left)/2;
        mergesort(A,n,left,mid);
        mergesort(A,n,mid,right);
        merge(A,n,left,mid,right);
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    int A[MAX],n,i;
    cnt = 0;
    cin>>n;
    for (i = 0;i<n;i++){cin>>A[i];}
    
    mergesort(A,n,0,n);
    for(i = 0;i<n;i++){
        if(i){cout<<" ";}
        cout<<A[i];
    }
    cout<<endl;
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 7044
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin>>N;
string s;
cin>>s;
int counter=0;
for(int i=0; i<N-2;i++){
if(s.at(i)=='A'&&s.at(i+1)=='B'&&s.at(i+2)=='C'){
counter++;}}
cout<<counter<<endl;}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,d;
  cin>>n;
  vector<int>D(n);
  for(int i=0;i<n;i++)
  {
    cin>>d;
    D[i]=d;
  }
  int count=0;
  for(int i=0;i<n;i++)
  {
    for(int j=i+1;j<n;j++)
    {
      count+=D[i]*D[j];
    }
  }
cout<<count;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
int n,cnt,a[200005];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=n;i>=1;i--){
		for(int j=i+i;j<=n;j+=i)a[i]^=a[j];
		if(a[i])cnt++;
	}
	printf("%d\n",cnt);
	for(int i=1;i<=n;i++)if(a[i])printf("%d ",i);
	return 0;
}

Measured memory_bytes: 1664
"use strict"
function main(arg) {
    //最大は1000000
    var num = parseInt(arg);
    var kotae = 0;


    for(var i = 1; i <= num; i++){
        var mozii =String(i);
        if(mozii.length % 2 != 0){
            kotae++;
        }
    }



    console.log(kotae);


}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 10956
import java.util.Scanner;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		
		int[] l = new int[N];
		// 棒の長さ受け取り
		for (int i=0; i<N; i++) {
			int next = sc.nextInt();
			// 長さを比べて長い方が最初になるように入れる
			if (i > 0) {
				for (int j=0; j<i; j++) {
					// 長ければその場所に
					if (next > l[j]) {
						System.arraycopy(l, j, l, j+1, i-j);
						l[j] = next;
						break;
					} else if (j+1 == i) {
						l[i] = next;
					}
				}
			} else {
				l[i] = next;
			}
		}
		// K個の棒をつなげる
		int sum = 0;
		for (int i=0; i<K; i++) {
			sum += l[i];
		}
		// 答えの出力
		System.out.println(sum);
	}
}

Measured memory_bytes: 21844
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<math.h>
int main(void){
	double r, m = M_PI, men, en;
	scanf("%lf", &r);
	men = r*r*m;
	en = (r * 2)*m;
	printf("%.6f %.6f\n", men, en);
	
	return 0;
}

Measured memory_bytes: 652
import java.util.*;

class Main{
	public static void main(String[] args){
		Solve s = new Solve();
		s.solve();
	}	
}

class Solve{
	Solve(){}
	
	Scanner in = new Scanner(System.in);

	void solve(){
		while(in.hasNext()) {
			int n = in.nextInt(), m = in.nextInt();
			if(n == 0 && m == 0) return;
			String[] s = new String[n];
			int[] d = new int[n];
			for(int i = 0; i < n; i++){
				s[i] = in.next();
				d[i] = in.nextInt();
			}
			int ans = 0;
			for(int i = 0; i < m; i++){
				String t = in.next();
				for(int j = 0; j < n; j++) {
					for(int k = 0; k < 8; k++){
						if(s[j].charAt(k) !='*' && s[j].charAt(k) != t.charAt(k)) break;
						if(k == 7) ans += d[j];
					}
				}
			}
			System.out.println(ans);
		}
	}

}

Measured memory_bytes: 43896
import java.util.Scanner;

public class Main {
	public static final int INFTY = 999999999;
	public static int hikaku = 0;  // 総比較回数

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] S = new int[n];
		for(int i = 0; i < n; i++) {
			S[i] = sc.nextInt();
		}
		mergeSort(S, 0, n);
		System.out.print(S[0]);
		for(int i = 1; i < n; i++) {
			System.out.print(" " + S[i]);
		}
		System.out.println("\n" + hikaku);
		sc.close();
	}

	// それぞれn1, n2個の整数が格納された配列LとRを配列Aにマージ（統合）する
	// LとRのすべての要素をそれらが昇順になるようにAにコピーする
	static void merge(int[] A, int left, int mid, int right) {
		int n1 = mid - left;
		int n2 = right - mid;
		int[] L = new int[n1 + 1];
		int[] R = new int[n2 + 1];
		for(int i = 0; i < n1; i++) {
			L[i] = A[left + i];
		}
		for(int i = 0; i < n2; i++) {
			R[i] = A[mid + i];
		}
		// LとRのそれぞれの末尾に番兵としてどの要素よりも大きな値を配置することで
		// 実装を簡略化することができる
		L[n1] = R[n2] = INFTY;
		int i = 0, j = 0;
		for(int k = left; k < right; k++) {
			hikaku++;
			if(L[i] <= R[j]) {
				A[k] = L[i];
				i++;
			}else {
				A[k] = R[j];
				j++;
			}
		}
	}

	// 配列Aとその部分配列の範囲を表すleft,rightを引数とする
	// leftは部分配列の先頭要素のインデックス、rightは部分配列の末尾+1の要素のインデックス
	static void mergeSort(int[] A, int left, int right) {
		if(left + 1 < right) {  // 部分配列の要素数が１でないとき
			int mid = (left + right) / 2;
			mergeSort(A, left, mid);
			mergeSort(A, mid, right);
			merge(A, left, mid, right);  // merge処理の直前には、既に2つの部分配列はソート済みになっている
		}
	}
}


Measured memory_bytes: 169568
#!/usr/bin/env python
# -*- coding:utf-8 -*-
from __future__ import print_function,division
import time
import sys
import io
import re
import math
start = time.clock()
i = 0

sys.stdin.readline()
a=[int(s) for s in sys.stdin.readline().split()]
sys.stdin.readline()
ms=[int(s) for s in sys.stdin.readline().split()]
ans=set([0])
for i in a:
    ans|=set(j+i for j in ans)
ans=list(ans)
for jk in ms:
    if jk in ans: print('yes')
    else: print('no')

Measured memory_bytes: 4692
#![allow(unused_mut, non_snake_case,unused_imports)]
use std::iter;
use std::cmp::{max, min, Ordering};
use std::mem::{swap};
use std::collections::{HashMap,BTreeMap,HashSet,BTreeSet,BinaryHeap,VecDeque};
use std::iter::FromIterator;

//　高速 EOF要
//macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();input_inner!{iter, $($r)*}};($($r:tt)*) => {let mut s = {use std::io::Read;let mut s = String::new();std::io::stdin().read_to_string(&mut s).unwrap();s};let mut iter = s.split_whitespace();input_inner!{iter, $($r)*}};}
//macro_rules! input_inner {($iter:expr) => {};($iter:expr, ) => {};($iter:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($iter, $t);input_inner!{$iter $($r)*}};}
//macro_rules! read_value {($iter:expr, ( $($t:tt),* )) => {( $(read_value!($iter, $t)),* )};($iter:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()};($iter:expr, chars) => {read_value!($iter, String).chars().collect::<Vec<char>>()};($iter:expr, usize1) => {read_value!($iter, usize) - 1};($iter:expr, $t:ty) => {$iter.next().unwrap().parse::<$t>().expect("Parse error")};}
// 低速 EOF不要
macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */
fn main(){
    input!(S:chars,T:chars);
    let mut S:Vec<char> = S;
    let mut T:Vec<char> = T;
    S.sort();
    T.sort();
    let mut cntS = vec![0;26];
    let mut cntT = vec![0;26];

    for c in S{
        cntS[c as usize - 'a' as usize]+=1;
    }
    for c in T{
        cntT[c as usize - 'a' as usize]+=1;
    }
    cntS.sort();
    cntT.sort();
    for i in 0..26{
        if cntS[i] != cntT[i]{
            println!("No");
            return;
        }
    }
    println!("Yes");
}


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

int main()
{
  vector<ll> nums(100001, 0);
  ll sum = 0;
  int n, a;
  cin >> n;
  rep(i, n) {
    cin >> a;
    nums[a]++;
    sum += a;
  }
  int q, b, c;
  cin >> q;
  rep(i, q) {
    cin >> b >> c;
    sum += (c - b) * nums[b];
    nums[c] += nums[b];
    nums[b] = 0;
    cout << sum << endl;
  }

  return 0;
}


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

int main(){
    string akiba="AKIHABARA";
    string s;
    cin>>s;
    int index=0;
    for(int i=0;i<s.size();i++){
        if(index>=akiba.size()) {
            index=1000000;
            break;
        }
        if(s[i]==akiba[index]){
            index++;
        }
        else if(akiba[index]=='A'){
            index++;
            i--;
        }
        else{
            index=1000000;
            break;
        }
    }
    
    for(int j=index;j<akiba.size();j++){
        if(akiba[j]!='A'){
            index=10000;
            break;
        }
        index++;
    }
    
    if(index==akiba.size()) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 256
#S= str(input())
N,M,X = map(int,input().split())
#N = int(input())
A = list(map(int,input().split()))
b=0
s=0
for i in A:
    if i>X:
        b+=1
    else:
        s+=1
if b>=s:
    print(s)
else:
    print(b)


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char* argv[])
{
	int N,x;
	cin>>N>>x;
	int i=0;
	long long a1;
	vector<long long> A(N,0);
	for (i=0;i<N;i++){
		cin>>a1;
		A[i]=a1;
	}
	long long aw=0;
	for (i=1;i<N;i++){
		if (A[i]+A[i-1]>x){
			long long y=A[i]+A[i-1]-x;
			A[i]-=y;
			if (A[i]<0){
				A[i-1]+=A[i];
				A[i]=0;
			}
			aw+=y;
		}
	}
	cout<<aw<<endl;
	return 0;
}

Measured memory_bytes: 1152
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String[] S = sc.nextLine().split(" ");
		Deque<Integer> stack = new ArrayDeque<Integer>();

		int a;
		int b;

		for (String s : S) {
			if ("+".equals(s)) {
				a = stack.pollLast();
				b = stack.pollLast();
				stack.offer(b + a);
			} else if ("-".equals(s)) {
				a = stack.pollLast();
				b = stack.pollLast();
				stack.offer(b - a);
			} else if ("*".equals(s)) {
				a = stack.pollLast();
				b = stack.pollLast();
				stack.offer(b * a);
			} else {
				stack.offer(Integer.parseInt(s));
			}
		}

		System.out.println(stack.pollLast());

		sc.close();
	}
}



Measured memory_bytes: 26152
function Main(input) {
  input = input.split("\n");
  const [n, q] = input.shift().split(" ").map((a) => parseInt(a, 10));
  const a = input.shift().split(" ").map((a) => parseInt(a, 10));

  // Preload queries
  const qs = [];
  for (let qi=0; qi<q; qi++) {
    const [l, r] = input[qi].split(" ");
    qs[l-1] = qs[l-1] || [];
    qs[l-1].push([r-1, qi]);
  }

  // store the information whether the number is already appeared
  const ps = [];
  const pi = {};
  for (let i=0; i<n; i++) {
    const l = pi[a[i]];
    if (l !== undefined) {
      ps[l] = ps[l] || [];
      ps[l].push(i);
    }
    pi[a[i]] = i;
  }

  const ans = [];

  // Create BIT
  const d = new Array(n+1).fill(0);
  for (let x=n-1; x>=0; --x) {
    const psLength = ps[x] && ps[x].length || 0;
    for (let y=0; y<psLength; y++) {
      let di = ps[x][y] + 1;
      for (; di<=n; di+=di&-di) {
        d[di] += 1;
      }
    }
    const qsLength = qs[x] && qs[x].length || 0;
    for (let y=0; y<qsLength; y++) {
      const [r, i] = qs[x][y];
      let sum = 0;
      let ri = r + 1;
      for (; ri; ri -= ri&-ri) {
        sum += d[ri];
      }
      ans[i] = (r-x+1) - sum;
    }
  }

  console.log(ans.join("\n"));
  return;
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 323528
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <set>

using namespace std;
using ll = long long;
const int MOD=1000000007;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

vector<vector<int> > vvi;
vector<vector<vector<int> > > vvvi;

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

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }


int main(int argc, char**argv){
    int n;
    cin >> n;
    vector<int> h(n);
    for (int i = 0; i < n; i++){
        cin >> h[i];
    }

    vector<int> c(n, 0);
    c[1] = c[0] + abs(h[1] - h[0]);
    for (int i = 2; i < n; i++){
        c[i] = min(c[i-2] + abs(h[i] - h[i-2]), c[i-1] + abs(h[i] - h[i-1]));
    }
    cout << c[n-1] << endl;

    return 0;
}



Measured memory_bytes: 1024
n,m=map(int,input().split())
ps=[list(input().split()) for _ in range(m)]
wa=[0]*n
w=0
ac=0
d=[0]*n
for p,s in ps:
  if s=='WA':
    if d[int(p)-1]==0:
      wa[int(p)-1]+=1
  else:
    if d[int(p)-1]==0:
      ac+=1
      d[int(p)-1]=1
      w+=wa[int(p)-1]
print(ac,w)

Measured memory_bytes: 32000
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	int len=s.length();
	for(int i=0;i<len;i+=2){
		if(s[i]=='L'){
			cout<<"No";
			return 0;
		}
	}
	for(int i=1;i<len;i+=2){
		if(s[i]=='R'){
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
import numpy as np
N = int(input())
comfort = list(map(int,input().split()))
comfort_reverse = np.sort(comfort)[::-1]

ans = comfort_reverse[0]

if N > 2:
    for i in range(N-2):
        num = i // 2 + 1
        ans += comfort_reverse[num]

print(ans)

Measured memory_bytes: 49796
#include <bits/stdc++.h>
#include <cstdlib>
using namespace std;
typedef std::bitset<6> bit;
 
int main(){
  int N,M,ans=0;
  cin>>N>>M;
  vector<int> H(N),Hmax(N);
  
  for(int i=0;i<N;i++){
    cin>>H.at(i);
    Hmax.at(i)=0;
  }
  int a,b;
  for(int i=0;i<M;i++){
    cin>>a>>b;
    Hmax.at(a-1)=max(Hmax.at(a-1),H.at(b-1));
    Hmax.at(b-1)=max(Hmax.at(b-1),H.at(a-1));
  }
  
  for(int i=0;i<N;i++){
    if(Hmax.at(i)<H.at(i)) ans++;
    //cout<<Hmax.at(i)<<" "<<H.at(i)<<endl;
  }
  
  cout<<ans;
  
  return 0;
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 300010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////


void solve() {
	ll N, P;
	cin >> N >> P;
	vector<pl> vec;
	for(ll i = 2; i * i <= P; i++) {
		if(P % i == 0) {
			ll cnt = 0;
			while(P % i == 0) {
				P /= i; cnt++;
			}
			vec.pb(pl(i, cnt));
		}
	}
	if(P != 1) {
		vec.pb(pl(P, 1));
	}
	ll res = 1;
	rep(i, 0, sz(vec)) {
		ll n = vec[i].sec;
		rep(j, 0, n / N) {
			res *= vec[i].fst;
		}
	}
	cout << res << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

LL modinv(LL a) {
    LL b = MOD, u = 1, v = 0;
    while (b) {
        LL t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= MOD;
    if (u < 0) u += MOD;
    return u;
}

LL moddev(LL a, LL b){
	return a * modinv(b) % MOD;
}

void Main()
{
    int a,b,c;
    cin >> a >> b >> c;

    if(a == b && c != b){
        cout << "Yes" << endl;
    }
    else if(b == c && a != b){
        cout << "Yes" << endl;
    }
    else if(c == a && b != c){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

struct Edge{
    int from,to,dist,c;
    Edge(int from,int to,int dist,int c) : from(from),to(to),dist(dist),c(c) {}
};


struct State{
    double time;
    int where,speed;
    int before;
    State(double time,int where,int speed,int before) 
        : time(time),where(where),speed(speed),before(before) {}
};

bool operator<(const State& rhs,const State& lhs){
    return rhs.time < lhs.time;
}
bool operator>(const State& rhs,const State& lhs){
    return rhs.time > lhs.time;
}

const int INF = 100000;
double solve(vector<vector<Edge> > E,int s,int g){
    int n = E.size();
    {
        vector<vector<int> > dist(n,vector<int>(n,INF));
        for(int i=0;i<n;i++){
            for(size_t j=0;j<E[i].size();j++){
                dist[i][E[i][j].to] = 0;
            }
        }
        for(int i=0;i<n;i++){
            dist[i][i] = 0;
        }
        for(int k=0;k<n;k++){
            for(int i=0;i<n;i++){
                for(int j=0;j<n;j++){
                    dist[i][j] = min(dist[i][j],dist[i][k] + dist[k][j]);
                }
            }
        }
        if(dist[s][g] >= INF) return -1;
    }

    vector<vector<vector<char> > > used(n,
           vector<vector<char> >(31,
           vector<char>(n,false)));

    priority_queue<State,vector<State>,greater<State> > que;
    que.push(State(0,s,0,s));
    double ans = INF;
    while(not que.empty()){
        double time = que.top().time;
        int where = que.top().where;
        int speed = que.top().speed;
        int before = que.top().before;

        que.pop();
        if(used[where][speed][before]) continue;
        used[where][speed][before] = true;
        if(where == g and speed == 1){
            ans = time;
            break;
        }
        for(size_t i=0;i<E[where].size();i++){
            for(int k=-1;k<=1;k++){
                int new_speed = speed + k;
                if(new_speed <= 0 or new_speed > E[where][i].c) continue;
                if(before == E[where][i].to) continue;
                que.push(State(time + E[where][i].dist / (double)new_speed,
                               E[where][i].to,new_speed,where));
            }
        }
    }
    return ans;

}

int main(){
    cout << fixed << setprecision(10);
    while(true){
        int n,m,s,g;
        cin >> n >> m ;
        if(n == 0) break;
        cin >> s >> g;
        s--;g--;
        vector<vector<Edge> > E(n);
        for(int i=0;i<m;i++){
            int x,y,d,c;
            cin >> x >> y >> d >> c;
            x--;y--;
            E[x].push_back(Edge(x,y,d,c));
            E[y].push_back(Edge(y,x,d,c));
        }
        double r = solve(E,s,g);
        if(r < 0){
            cout << "unreachable" << endl;
        }else{
            cout << r << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 15116
def countSetBits(n):
    count = 0
    while (n):
        n &= (n - 1)
        count += 1

    return count



N=10**9 + 7
n=int(input())
ar = [list(map(int,input().split())) for _ in range(n)]   
total=1<<n
bits=[[]for _ in range(n+1)]
dp=[[0]*(total+5) for j in range(n+5)]

for i in range(n):
    if ar[0][i]==1:
        dp[0][1<<(n-1-i)]=1

for j in range(total):
    i=countSetBits(j)-1
    for k in range(0,n):
        if ar[i][n-k-1]==1 and j&(1<<k):
            dp[i][j]=(dp[i][j]+dp[i-1][j&(~(1<<k))])%N

print(dp[n-1][total-1])
















Measured memory_bytes: 500024
using System;
using System.Linq;
namespace ConsoleApp13
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);
            int[] n = new int[3];
            n[0] = a + b;
            n[1] = a - b;
            n[2] = a * b;
            Console.WriteLine(n.Max());


        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RNG(i,from,to) for(int i=(from); i<(int)(to); i++)
#define gcd(i,j) __gcd((i), (j))
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vecll;
template<typename S, typename T> string to_string(pair<S, T> p) { return "("+to_string(p.first)+","+to_string(p.second)+")"; }
template<typename T> string to_string(T p[2]) { return "["+to_string(p[0])+","+to_string(p[1])+"]"; }
template<typename T> void println(T e){ cout << to_string(e) << endl; }
template<typename T> void println(const vector<T>& v){ cout << "[";for(const auto& e : v){ cout << to_string(e) << ","; }cout << "]";cout << endl; }
template<typename T> void println(const vector<vector<T>>& vv){ for(const auto& v : vv){ println(v); } }
template<typename Iter> void println(Iter first, Iter last){ for(auto it=first; it != last; it++){ cout << *it << " "; }; cout << endl; }
template<typename T> T mod_pow(T x, T n, const T &p) { T ret = 1; while(n > 0) { if(n & 1) (ret *= x) %= p; (x *= x) %= p; n >>= 1; } return ret; }
template<typename T> T mod_inv(T x, const T &p) { return mod_pow(x, p-2, p); }
const ll DVSR = 1e9+7;


int main(int argc, char const *argv[])
{
  ll a,b; cin >> a >> b;
  if (a <= b) {
    cout << a << endl;
  } else {
    cout << a-1 << endl;
  }
  return 0;
}



Measured memory_bytes: 256
H=int(input())
monsters=[]
monsters.append([1,H])

n=0
a=H
for i in range(40):
  a=a//2
  if a>=1:
    n+=1
  else:
    break

ans=0
for i in range(n+1):
  if monsters[i][1]==1:
    ans+=monsters[i][0]
  else:
    ans+=monsters[i][0]
    monsters.append([2*monsters[i][0],monsters[i][1]//2])

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdlib>
#include <bitset>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>
#include <sstream>
#include <math.h>

using namespace std;

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecchar vector<char>
#define vecstr vector<string>
#define vecbool vector<bool>
#define vec2bool vector<vector<bool>>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s >= 0;s--)

#define Pi 3.1415926535897932384626

int main() {
	ll n, ans;
	ll x[5];
	string s = "No";
	bool flag = false;

	forll(i, 0, 5)
		cin >> x[i];

	forll(i, 0, 5)
	{
		if (x[i] == 0)
		{
			ans = i + 1;
			break;
		}
	}


	cout << ans;
}


Measured memory_bytes: 3620
n = map(int, input())
s = input()


while True:
    temp_s = []
    prev_color = ""
    isFusion = False
    for i in range(len(s)):
        if s[i] == prev_color:
            continue
        else:
            temp_s.append(s[i])
            prev_color = s[i]
    s = temp_s
    if not isFusion:
        break
print(len(s))

Measured memory_bytes: 3956
#include <stdio.h>

int main(void) {
	double w,l;
	int n;
	while(scanf("%d,%lf,%lf",&n,&w,&l) != EOF){
		if((w / (l * l)) >= 25.0f){
			printf("%d\n",n);
		}
	}
	return 0;
}

Measured memory_bytes: 628
# from https://atcoder.jp/contests/abc142/submissions/7778197
n,m = gets.split.map!(&:to_i)
kk = m.times.map {
  [
    gets.strip.split.map(&:to_i),
    gets.strip.split.map(&:to_i)
  ]
}

INF = 10**10
dp = Array.new(2**n, INF)

kk.each do |(price, _), targets|
  key_state = targets.inject(0) {|memo, c| memo+2**(c-1) }
  dp[key_state] = price if dp[key_state] > price

  dp.each_with_index do |current_price, current_state|
    next_state = current_state | key_state
    dp[next_state] = current_price + price if dp[next_state] > current_price + price
  end

#  p dp
end

if dp.last==INF
  p -1;exit
end

p dp.last


Measured memory_bytes: 4220