akhauriyash/Code-Regression huggingface dataset:
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
def main(N, A):
    xor = 0
    for i in range(2, N):
        xor ^= A[i]
    p = A[0] + A[1]
    if (p - xor) & 1:
        return -1
    a = (p - xor) >> 1

    # dp[i][j]=A[0]と同じ桁数の整数で下からi桁目までで条件を満たす値の最大値
    # j=0:i桁目より下の数値がA[0]以下 j=1:A[0]より大きい
    bl = max(A[0], xor).bit_length()
    dp = [[-1] * 2 for _ in range(bl + 1)]
    # 初期状態
    dp[0][0] = 0

    az = A[0]
    for i in range(bl):
        ni = i + 1
        azb = az & 1
        xorb = xor & 1
        ab = a & 1
        for j in range(2):
            if dp[i][j] < 0: continue
            for nazb in range(2):
                if nazb > azb:
                    nj = 1
                elif nazb < azb:
                    nj = 0
                else:
                    nj = j
                for nbzb in range(2):
                    if nazb ^ nbzb == xorb and nazb & nbzb == ab:
                        break
                else:
                    continue
                dp[ni][nj] = max(dp[ni][nj], dp[i][j] | (nazb << i))
        az >>= 1
        xor >>= 1
        a >>= 1

    ans = dp[bl][0]
    if ans <= 0:
        return - 1
    return A[0] - ans

if __name__ == '__main__':
    input = sys.stdin.readline
    N = int(input())
    *A, = map(int, input().split())
    print(main(N, A))


Measured memory_bytes: 62200
private fun readIntList() = readLine()!!.split(" ").map { it.toInt() }.toList()

fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val A = readIntList()

    println(A.sorted().let { it.first() to it.last() }.let { Math.abs(it.second - it.first) })
}

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


int main()
{
  int n;
  cin >> n;
  ll l[90];
  l[0] = 2;
  l[1] = 1;
  for(int i = 2;i <=n;i++){
    l[i] = l[i-1] + l[i-2];
  }
  cout << l[n] << endl;
  return 0;
}


Measured memory_bytes: 384
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;
typedef struct pair<int,int> P;
int N,M;
int A[101];
int main() {
	cin>>N>>M;
	for(int i=1;i<N+1;i++){
		cin>>A[i];
	}
	int T=0;
	for(int j=2;j<M+1;j++){
		for(int i=1;i<N;i++){
			if(A[i]%j>A[i+1]%j){
				T=A[i];
				A[i]=A[i+1];
				A[i+1]=T;
			}
		}
	}
	for(int i=1;i<N+1;i++){
		cout<<A[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 3100
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;

int main(){
 int N,K;
 cin >> N >> K;
 double psum=0.0;
 for(int i=1;i<=N;i++){
     for(int t=0;t<20;t++){
         if(i*pow(2,t)>=K){
               psum += 1.0/N * 1./pow(2,t);
               break;
         }
     }
 }

 cout << setprecision(15) << psum << endl;
}             

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

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = (int) 2e5 + 7;
int n;
int a[N];
int f[N];
ll sol = 0;

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

  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sol += f[a[i]];
    f[a[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << sol - f[a[i]] + 1 << "\n";
  }
}


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

int main() {
  int n;
  cin >> n;
  int64_t tuyonowa = 0;
  vector<int> a(3 * n);
  for (int i = 0; i < 3 * n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  for (int i = n; i < 3 * n; i += 2) tuyonowa += a[i];
  cout << tuyonowa;
}

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


// 最小公倍数を求める
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'));
}
int fact(int n){
  if(n == 1)return 1;
  return n * fact(n-1);
  }


int main(){
  int m;
  cin >> m; 
  cout << 48 - m << endl;
}


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


#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

using namespace std;

inline bool isvowel (char c) {
	c = tolower(c);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u') return 1;
    return 0;
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int h, w;
char c[511][511];
char red[511][511], blue[511][511];
 
int main() {
	cin >> h >> w;
	for (int i=  1; i <= h; i ++) {
		for (int j = 1; j <= w; j ++) {
			cin >> c[i][j];
  	    }
	}
	
	for(int i = 1; i <= h; i ++) {
		red[i][1] = '#';		
		blue[i][w] = '#';
		if(i & 1) {
			for(int j = 1; j < w; j ++) 
				red[i][j] = '#';
		} else {
			for(int j = w; j > 1; j --)
				blue[i][j] = '#';
		}		
	}
	for(int i = 1; i <= h; i ++) {
		for(int j = 1; j <= w; j ++) {
			if(c[i][j] == '#')
				red[i][j] = blue[i][j] = '#';
		}
	}
	for(int i = 1; i <= h; i ++) {
		for(int j = 1; j <= w; j ++) {
			if(red[i][j] != '#') red[i][j] = '.';
			cout << red[i][j];
		}
		cout << '\n';
	}
	cout << '\n';
	for(int i = 1; i <= h; i ++) {
		for(int j = 1; j <= w; j ++) {
			if(blue[i][j] != '#') blue[i][j] = '.';
			cout << blue[i][j];
		}
		cout << '\n';
	}
	return Accepted;  
}

// Coded By OB

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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; }

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll x,y; cin>>x>>y;
  ll ans;
  if(x<y){
    ans=y-x;
    if(x<0 && 0<y){
      chmin(ans,abs(abs(x)-abs(y))+1);
    }
  }else{
    if(y<0 && 0<x){
      ans=abs(abs(x)-abs(y))+1;
    }else if(x==0 || y==0){
      ans=abs(x+y)+1;
    }else{
      ans=abs(abs(x)-abs(y))+2;
    }
  }
  
  cout<<ans<<endl;
}

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

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

using namespace std;



int main(void) {
	string s;
	cin >> s;
	int count = 0;
	while (s.length() > 1) {
		if (s[0] == s[s.length() - 1]) {
			s.erase(s.begin());
			s.erase(s.end() - 1);
		}
		else if (s[0] != s[s.length() - 1] && s[0] == 'x') {
			s.push_back('x');
			count++;
		}
		else if (s[0] != s[s.length() - 1] && s[s.length() - 1] == 'x') {
			s.insert(s.begin(), 'x');
			count++;
		}
		else {
			cout << -1 << endl;
			return 0;
		}
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
int main(void)
{
	int a,b,f[10],x,N,n,m;
	for(;;)
	{
		scanf("%d",&x);
		if(x==-1)
			break;
		for(a=0;a<10;a++)
			f[a]=0;
		for(;x>0;)
		{
			for(N=0,n=1;;N++,n*=4)
				if(n>x)
				{
					n/=4;
					N--;
					break;
				}
			for(m=1;;m++)
				if(m*n>x)
				{
					m--;
					break;
				}
			f[N]=m;
			x-=m*n;
		}
		for(a=9,b=0;a>=0;a--)
		{
			if(f[a]!=0)
				b=1;
			if(b==1)
				printf("%d",f[a]);
			else if(a==0)
				printf("0");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG

using namespace std;
using ll = long long;

int		main(void)
{
	string S;

	cin >> S;
	ll A = 0;
	ll W = 0;

	for (int i = 0; S[i]; i++)
	{
		if (S[i] == 'W')
		{
			A += i;
			W++;
		}
	}
	// (W) = (1 + W - 1)
	ll B = (W) * (W - 1) / 2;
	cout << A - B << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repa(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define _GLIBCXX_DEBUG

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

  cout << max(a*b, c*d) << endl;

}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=1e6;
ll d[mm];
ll mod=1e9+7;
int main()
{
	ll n,m,i,j,k,kk,a,b,t,p;
	cin>>n>>m;
	n++;
	ll s=0; ll ss=0;k=0;kk=0;
 	for(i=1;i<=m-1;i++)
		s+=i;
	k=m;
//	cout<<s<<endl;
	for(i=n;i>=n-m+2;i--) ss+=i;
	kk=n-m+1;
//	cout<<ss<<endl;
	p=0;
	for(i=m;i<=n;i++)
	{
		s+=k;
		ss+=kk;
		p=(p+(ss-s+1))%mod;
		kk--;
		k++;
//		cout<<k<<' '<<kk<<' '<<p<<endl;
	}
	cout<<p<<endl;

}

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

int main() {
  int X, K;
  cin >> X;
  K = 1;
  
  for (int i = 1; ; i++) {
    if  ((i * X) % 360 == 0) {
      break;
    }
    K++;
  }
  cout << K << endl;
  return 0;
}

Measured memory_bytes: 3628
/**********************************************************************
   File gacha.cpp
   Author  harunaya
   Date   2020-04-27(Mon)
   note
**********************************************************************/

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

int main() {
  int n; cin >> n;
  set<string> S;
  for (int i = 0; i < n; i++){
    string s;
    cin >> s;
    S.insert(s);
  }
  cout << S.size() << endl;
}


Measured memory_bytes: 19216
#include<stdio.h>
int A[2000];
int n;
int func(int i, int m);

int main()
{
  int m, q;
  int i;

  scanf("%d", &n);
  for(i=0; i<n; i++){
    scanf("%d", &A[i]);
    // printf("A[%d] = %d\n", i, A[i]);
  }

  scanf("%d", &q);

  for(i=0; i<q; i++){
    scanf("%d", &m);

    if(func(0, m)){
      printf("yes\n");
    }
    else{
      printf("no\n");
    }
    }

  return 0;
}


int func(int i, int m)
{
  int work;

  if(m==0)
    return 1;
  if(i >= n)
    return 0;
  
  work = func(i+1, m) || func(i+1, m-A[i]);
  // printf("i=%d   m=%d   A[%d]=%d   work=%d\n", i, m, i, A[i], work);
  return work;
  }

Measured memory_bytes: 580
'use strict';
        (function(stdin) {
          var inputs  = stdin.toString().split('\n');
          var EOF = '0';
          var data = inputs.slice(0,inputs.indexOf(EOF));
          
          data.forEach(function(d,i,o){
            console.log('Case',i + 1 + ':',d);
          });

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

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

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

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

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	string s;
	LL k;
	cin>>s>>k;
	int l=s.length(),t=1,idx=0;
	FOR(i,0,l){
		if(s[i]!='1'){
			t=s[i]-'0';
			idx=i;
			//cerr<<i;
			break;
		}
	}
	if(idx+1<=k)cout<<s[idx];
	else cout<<1;


    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int a[5],k,pivot = 0;

void process()
{
    for (int i = 0 ; i < 5; i ++)
    {
        for (int j = i+1; j < 5 ; j ++)
        {
            if (abs(a[i] - a[j]) > k)
            {
                cout << ":(" << endl;
                pivot = 1;
                break;
            }
            if (pivot == 1)
            break;
        }
    }
    if (pivot == 0) cout << "Yay!";
}

int main()
{

    cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] >> k;
    process();
    return 0;

}


Measured memory_bytes: 256
from numba import njit


@njit(fastmath=True)
def fact(x):
    i = 1
    while i * i <= x:
        if x % i == 0:
            yield i
            yield x // i
        i += 1


def main():
    n = int(input())
    a = tuple(map(int, input().split()))

    c = [0] * (max(a) + 1)

    for e in a:
        c[e] += 1

    ans = n
    for e in a:
        c[e] -= 1
        for fct in fact(e):
            if c[fct]:
                ans -= 1
                break

        c[e] += 1

    print(ans)


if __name__ == "__main__":
    main()


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

typedef long long ll;
typedef pair<int, int> pii; 
const int N = 2e5+10, mod = 1e9+7;

void solve() {
    string s; cin >> s;
    int a = 0;
    if (s == "SUN") {
        a = 7;
    } else if (s == "MON") {
        a = 6;
    } else if (s == "TUE") {
        a = 5;
    } else if (s == "WED") {
        a = 4;
    } else if (s == "THU") {
        a = 3;
    } else if (s == "FRI") {
        a = 2;
    } else {
        a = 1;
    }
    cout << a << endl;
}

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

Measured memory_bytes: 3656
#include <iostream>

using namespace std;

int main()
{
    long int n,W;
    cin>>n>>W;
    long int weight[n],val[n],dp[n+1][W+1];
    for(long int i=0;i<n;i++)
    {
        cin>>weight[i]>>val[i];
    }
    for(long int i=0;i<n+1;i++)
    {
        for(long int j=0;j<W+1;j++)
        {
            if(i==0 || j==0)
            {
                dp[i][j]=0;
            }
            else if(j>=weight[i-1])
            {
                dp[i][j]=max(dp[i-1][j],val[i-1]+dp[i-1][j-weight[i-1]]);
            }
            else
            {
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    cout<<dp[n][W];


    return 0;
}


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

using namespace std;

#define MP make_pair
#define PB push_back
#define f first
#define s second

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;

//int dr1[] = {-1, 0, 1, 0};
//int dc1[] = {0, 1, 0, -1};
//int dr3[] = {0, 1, 2, 3, 2, 1, 0, -1, -2, -3, -2, -1, -1, 1, 0, 0};
//int dc3[] = {3, 2, 1, 0, -1, -2, -3, -2, -1, 0, 1, 2, 0, 0, -1, 1};
const int MOD = 1000000007;
const int INF = 1000000007;

ll modx(ll a)
{
    return (a%MOD+MOD)%MOD;
}

ll times(ll a, ll b)
{
    return modx(modx(a)*modx(b));
}

ll add(ll a, ll b)
{
    return modx(modx(a)+modx(b));
}

ll sub(ll a, ll b)
{
    return modx(MOD+modx(a)-modx(b));
}

ll fastExp(ll base, ll exp)
{
    if(exp == 0LL)
    {
        return 1LL;
    }

    if(exp%2==0)
    {
        return fastExp(times(base, base), exp/2);
    }
    else
    {
        return times(exp, fastExp(times(base, base), exp/2));
    }
}


const int MAXN = (int)2e5+5;
ll N, Q, tot[MAXN];
vector<int> graph[MAXN];



void dfs(int v, int u)
{
    for(int i=0; i<graph[v].size(); i++)
    {
        if(graph[v][i] != u)
        {
            tot[graph[v][i]]+=tot[v];
            dfs(graph[v][i], v);
        }
    }
}

int main()
{
    //freopen("input.in","r",stdin);
    //freopen("output.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> N >> Q;
    for(int i=0; i<N-1; i++)
    {
        int x, y;
        cin >> x >> y;
        x--; y--;
        graph[x].PB(y);
        graph[y].PB(x);
    }

    for(int i=0; i<Q; i++)
    {
        int v;
        ll x;
        cin >> v >> x;
        v--;
        tot[v]+=x;
    }

    dfs(0, -1);
    for(int i=0; i<N; i++)
    {
        cout << tot[i] << " ";
    }
    return 0;
}


Measured memory_bytes: 27392
export class Main {
  static main(input: string): string {
    const tmp: string[] = input.split("\n");
    const [s]: string[] = tmp.shift().split(" ");
    const [t]: string[] = tmp.shift().split(" ");
    for (let i = 0, len = s.length; i < len; i++) {
      if (s.charAt(i) != t.charAt(i)) {
        return "No";
      }
    }
    return `Yes`;
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));


Measured memory_bytes: 29632
def fractorial(m):
    ans = 1
    for i in range(1,m):
        ans*=i
    if m==0:
        ans=1
    return ans

n = int(input())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
list_nump = list(range(1,n+1))
list_numq = list(range(1,n+1))
rank_p = 0
rank_q = 0
for i in range(n):
    tmp_frac = fractorial(n-i)
    rank_p += (list_nump.index(p[i]))*tmp_frac
    list_nump.remove(p[i])
    rank_q += (list_numq.index(q[i]))*tmp_frac
    list_numq.remove(q[i])
print(abs(rank_p-rank_q))

Measured memory_bytes: 3064
#include <math.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <vector>

using namespace std;
using Graph = vector<vector<int>>;

using ll = long long;
typedef pair<ll, ll> P_ll;
typedef pair<int, int> P;

const ll INF_ll = 1e17;
const int INF = 1e8;

int main() {
  int N, H;
  cin >> H >> N;
  vector<vector<int>> AB(N, vector<int>(2, 0));
  for (int i = 0; i < N; i++) {
    cin >> AB[i][0] >> AB[i][1];
  }
  vector<vector<int>> dp(N + 1, vector<int>(H + 1, INF));
  for (int i = 0; i <= N; i++) {
    dp[i][0] = 0;
  }

  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= H; j++) {
      if (j < AB[i][0]) {
        dp[i + 1][j] = min(dp[i][j], AB[i][1]);
      } else {
        dp[i + 1][j] = min(dp[i][j], min(dp[i][j - AB[i][0]] + AB[i][1],
                                         dp[i + 1][j - AB[i][0]] + AB[i][1]));
      }
    }
  }
  cout << dp[N][H] << endl;
  // for (int i = 0; i <= N; i++) {
  //   for (int j = 0; j <= H; j++) {
  //     cout << dp[i][j] << " ";
  //   }
  //   cout << endl;
  // }
}

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

template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char& ch) {
	string s = "";
	s += ch;
	return "'" + s + "', ";
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cout << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL_DEFINE
#define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
   
#define int long long
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
typedef pair<int, int> pii;
const int mod = (int) 1000000007; // 998244353;
const int inf = (int) 2e18;

const int maxn = 1e6 + 10;
int a[maxn], freq[maxn];

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(9);
	#ifdef LOCAL_DEFINE
		freopen("in.txt", "rt", stdin);
	#endif
	
	
	int n;
	cin >> n;
	for(int i = 0; i < n; ++ i)
	{
		cin >> a[i];
		++ freq[a[i]];
	}
	int ans = 0;
	for(int i = 0; i < n; ++ i)
	{
		-- freq[a[i]];
		bool ok = true;
		for(int j = 1; j * j <= a[i]; ++ j)
		{
			if(a[i] % j == 0)
			{
				ok &= (!freq[j]);
				ok &= (!freq[a[i] / j]);
				debug(a[i], j, freq[j], freq[a[i] / j]);
			}
		}
		ans += ok;
		++ freq[a[i]];
	}
	
	cout << ans << '\n';
	
	return 0;
}






Measured memory_bytes: 12924
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int n,m;
int h[2222];
int w[2222];
int a[1500001];
int b[1500001];
int main(void){
  while(cin >> n >> m){
    if(!n) break;
    for(int i = 1; i <= n; i++){
      cin >> h[i];
      h[i] += h[i-1];
    }
    for(int i = 1; i <= m; i++){
      cin >> w[i];
      w[i] += w[i-1];
    }

    memset(a,0,sizeof(a));
    memset(b,0,sizeof(b));
    for(int i = 0; i < n; i++){
      for(int j = i+1; j <= n; j++){
	a[h[j]-h[i]]++;
      }
    }
    for(int i = 0; i < m; i++){
      for(int j = i+1; j <= m; j++){
	b[w[j]-w[i]]++;
      }
    }

    int res = 0;
    for(int i = 1; i <= 1500000; i++){
      res += a[i] * b[i];
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 12904
s = input()
c1 = 1 if s[0] == '0' else 0
a = []
a.append('1')
for i in range(1,len(s)):
  if s[i] == a[len(a)-1]:
    c1+=1
    a.append('0' if s[i]=='1' else '1')
  else:
    a.append(s[i])
    
a = []
a.append('0')
c2 = 1 if s[0]=='1' else 0
for i in range(1,len(s)):
  if s[i] == a[len(a)-1]:
    c2+=1
    a.append('0' if s[i]=='1' else '1')
  else:
    a.append(s[i])
    
    
print(min(c1,c2))
  

    
    



Measured memory_bytes: 4092
count = 0

#クイックソート
def partition(A, p, r):
    x = A[r][1]
    i = p - 1
    for j in range(p, r):
        if A[j][1] <= x:
            i += 1
            a = A[j]
            A[j] = A[i]
            A[i] = a
    a = A[i+1]
    A[i+1] = A[r]
    A[r] = a

    return i+1

def quicksort(A, p, r):
    if p < r:
        q = partition(A, p, r)
        quicksort(A, p, q-1)
        quicksort(A, q+1, r)

#比較のための安定なソートとしてのマージソート
def merge(a, left, mid, right):
    global count
    L = [0] * (mid - left + 1)
    R = [0] * (right - mid + 1)

    for i in range(len(L)):
        if i  == len(L) - 1:
            L[i] = ['A', float('inf')]
        else:
            L[i] = a[left+i]
    
    for i in range(len(R)):
        if i == len(R) - 1:
            R[i] = ['A', float('inf')]
        else:
            R[i] = a[mid+i]

    i = 0
    j = 0
    for k in range(left, right):
        if L[i][1] <= R[j][1]:
            a[k] = L[i]
            i += 1
        else:
            if i != len(L) - 1 and j != len(R) - 1:
                count += len(L) - i - 1
            a[k] = R[j]
            j += 1

def mergeSort(a, left, right):
    if left+1 < right:
        mid = int((left + right) / 2)
        mergeSort(a, left, mid)
        mergeSort(a, mid, right)
        merge(a, left, mid, right)

n = int(input())
A = []
A2 = []
for i in range(n):
    cell = input().split()
    A.append([cell[0], int(cell[1])])
    A2.append([cell[0], int(cell[1])])

quicksort(A, 0, n-1)
mergeSort(A2, 0, n)

flag = 0
for i in range(n):
    if A[i] != A2[i]:
        flag = 1

if flag == 1:
    print('Not stable')
else:
    print('Stable')

for i in range(n):
    print(str(A[i][0]) + ' ' + str(A[i][1]))


Measured memory_bytes: 29996
#include<algorithm>
#include<cmath>
#include<climits>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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

int main()
{
	int K;
	cin >> K;

	string S;
	cin >> S;

	if (S.size() <= K)
	{
		cout << S << endl;
	}
	else
	{
		cout << S.substr(0, K) + "..." << endl;
	}

	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

const int mod = 1000000007;
struct mint {
    ll x;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) {
            x -= mod;
        }
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) {
            x -= mod;
        }
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

int main() {
    ll n, m, k;
    cin >> n >> m >> k;
    vector<mint> nck(k-1, 1);
    rep(i, k-2){
        nck[i+1] = nck[i].x * (n*m-2-i);
        nck[i+1] /= (i+1);
    }
    
    ll ans = m * m * nck[k-2].x % mod;
    ll sum = 0;
    rep(i, n-1){
        (sum += (i+1) * (n-1-i)) %= mod;
    }
    (ans *= sum) %= mod;
    ll cnt = n * n * nck[k-2].x % mod;
    sum = 0;
    rep(i, m-1){
        (sum += (i+1) * (m-1-i)) %= mod;
    }
    (cnt *= sum) %= mod;
    cout << (ans + cnt) % mod << endl;
}

Measured memory_bytes: 1792
let id x = x

let init n f =
  let rec g i ns = if i = 0 then 0 :: ns else g (i - 1) (i :: ns) in
  List.map f (g (n - 1) [])

let (n, x, y) = Scanf.scanf "%d %d %d" @@ fun n x y -> (n, x, y)

let f (i, j) = 
  let rec min' m = function
    | [] -> m
    | x :: xs -> min' (min m x) xs 
  in
  min' max_int [(abs (i - j)); (abs (i - y)) + 1 + (abs (x - j)); (abs (i - x)) + 1 + (abs (y - j))]

let () =
  let k = Array.make (n + 1) 0 in
  for i = 1 to n - 1 do
    for j = i + 1 to n do
      let d = f (i, j) in k.(d) <- k.(d) + 1
    done
  done;
  for i = 1 to n - 1 do
    Printf.printf "%d\n" k.(i)
  done

Measured memory_bytes: 2560
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
#include<iomanip>
#include<map>
#include<iostream>
using namespace std;
int main(){
int n,a[100001]={0},m;
cin>>n>>m;
cout<<(n-1)*(m-1);
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;
}
using ll = long long;
const ll MOD = 1e9 + 7;
const long long INF = 1LL << 60;

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

    ll answer = 0;
    ll goal = 0;
    for (int i = 0; i < int(s.size()); i++)
    {

        if (s.at(i) == 'W')
        {
            if (goal <= i)
            {
            answer += i - goal;
            goal++;
            }
        }
    }

    cout << answer << endl;
}

Measured memory_bytes: 640
#include<stdio.h>
 
int main()
{
	int a,b,c,x,i,j,k,cnt=0;
	scanf("%d%d%d%d",&a,&b,&c,&x);
	for(i=0;i<=a;i++)
	{
		for(j=0;j<=b;j++)
		{
			for(k=0;k<=c;k++)
			{
				if(500*i+100*j+50*k==x)
				{
					cnt++;
				}
			}
		}
	}
	printf("%d\n",cnt);
}

Measured memory_bytes: 128
a, b, k = map(int, input().split())
if b - a + 1 <= k * 2:
  for i in range(a, b + 1):
    print(i)
  exit()
for i in range(k):
  print(a + i)
for i in range(k):
  print(b - k + 1 + i)

Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, X;
  cin >> N >> X;
  vector<int> m(N);
  int minimum = 10000;
  int sum = 0;
  
  for (int i = 0; i < N; i++){
    cin >> m.at(i);
    sum += m.at(i);
    if (m.at(i) < minimum) {
      minimum = m.at(i);
    }
  }
  
  cout << N + (X - sum)/ minimum << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
const int SIZE = 63;
bool bit(long long n, int i){
    return (n>>i)&1;
}
int main(){
    long long n; cin >> n;
    long long dp[SIZE][3] = {0};
    dp[SIZE-1][0] = 1;
    for (int i = SIZE-1; i > 0; i--)
    {
        for (int j = 0; j < 3; j++)
        {
            for (int k = 0; k < 3; k++)
            {
                if (2*j-k+bit(n,i-1) < 0){
                    continue;
                }
                if (2*j-k+bit(n,i-1) > 2){
                    dp[i-1][2] += dp[i][j];
                    dp[i-1][2] %= mod;
                    continue;
                }
                dp[i-1][2*j-k+bit(n, i-1)] += dp[i][j];
                dp[i-1][2*j-k+bit(n, i-1)] %= mod;
            }
        }
    }
    
    cout << (dp[0][0]+dp[0][1]+dp[0][2])%mod << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;cin>>n;
  int k;cin>>k;
  vector<int> v(n);
  for(int i=0;i<n;i++){
    int x;cin>>x;
    v[i]=x;
  }
  vector<int> c(n);
  c[0]=0;c[1]=abs(v[0]-v[1]);
  for(int i=2;i<n;i++){
      c[i]= INT_MAX;
    for(int j=1;j<=k&&i-j>=0;j++){
      c[i]=min(c[i-j]+abs(v[i]-v[i-j]),c[i]);
    }
  }
  cout<<c[n-1];
}


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


void solve(long long N){
  vector<long long> yakusu({24, 30, 40, 42, 54, 56, 66, 70, 78, 88, 102, 104, 105, 110, 114, 128, 130, 135, 136, 138, 152, 154, 165, 170, 174, 182, 184, 186, 189, 190, 195});

  cout << count_if(yakusu.begin(), yakusu.end(), [&](auto a) { return ((a % 2) == 1) && a <= N; }) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
  scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] heights = new int[n];
		for (int i = 0; i < n; i++) {
			heights[i] = sc.nextInt();
		}
		int ans = 0;
		Stack<Integer> stack = new Stack<>();
		for (int i = 0; i < n; i++) {
			while (!stack.isEmpty() && heights[i] >= stack.peek()) {
				stack.pop();
			}
			if (stack.isEmpty()) {
				ans++;
			}
			stack.push(heights[i]);
		}
		System.out.println(ans);
	}
}

 
 

 
 
 
 


Measured memory_bytes: 35532
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AOJ1_10_D
{
    class Program
    {

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] x_str = Console.ReadLine().Split(' ');
            string[] y_str = Console.ReadLine().Split(' ');
            double[] x = new double[n];
            double[] y = new double[n];
            double DInfinity = 0;
            for (int i = 0; i < n; i++)
            {
                x[i] = double.Parse(x_str[i]);
                y[i] = double.Parse(y_str[i]);
                DInfinity = Math.Max(Math.Abs(x[i] - y[i]), DInfinity);
            }

            Console.WriteLine(CalcDistance(n, x, y, 1));
            Console.WriteLine(CalcDistance(n, x, y, 2));
            Console.WriteLine(CalcDistance(n, x, y, 3));
            Console.WriteLine(DInfinity);

        }
        public static double CalcDistance(double n, double[] x, double[] y, double p)
        {
            double Distance = new double();
            double xminusy;
            for (long i = 0; i < n; i++)
            {
                xminusy = x[i] - y[i];
                xminusy = Math.Pow(xminusy, p);
                Distance += Math.Abs(xminusy);
            }
            Distance = Math.Pow(Distance, 1 / p);
            return Distance;
        }
    }
}





Measured memory_bytes: 18004
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstring>
#include<map>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

const int MAXI = 8, MAXJ = 60, INF = (1 << 28) - 1;

int w[] = {2, 3, 5, 10, 12, 15};
int v[] = {380, 550, 850, 1520, 1870 , 2244};
//int v[] = {380, 550, 850, 380*5 * 8 /10, 550*4*85/100, 850*3*88/100};
int dp[MAXI][MAXJ];

int main()
{
    memset(dp, INF, sizeof(dp));
    rep(j,MAXJ) dp[0][j] = INF;
    rep(i,MAXI) dp[i][0] = 0;


    REP(6)for(int j = 1;j<51;j++)
    {
        if(j - w[i] >= 0)dp[i+1][j] = min(dp[i][j], dp[i + 1][j - w[i]] + v[i]);
        else dp[i+1][j] = dp[i][j];
    }
    //rep(i,7){ rep(j,51) cout<< dp[i][j] <<" " ; cout << endl;}

    int wei;
    while(cin >> wei && wei)cout << dp[6][wei / 100] << endl;

    
    return 0;
}

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

    ll N;
    double D;
    cin >> N >> D;
    vector<ll> X(N), Y(N);
    rep(i, N) { cin >> X[i] >> Y[i]; }

    ll cnt = 0;
    rep(i, N) {
        double dist = sqrt(X[i] * X[i] + Y[i] * Y[i]);
        if (dist <= D) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 6436
#include <iostream>
#include <bitset>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>

using namespace std;

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<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--)

int main()
{
	ll n;
	string s, ans = "No";

	cin >> s;

	if (s[0] == '7' || s[1] == '7' || s[2] == '7')
		ans = "Yes";


	cout << ans << endl;

}

Measured memory_bytes: 3624
# AOJ 0053: Sum of Prime Numbers
# Python3 2018.6.15 bal4u

MAX = 104729  # 10000th prime
SQRT = 323    # sqrt(MAX)

prime = [True for i in range(MAX+2)]
def sieve():
	for i in range(2, MAX, 2):
		prime[i] = False
	for i in range(3, SQRT, 2):
		if prime[i] is True:
			for j in range(i*i, MAX, i):
				prime[j] = False

sieve()
sum = [0 for i in range(MAX+2)]
j = sum[1] = 2;
for i in range(3, MAX+1, 2):
	if prime[i]:
		sum[j] = sum[j-1] + i
		j += 1

while True:
	n = int(input())
	if n == 0: break
	print(sum[n])


Measured memory_bytes: 7428
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <ctime>
#include <cstring>
using namespace std;

int n;
int MAX = 15;
int p[16][16];
bool up[16][16];
bool ri[16][16];
int matatabi;

int main(void){

	cin >> n;
	for(int i = 0; i < n; i++){
		int x_g, y_g;
		cin >> x_g >> y_g;
		for(int j = 0; j <= x_g; j++){
			for(int k = 0; k <= y_g; k++){
				p[j][k] = 0;
				up[j][k] = true;
				ri[j][k] = true;
			}
		}

		p[0][0] = 1;

		cin >> matatabi;
		for(int j = 0; j < matatabi; j++){
			int x1, y1, x2, y2;
			cin >> x1 >> y1 >> x2 >> y2;
			if(x1 == x2){
				up[x1][min(y1, y2)] = false;
			}else{
				ri[min(x1, x2)][y1] = false;
			}
		}

		for(int j = 0; j <= x_g; j++){
			for(int k = 0; k <= y_g; k++){
				if(j + k != 0){
					if(j == 0){
						if(up[j][k - 1]){
							p[j][k] += p[j][k - 1];
						}
					}else if(k == 0){
						if(ri[j - 1][k]){
							p[j][k] += p[j - 1][k];
						}
					}else{
						if(up[j][k - 1]){
							p[j][k] += p[j][k - 1];
						}
						if(ri[j - 1][k]){
							p[j][k] += p[j - 1][k];
						}
					}
				}
			}
		}



		if(p[x_g][y_g] == 0){
			cout << "Miserable Hokusai!" << endl;
		}else{
			cout << p[x_g][y_g] << endl;
		}
		


	}

    return 0;
}

Measured memory_bytes: 1160
from collections import deque

def main():
    h, w = map(int, input().split())
    ls = [input() for _ in range(h)]

    def trans(a, b):
        return a * w + b

    ls2 = [[] for _ in range(h * w)]

    for i in range(h):
        for j in range(w):
            # check ij
            if ls[i][j] == '#':
                continue
            if i >= 1 and ls[i-1][j] != '#':
                ls2[trans(i, j)].append(trans(i-1, j))
            if i <= h-2 and ls[i+1][j] != '#':
                ls2[trans(i, j)].append(trans(i + 1, j))
            if j <= w-2 and ls[i][j+1] != '#':
                ls2[trans(i, j)].append(trans(i, j + 1))
            if j >= 1 and ls[i][j-1] != '#':
                ls2[trans(i, j)].append(trans(i, j - 1))


    #print(ls2)


    def route(i):
        count = 1
        ss = deque(ls2[i])
        next = deque()
        explored = {i}
        while ss or next:
            if not ss:
                count +=1
                ss = next
                next = deque()
            now =ss.popleft()
            if now in explored:
                continue
            else:
                explored.add(now)
                next.extend(ls2[now])
        return count-1
    ans = 0
    for i in range(h * w - 1):
        if ls2[i] == []:
            continue
        ans = max(ans, route(i))

    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 74356
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <complex>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <valarray>

using namespace std;


main()
{
    int n; cin>>n;
    vector<tuple<int,int,int>> sta(n-1);
    for(int i=0;i+1<n;++i)
    {
        int x,y,z; cin>>x>>y>>z;
        sta[i]=tie(x,y,z);
    }
    for(int i=0;i<n;++i)
    {
        int now=0;
        for(auto&s:sta)
        {
            int x,y,z; tie(x,y,z)=s;
            if(now<y) now=y;
            now=(now+z-1)/z*z;
            now+=x;
        }
        cout << now << "\n";
        sta.erase(sta.begin());
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    int A, B, C, K;
    cin >> A >> B >> C >> K;
    string res = "Yes";
    int cnt = 0;
    while (B <= A) {
        ++cnt;
        B *= 2;
    }
    while (C <= B) {
        ++cnt;
        C *= 2;
    }
    if (cnt > K) {
        res = "No";
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3652
#include <stdio.h>

int main() {
  int operand_a, operand_b, answer;
  char ch;
  scanf("%d %c %d", &operand_a, &ch, &operand_b);
  if(ch == '+') {
    answer = operand_a + operand_b;
  } else if(ch == '-') {
    answer = operand_a - operand_b;
  }
  printf("%d\n", answer);
  return 0;
}


Measured memory_bytes: 128
/*

Sviatoslav Bidzilia 2019
CF: anakib1

*/

#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <cstring>
#include <string>
#include <cstdlib>
#include <vector>
#include <bitset>
#include <map>
#include <chrono>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <queue>
#include <ctime>
#include <stack>
#include <set>
#include <list>
#include <deque>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdarg.h>
#include <utility>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unisgned long long
#define ld long double
#define all(a) a.begin(), a.end()
#define SORT(a) sort(all(a))
#define pii pair<int, int>
#define tii triple<int, int, int>
#define e 1e-7
#define PI acos(-1)
#define inf 1e17
#define vi vector<int>
#define F first
#define S second
#define rng(x) for(int _ = 0; _ < (x); _++)
#define rngi(i, x) for(int i = 0; i < (x); i++)
#define rngsi(s, i, x) for(int i = (s); i <(x); i++)
#define int long long

template<typename A, typename B, typename C>
struct triple
{
	A X;
	B Y;
	C Z;
	triple(A a = 0, B b = 0, C c = 0) :X(a), Y(b), Z(c) {}
};
template<typename A, typename B, typename C>
triple<A, B, C> make_triple(A a = 0, B b = 0, C c = 0)
{
	return triple<A, B, C>(a, b, c);
}
template<typename A, typename B, typename C>
bool operator<(const triple<A, B, C>& a, const triple<A, B, C>& b)
{
	if (a.X != b.X)
		return a.X < b.X;
	if (a.Y != b.Y)
		return a.Y < b.Y;
	return a.Z < b.Z;
}
template<typename T, typename SS>
ostream& operator<<(ostream& ofs, const pair<T, SS>& p)
{
	ofs << "( " << p.F << " , " << p.S << " )";
	return ofs;
}
template<typename T>
void print(T a)
{
	for (auto i : a)
		cout << i << ' ';
	cout << '\n';
}
template<typename T>
T max(T a, T b, T c)
{
	return max(a, max(b, c));
}
template<typename T>
T min(T a, T b, T c)
{
	return min(a, min(b, c));
}
struct custom_hash
{
	static uint64_t splitmix64(uint64_t x)
	{
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}

	size_t operator()(uint64_t x) const
	{
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
};
signed main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	srand(time(NULL));
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(false);
	int n, d, a;
	cin >> n >> d >> a;
	vi x(n), h(n);
	rngi(i, n)
		cin >> x[i] >> h[i];
	set<pii> events;
	rngi(i, n)
		events.insert(mp(x[i], i));
	int now = 0;
	int use = 0;
	while (events.size())
	{
		pii b = *events.begin();
		events.erase(events.begin());
		if (b.second < 0)
			now += b.second;
		else
		{
			int hp = h[b.second];
			if (now >= hp)
				continue;
			hp -= now;
			int cz = (hp + a - 1) / a;
			use += cz;
			now += cz * a;
			events.insert(mp(b.first + 2 * d + 1, -cz * a));
		}

	}
	cout << use << '\n';
}

Measured memory_bytes: 15872
A, B = map(int, input().split())
S = input()
ans = "Yes"
if S[A] != "-":
    ans = "No"
if any([c == '-' for c in S[:A]]):
    ans = "No"
if any([c == '-' for c in S[A+B:]]):
    ans = "No"
print(ans)


Measured memory_bytes: 3060
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    int[] inf = new int[N+1];
    int now = 0;
    int paint = 1;
    int[] ans = new int[N-1];
    int max = 0;
    int[][] val = new int[N-1][4];
    for(int i = 0; i < N-1; i++){
      String[] S = sc.nextLine().split(" ");
      val[i][0] = Integer.parseInt(S[0]);
      val[i][1] = Integer.parseInt(S[1]);
      val[i][2] = i;
    }
    Arrays.sort(val, (a,b)->Integer.compare(a[0],b[0]));
    
    for(int i = 0; i < N-1; i++){
      int a = val[i][0];
      int b = val[i][1];
      if(a == now){
        paint++;
      }else{
        now = a;
        paint = 1;
      }
      if(inf[a] == paint){
        paint++;
      }
      val[i][3] = paint;
      inf[b] = paint;
      if(max < paint){
        max = paint;
      }
    }
    
    Arrays.sort(val, (a,b)->Integer.compare(a[2],b[2]));
    System.out.println(max);
    for(int[] n : val){
      System.out.println(n[3]);
    }
  }
}

Measured memory_bytes: 138540