akhauriyash/Code-Regression huggingface dataset:
from itertools import accumulate
from collections import Counter
from operator import mul
from functools import reduce
 
def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under
 
 
n,*a=map(int,open(0).read().split())
b=list(accumulate(a))
print(sum(cmb(v,2)for k,v in Counter(b).items() if v>1)+b.count(0))

Measured memory_bytes: 41596
package main

import (
	"fmt"
)

func main() {

	var N int
	fmt.Scanf("%d", &N)

	var A, flag int
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &A)
		if A%2 == 0 && (A%3 != 0 && A%5 != 0) {
			flag = 1
		}
	}

	if flag == 1 {
		fmt.Println("DENIED")
	} else {
		fmt.Println("APPROVED")
	}

}


Measured memory_bytes: 1836
#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

const int MAX = 2000000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  int N; cin >> N; ll fact[N+10]; fact[0] = 1;
  rep(i, N+9){
    fact[i+1] = fact[i]*(i+1)%mod;
  }
  COMinit();
  ll ans = fact[N-1]*(N-1)%mod;
  if(N%2==0){
    int k = 1;
    for(int i=(N-3); i>=(N-2)/2; i--){
      ans-=((COM(i, k)*fact[i+1])%mod)*fact[N-i-2]%mod; 
      if(ans<0) ans+=mod; ans%=mod; k++;
    }
    cout << ans << endl; return 0;
  }
  int k = 1;
  for(int i=(N-3); i>=N/2; i--){
    ans-=((COM(i, k)*fact[i+1])%mod)*fact[N-i-2]%mod;
    if(ans<0) ans+=mod; ans%=mod; k++;
  }
  cout << ans << endl; 
}

Measured memory_bytes: 54912
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <map>
#include <algorithm>  // std::unique
#include <cmath>
#include <limits.h>
#include <queue>
#include <unordered_map>
#include <sstream>      // std::ostringstream
#include <bitset>
#include <iomanip>
#include <functional>
#include <set>
#include <list>

#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;

using ll = long long;
constexpr auto PrimeBigNum10_9_7 = 1000000007;
const long long INF = 1LL << 60;

#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define repb(i,a,b) for(ll i=a;i>=b;--i)

template <typename T>
void DisplayAnswer(const T& v) {
	cout << v << endl;
}
template <typename T>
void DisplayAnswers(const vector<T>& vs) {
	for (const auto& v : vs) {
		cout << v << endl;
	}
}

template <typename T>
void DisplayAnswerOneLine(const vector<T>& vs) {
	for (const auto& v : vs) {
		cout << v << ' ';
	}
	cout << endl;
}


std::vector<std::string> split(const std::string &str, char sep)
{
	std::vector<std::string> v;
	std::stringstream ss(str);
	std::string buffer;
	while (std::getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}



template<class T>
void chmin(T& a, T b) {
	if (a > b) {
		a = b;
	}
}


// 素数判定
template <typename T>
bool IsPrimeNumber(T value) {

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

// 桁数判定
template <typename T>
T GetFigureLength(T value) {
	T figure = 1;
	while (value >= 10) {
		value /= 10;
		++figure;
	}
	return figure;
}

// 素因数分解結果
template <typename T>
map<T, T> GetPrimeFactorize(T value) {

	map<T, T> res;

	for (T i = 2; i * i <= value; ++i) {
		if ((value%i) != 0)	continue;

		T count = 0;
		while ((value % i) == 0) {
			value /= i;
			++count;
		}

		res[i] = count;
	}

	if (value != 1) {
		res[value] = 1;
	}
	return res;
}


void DebugPrint(const vector<ll>& vec) {
	cout << "{";
	for (auto itr = vec.begin(); itr != vec.end(); ++itr) {
		cout << *itr << ",";
	}
	cout << "}" << endl;
}

// valueが2のx乗以下である計算
ll calc2x(ll value) {
	ll n = 0;
	while (value > 0) {
		value /= 2;
		++n;
	}
	return n;
}
int main(void) {

	ll N;
	cin >> N;

	vector<map<char, ll>> vec(N);

	for (ll i = 0; i < N; ++i) {
		string str;
		cin >> str;
		for (const auto& c : str) {
			vec[i][c]++;
		}
	}

	string answer = "";
	for (char c = 'a'; c <= 'z'; ++c) {
		
		ll n = 100;
		for (const auto& v : vec) {
			if (v.count(c) > 0) {
				n = min(n, v.at(c));
			}
			else {
				n = 0;
				break;
			}
		}
		for (ll i = 0; i < n; ++i) {
			answer.push_back(c);
		}
	}

	cout << answer << endl;

	
	return 0;
}


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

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

    long long int rem = 0;
    for(int i=0; i<=k; i++){
        rem = rem * 10 + 7;
        rem %= k;
        if(rem == 0){
            cout << i+1 << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

bool range(ll x, ll a, ll b)
{
        return a <= x and x <= b;
}

ll getid(ll n)
{
        if (range(n, 1, 399)) return 1;
        if (range(n, 400, 799)) return 2;
        if (range(n, 800, 1199)) return 3;
        if (range(n, 1200, 1599)) return 4;
        if (range(n, 1600, 1999)) return 5;
        if (range(n, 2000, 2399)) return 6;
        if (range(n, 2400, 2799)) return 7;
        if (range(n, 2800, 3199)) return 8;
        if (n >= 3200) return -1;
}

int main()
{
        ll N;
        cin >> N;
        vll a(N);
        rep(i, 0, N) cin >> a[i];
        ll tmp = 0;
        set<ll> s;
        rep(i, 0, N) {
                if (getid(a[i]) == -1) ++tmp;
                else s.insert(getid(a[i]));
        }
        if (len(s) == 0) {
                cout << 1 << ' ' << tmp << endl;
                return 0;
        }
        cout << len(s) << ' ' << len(s) + tmp << endl;
}

Measured memory_bytes: 3544
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int ceil(int a, int b) {
	return a/b + (a % b != 0);
}

int main() {
	int n, k; scanf("%d %d", &n, &k);
	int onePlace = -1;
	for (int i = 0; i < n; ++i) {
		scanf("%d", &onePlace);
		if (onePlace == 1) {
			onePlace = i;
			break;
		}
	}
	int ans = 1000000000;
	for (int start = 0; start + k <= n; ++start) {
		if (!(start <= onePlace and onePlace < start + k)) continue;
		int leftOp = ceil(start, k - 1);
		int rightOp = ceil(n - (start + k), k - 1);
		// printf("val %d is %d %d %d\n", start, leftOp, rightOp, n - (start + k));
		ans = min(ans, leftOp + rightOp + 1);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>

#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}


int main(void) {

	int n, h, w;
	cin >> n >> h >> w;

	COUT((n - h + 1) * (n - w + 1));





	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define mp make_pair
#define pb(x) push_back(x)
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mll map<long long, long long>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define flsh fflush(stdout)
#define gcd __gcd
#define clr(x) memset(x, 0, sizeof(x))
#define mod 1000000007LL
#define mod2 998244353LL
#define INF 1000000000007
 

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> o_tree;


void solve()
{
   ll n,m;
   cin>>n>>m;
   ll i,j;
   ll a[n];
   ll b[n];
   vll v;
   for(i=0;i<n;i++)
   {
       cin>>a[i];
    //    v.pb(a[i]/2);
       b[i]=a[i]/2;
   }

   ll no = b[0];
   for(i=1;i<n;i++)
   {
       no = (no*b[i])/gcd(no,b[i]);
   }
   for(i=0;i<n;i++)
   {
       if(no%a[i]!=b[i])
       {
           cout<<"0\n";
           return;
       }
   }
//    cout<<no<<"\n";
   ll res =m/no;
   cout<<(res+1)/2<<"\n";
//    
   



   
}


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


if (fopen("input.txt","r" ))
  {
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
  }
cout<<setprecision(20);


ll t=1;


// cin>>t;


while(t--)
{
solve();
} 


return 0;
}

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

int main() {
    string S;
    cin>>S;
    vector<long long> left_count(S.size()+1,0);
    vector<long long> right_count(S.size()+1,0);
    long long count =0;
    rep(i,S.size()){
        if (S[i]=='<'){
            count++;
        }else{
            count =0;
        }
        left_count[i+1]=count;
    }

    count = 0;
    rep(j,S.size()){
        if (S[S.size()-1-j]=='>'){
            count++;
        }else{
            count = 0;
        }
        right_count[S.size()-1-j]=count;
    }
    long long ans =0;
    rep(k,S.size()+1){
        ans+=max(left_count[k],right_count[k]);
    }
    cout << ans << endl;
}

//18:00-18:38 miss1

Measured memory_bytes: 8708
fun main(args: Array<String>) {
    val N = readInputLine().toInt()

    val arr = Array<Pair<String, Int>>(N) { val (s, t) = readInputLine().split(" "); Pair(s, t.toInt()) }
    val X = readInputLine()

    var start = false
    var ans = 0

    for (a in arr) {
        val (s, t) = a
        if (start) {
            ans += t
        }
        if (X == s) {
            start = true
        }
    }

    println(ans)
}

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


Measured memory_bytes: 38056
#include<stdio.h>

int main(void){
    int i, n, F[45] = {};
    scanf("%d", &n);

    F[0] = 1;
    F[1] = 1;

    for(i=2;i<=n;i++) F[i] = F[i-2] + F[i-1];

    printf("%d\n", F[n]);

    return 0;
}




Measured memory_bytes: 2724
from _collections import deque
S = deque(input())
Q = int(input())
dir = 1

for i in range(Q):
    query = list(input().split())
    if len(query) == 1:
       dir *= -1
    else:
        T, f, c = query
        if int(f) == 1:
            if dir == 1:
                S.appendleft(c)
            else:
                S.append(c)
        else:
            if dir == 1:
                S.append(c)
            else:
                S.appendleft(c)
if dir == -1:
    S.reverse()
print(''.join(S))

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

int main() {
    vector<int> num(3);
    cin >> num[0] >> num[1] >> num[2];
    sort(num.begin(), num.end());
    cout << num[0] << " " << num[1] << " " << num[2] << endl;
}


Measured memory_bytes: 3144
#include<iostream>
#include<cstdio>
using namespace std;
int A, B, C;
bool ans;
int main()
{
	cin >> A >> B >> C;
	if (C == 1 || (A == 1 && B == 1))ans = true;
	else ans = false;
	if (ans)printf("Open\n");
	else printf("Close\n");
	return 0;
}

Measured memory_bytes: 1116
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <string>
using namespace std;

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

  string month = S.substr(5,2);
  if(month == "01" || month == "02" || month == "03" || month == "04"){
    cout << "Heisei" << "\n";
  }else{
    cout << "TBD" << "\n";
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
vector<int> g[100000];
vector<int> c(100000);

void dfs(int v, int col) {
    c[v] = col;
    for (int i = 0; i < g[v].size(); ++i) {
        if(c[g[v][i]] == 0) dfs(g[v][i], col);
    }
}

int main() {
    int n, m, q;
    cin >> n>> m;
    for (int i = 0; i < m; ++i) {
        int v, w;
        cin >> v >> w;
        g[w].push_back(v);
        g[v].push_back(w);
    }

    for (int k = 0; k < n; ++k) {
        c[k] = 0;
    }

    int col = 1;
    for (int j = 0; j < n; ++j) {
        if(!c[j]) {
            dfs(j, col);
            col++;
        }
    }

    cin >> q;
    for (int l = 0; l < q; ++l) {
        int v,w;
        cin >> v >> w;
        if(c[v] == c[w]) cout << "yes";
        else cout << "no";
        cout << endl;

    }


    return 0;
}



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

int N, K;
const int MAX_N = 100000;
int A[MAX_N];

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

    cout << (N-1+(K-2))/(K-1) << endl;

    return 0;
}

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

// input
int K, S;


void input() {
    cin >> K >> S;
}


int main() {
    input();
    int ans = 0;
    rep(x, K + 1) rep(y, K + 1) {
        int z = S - (x + y);
        if (0 <= z && z <= K) ans++;
    }
    cout << ans << endl;
}


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

#define INF 1000000010
#define INFLL ((1LL<<62)-5)
#define FO(i,a,b) for (int (i) = (a); (i) < (b); ++(i))
#define OF(i,a,b) for (int (i) = (a)-1; (i) >= (b); --(i))
#define SZ(v) int(v.size())

using namespace std;
//PAIRS:
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pii;
typedef long long ll;

/*~~~~TEMPLATE END~~~~*/

int N, K;
int a[100005];
vector <int> temC[100005];
vector <int> allC[100005];
int par[100005];

int ans;

void buildTree (int c) {
    for (int nxt : temC[c]) {
        if (nxt == c || nxt == 0) continue;
        allC[c].push_back (nxt);
        par[nxt] = c;
        buildTree (nxt);
    }
}

int getAns (int c) {
    int mxD = 0;
    for (int nxt : allC[c]) mxD = max (mxD, getAns(nxt));
    if (mxD == K-1 && c != 0 && par[c] != 0) {
        ans++;
        mxD = 0;
    } else {
        mxD++;
    }
    return mxD;
}



int main() {
    scanf ("%d %d", &N, &K);
    FO (i,0,N) {
        scanf ("%d", &a[i]);
        a[i]--;
        temC[a[i]].push_back (i);
    }
    ans += (a[0] != 0);
    buildTree (0);
    getAns(0);
    printf ("%d\n", ans);
    return 0;
}


Measured memory_bytes: 18176
// Marcin Knapik
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using namespace std;

// #include <ext/pb_ds/assoc_container.hpp> // order_of_key
// #include <ext/pb_ds/tree_policy.hpp> // find by order
// using namespace __gnu_pbds; 
// #define ordered_set tree< int , null_type,less< int >, rb_tree_tag,tree_order_statistics_node_update>  

// const ll MAX_LL = 0xFFFFFFFFFFFFFFFF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define losuj(a, b) uniform_int_distribution<ll>(a, b)(rng)

typedef long double             ld;
typedef long long               ll;
typedef pair<int, int>          ii;
typedef vector<int>             vi;
typedef vector<ll>              vll;
typedef vector<vll>             vvll;
typedef vector<ii>              vii;
typedef vector<vi>              vvi;
typedef vector<vii>             vvii;
#define pll pair<long long, long long>
#define ull unsigned long long

#define sz(a)                   (int)(a).size()
#define pb                      push_back
#define all(c)                  (c).begin(), (c).end()
#define rall(c)                 (c).rbegin(), (c).rend()
#define FOR(i, a)               for (int i = 0; i < (a); i++)
#define f                       first
#define s                       second

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

template<class T> inline T fast(T a,T b,T mod) {ll res = 1; while(b){if(b&1) res = (res*a)%mod;a = (a*a)%mod;b >>= 1;}return res;}
template<class T> istream &operator>>(istream &os, vector<T> &container){for (auto &u : container)os >> u;return os;}
template<class T> ostream &operator<<(ostream &os, const vector<T> &container){for (auto &u : container)os << u << " ";return os;}
template<class T> inline T gcd(T a, T b) { while (b)swap(a %= b, b); return abs(a); }

const ll INF = 1e9 + 7;
const ll mod = 998244353;
const ll BIG_INF = 1e18 + 7;
const ll N = 1e8+7;
const ll T = 1<<20;
const ld inf = 1e18;

ll m, n, k, l, q;

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

	string s;
	cin >> s;
	cout << s.substr(0, 3) << '\n';
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m;scanf("%d%d",&n,&m);
	int l=1,r=m+1;
	while(l<r)printf("%d %d\n",l++,r--);
	l=m+2,r=2*m+1;
	while(l<r)printf("%d %d\n",l++,r--);
	return 0;
}

Measured memory_bytes: 3800
#pragma GCC optimize("O3")
#define _GLIBCXX_DEBUG

#include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define endl '\n'
#define fcout cout << fixed << setprecision(15)

#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

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

using ll    = long long;
using ld    = long double;
using Pii   = pair<int, int>;
using Pll   = pair<ll, ll>;

constexpr int MOD       = (int)1e9 + 7;
constexpr int INF_int   = (int)(1 << 30);
constexpr ll INF_ll     = (ll)1e18 + 1;
constexpr ld PI         = 3.141592653589793L;

template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
//vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };

/*追加部分*/



/*main関数*/

signed main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    
    int n, d, ans = 0; cin >> n >> d;
    rep(i, n){
        int x, y;
        cin >> x >> y;
        if(hypot(x, y) <= d) ans++;
    }

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

Measured memory_bytes: 3692
#[allow(unused_imports)]
use {
   proconio::{fastout, input, marker::*},
   std::cmp::*,
   std::collections::*,
};

#[fastout]
fn main() {
   input! {
      n: usize,
      xyp: [(i64, i64, i64); n]
   }

   let num = 1 << n;
   let mut tx = vec![vec![0i64; n]; num];
   let mut ty = vec![vec![0i64; n]; num];
   for s in 0..num {
      let mut xs = vec![];
      let mut ys = vec![];
      for i in 0..n {
         if (s >> i) & 1 == 1 {
            let (x, y, _) = xyp[i];
            xs.push(x);
            ys.push(y);
         } 
      }
      for i in 0..n {
         if (s >> i) & 1 == 1 {
            continue;
         }
         let (x, y, p) = xyp[i];
         let mut dx = x.abs();
         let mut dy = y.abs();
         for (xn, yn) in xs.iter().zip(ys.iter()) {
            dx = min(dx, (x - xn).abs());
            dy = min(dy, (y - yn).abs());
         }
         tx[s][i] = p * dx;
         ty[s][i] = p * dy;
      }
   }

   let mut ans = vec![std::i64::MAX; n + 1];
   let num: usize = (0..n).fold(1_usize, |acc, _| acc * 3);
   for _s in 0..num {
      let mut s1 = 0;
      let mut s2 = 0;
      let mut s = _s;
      let mut k = n;
      for i in 0..n {
         if s % 3 == 1 {
            s1 += 1 << i;
         } else if s % 3 == 2 {
            s2 += 1 << i;
         } else {
            k -= 1;
         }
         s /= 3;
      }
      let score = (0..n).map(|i| min(tx[s1][i], ty[s2][i])).sum();
      ans[k] = min(ans[k], score);
   }
   for a in ans {
      println!("{}", a);
   }
}


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

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

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  string s;
  cin >> s;
  rep(i,s.size()-1){
    if(s[i] == 'A' && s[i+1] == 'C'){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
INF =  float("inf")
import bisect
import statistics

N = int(input())
a = list(map(int, input().split()))

for i in range(N):
    a[i] = a[i] - i

def f(k):
    return sum(map(lambda x: abs(x-k), a))

c = statistics.median(a)
print(int(f(c)))




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

int main(void){
  int i,N,S,K;
  S = 1;
  cin >> N >> K;
 while (i <  N){
   if (S <= K){
     S = 2 * S;
   }
   else{
     S = S + K;
   }
   i++;
 }
  cout << S << endl;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int m;
	cin>>m;
	long long sum=0,br=0;
	for(int i=0;i<m;i++) {long long t1,t2; cin>>t1>>t2; br+=t2; sum+=t1*t2;}
	cout<<br-1+(sum-1)/9;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, x, ans = 0;
  cin >> a >> b >> c >> x;
  for(int i = 0; i <= a; i++) {
    for(int j = 0; j <= b; j++) {
      if(x -500*i -100*j <= 50*c and x -500*i -100*j >= 0)
        ans++;
    }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>

using namespace std;

#define l first
#define r second

pair<int, int> a[5000000];
int ans = 0;

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i].l >> a[i].r;
    int mx = 0, mxl = 0, mnr = 1e9;
    for (int i = 0; i < n; i++)
    {
        mx = max(mx, a[i].r - a[i].l + 1);
        mxl = max(mxl, a[i].l);
        mnr = min(mnr, a[i].r);
    }
    ans = max(0, mnr - mxl + 1) + mx;
    int ans2 = 0;
    sort(a, a + n);
    map<int, int> pe;
    for (int i = n - 1; i >= 0; i--)
    {
        int lk = a[i].l;
        ans2 = max(ans2, mnr - lk + 1 + (*pe.begin()).first - mxl + 1);
        pe[a[i].r]++;
    }
    cout << max(ans2, ans);
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
    // Write Your Code Below
    int n; cin >> n;
    int x; cin >> x;
    int ans = 0;
    while(n!=0||x!=0){
        for(int i=0;i<n-2;i++){
            int p = i+1;
            for(int j=p;j<n-1;j++){
                int q = j+1;
                for(int k=q;k<n;k++){
                    int r = k+1;
                    if(p+q+r==x){
                        ans++;
                    }
                }
            }
        }
        cout << ans << endl;
        ans = 0;
        cin >> n >> x;
    }
}



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

namespace ABC112A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, n;

            
             n = int.Parse(Console.ReadLine());

            if (n == 1)
                Console.WriteLine("Hello World");

            else if (n == 2)
            {
                a = int.Parse(Console.ReadLine());
                b = int.Parse(Console.ReadLine());
                Console.WriteLine(a + b);
            }
           
             Console.ReadKey();

        }
    }
}


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

int main() {
  long long N;
  cin >> N;
  
  int digit = log10(N) + 1;
  for (int i = 2; i <= sqrt(N); i++) {
    if (N % i == 0) {
      int dd = log10(N / i) + 1;
      digit = min(digit, dd);
    }
  }
  
  cout << digit << endl;
}


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



int main(){
    int N;
    cin>>N;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin>>A.at(i);
    }
    bool flag=true;
    for(int i=0;i<N;i++){
        
            if(A.at(i)%2==0&&A.at(i)%3!=0&&A.at(i)%5!=0){
                flag=false;
            
        }
    }
    if(flag){
        cout<<"APPROVED"<<endl;
    }else{
        cout<<"DENIED"<<endl;
    }
}

Measured memory_bytes: 3564
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#include <numeric>
#include <string.h>
#define int long long
#define double long double
#define oku7 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用

using namespace std;
std::mt19937 mt((int)time(0));

int dx[4] = { 0, 1, 0, -1 }; // x軸方向への変位
int dy[4] = { 1, 0, -1, 0 }; // y軸方向への変位

char cases[4][100001];
int N;
string s;

int getNextIndex(int now, int mod) {
	return (now + 1) % mod;
}
int getPrevIndex(int now, int mod) {
	return (now + mod - 1) % mod;
}

bool chk(int casenum, int index) {

	int next = getNextIndex(index, N);
	int prev = getPrevIndex(index, N);
	if (s[index] == 'o') {
		if (cases[casenum][index] == 'S' && cases[casenum][next] == cases[casenum][prev]) {
			return true;
		}
		if (cases[casenum][index] == 'W' && cases[casenum][next] != cases[casenum][prev]) {
			return true;
		}
	}
	else {
		if (cases[casenum][index] == 'S' && cases[casenum][next] != cases[casenum][prev]) {
			return true;
		}
		if (cases[casenum][index] == 'W' && cases[casenum][next] == cases[casenum][prev]) {
			return true;
		}
	}
	return false;
}

signed main() {

	cin >> N >> s;
	strcpy(cases[0], "SS");
	strcpy(cases[1], "SW");
	strcpy(cases[2], "WS");
	strcpy(cases[3], "WW");
	bool flag = false;

	for (int i = 0; i < 4; i++) {
		int nowIndex = 1;
		while (cases[i][getNextIndex(nowIndex, N)] == '\0') {
			if (cases[i][nowIndex] == 'S') {
				if (s[nowIndex] == 'o') {
					cases[i][nowIndex + 1] = cases[i][nowIndex - 1];
				}
				else if(cases[i][nowIndex-1] == 'S'){
					cases[i][nowIndex + 1] = 'W';
				}
				else {
					cases[i][nowIndex + 1] = 'S';
				}
			}
			else {
				if (s[nowIndex] == 'x') {
					cases[i][nowIndex + 1] = cases[i][nowIndex - 1];
				}
				else if (cases[i][nowIndex - 1] == 'S') {
					cases[i][nowIndex + 1] = 'W';
				}
				else {
					cases[i][nowIndex + 1] = 'S';
				}
			}
			nowIndex = getNextIndex(nowIndex, N);

		}
		if (chk(i, 0) && chk(i, N - 1)) {
			flag = true;
			cout << cases[i] << "\n";
			break;
		}

		
	}
	if (!flag) cout << "-1\n";





	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
int main(void){
    int s, w;
    cin>>s>>w;
    if(w>=s){
        cout<<"unsafe"<<endl;
    }
    else cout<<"safe"<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>

int main(){
  int A, B, C, D, E, F;
  scanf("%d %d %d %d %d %d", &A, &B, &C, &D, &E, &F);
  
  int w = A;
  int s = 0;
  for(int a = 0; 100 * A * a <= F; a++){
    for(int b = 0; 100 * (A * a + B * b) <= F; b++){
      if(a == 0 && b == 0) continue;
      for(int c = 0; 100 * (A * a + B * b) + C * c <= F; c++){
        for(int d = 0; 100 * (A * a + B * b) + C * c + D * d <= F; d++){
          if((A * a + B * b) * E < C * c + D * d) continue;
          if((100 * (A * a + B * b) + C * c + D * d) * s <= (w + s) * (C * c + D * d)){
            w = 100 * (A * a + B * b);
            s = C * c + D * d;
          }
        }
      }
    }
  }
  
  printf("%d %d\n", w + s, s);
  
  return 0;
}

Measured memory_bytes: 128
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5+5;

int n;
int ar[N];
int gP[N];
int gS[N];

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

int main(){
    scanf("%d" , &n);
    for(int i = 1; i <= n; i++){
        scanf("%d" , &ar[i]);
        gP[i] = gcd(gP[i - 1] , ar[i]);
    }
    for(int i = n; i >= 1; i--){
        gS[i] = gcd(gS[i + 1] , ar[i]);
    }
    int best = gP[n];
    for(int i = 1; i <= n; i++){
        best = max(1ll*best , gcd(gP[i - 1] , gS[i + 1]));
    }
    printf("%d\n" , best);
}


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

int main() {
  int total_cost = 0;
  cin >> total_cost;
  int cake = 4;
  int donut = 7;

  int cake_cost = 0;
  while (cake_cost <= total_cost) {
    int donut_cost = total_cost - cake_cost;
    if (donut_cost % donut == 0) {
      cout << "Yes" << endl;
      return 0;
    }
    cake_cost += cake;
  }
  cout << "No" << endl;
}


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

int main() {
  string S, T;
  cin >> S >> T;
  
  int cnt = 0;
  int len = S.size();
  for (int i = 0; i < len; i++) {
    if (S[i] != T[i]) {
      cnt++;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3912
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cassert>

using namespace std;

const int N=3005;
//const int P=998244353;

int n;
long long P;

#define multi(x,y) ((((x)%P)*((y)%P))%P)

inline long long ksm(long long base,long long x){
	long long res=1;
	while(x){
		if(x&1) res=multi(res,base);
		base=multi(base,base);
		x>>=1;
	}
	return res;
}

long long f[N][N];
long long ff[N][N];
long long g[N];
long long ans;
long long fac[N],inv_fac[N];
long long exp_2[N],exp_exp_2[N],exp_exp_exp_2[N];

inline void init_f(){
	f[0][0]=1;
	f[1][0]=1;
	f[1][1]=1;
	for(int i=2;i<=n;i++){
		f[i][0]=1;
		for(int j=1;j<=i;j++){
			f[i][j]=(P+f[i-1][j-1]+multi((j+1),f[i-1][j]))%P;
		}
	}
}


/*
inline void init_f(){
	//f[0][0]=1;
	//f[1][0]=1;
	ff[1][1]=1;
	for(int i=2;i<=n;i++){
		//f[i][0]=1;
		for(int j=1;j<=i;j++){
			ff[i][j]=(ff[i-1][j-1]+(((j)*ff[i-1][j])%P))%P;
		}
	}
	f[0][0]=1;
	for(int i=1;i<=n;i++){
		//f[i][j]=ff[i][j];
		for(int j=0;j<=i;j++){
			f[i][j]=(ff[i][j]+(ff[i][j+1]*(j+1))%P)%P;
		}
	}
}
*/


inline long long C(int x,int y){
    if(y<0||y>x)return 0;
	return multi(fac[x],multi(inv_fac[y],inv_fac[x-y]));
}

void init(){
	scanf("%d%lld",&n,&P);
	init_f();
	fac[0]=1;
	inv_fac[0]=1;
	for(int i=1;i<=n;i++) fac[i]=multi(fac[i-1],i),inv_fac[i]=ksm(fac[i],P-2);
	exp_2[0]=1;
	exp_exp_2[0]=2;
	exp_exp_exp_2[0]=1;
	for(int i=1;i<=n;i++) exp_2[i]=(exp_2[i-1]*2)%(P-1),exp_exp_2[i]=ksm(2,exp_2[i]),exp_exp_exp_2[i]=ksm(2,i);
	
	//printf("...\n");
	for(int i=0;i<=n;i++){
		for(int j=0;j<=i;j++){
			//g[i]+=multi(ksm(2,ksm(2,n-i)),multi(f[i][j],ksm(2,(j*(n-i))%P)));
			g[i]+=multi(exp_exp_2[n-i],multi(f[i][j],ksm(exp_exp_exp_2[n-i],j)));
			g[i]%=P;
			/*
			if(g[i]>P) cout<<"Error"<<endl;
			cout<<i<<' '<<j<<' '<<g[i]<<endl;
			assert(g[i]<=P);
			*/
		}
	}
	
	/*
	for(int i=0;i<=n;i++){
		for(int j=0;j<=i;j++){
			printf("%d ",f[i][j]);
		}
		printf("\n");
	}
	*/
	
	for(int i=0;i<=n;i++){
		if(i%2==0) ans+=multi(C(n,i),g[i]),ans%=P;
		else ans-=multi(C(n,i),g[i]),ans%=P,ans+=P,ans%=P;
	}
	printf("%lld\n",ans%P);
}

int main(){
	init();
	return 0;
}

Measured memory_bytes: 71936
#include <iostream>

using namespace std;


int main()
{
    int juice_num, min_count, p[1000], sum = 0,del = 0, count = 0;
    cin >> juice_num;
    cin >> min_count;
    for (int i = 0; i < juice_num; i++)
        cin >> p[i];
    int low;
    while (count < min_count)
    {
        low = 10000000000000;
        for (int i = 0; i < juice_num; i++) {
            if (low > p[i] && p[i] != 0) {
                low = p[i];
                del = i;
            }
        }
        p[del] = 0;
        sum += low;
        count++;
    }
    cout << sum;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	
	for(x=0;x<=N;x+=4) {
		if((N-x)%7==0) return _P("Yes\n");
	}
	_P("No\n");
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

int main(){
    int n,m;
    cin>>n>>m;
    vector<int> v(n+1,-1);
    rep(i,m){
        int s,c;
        cin>>s>>c;
        if(v[s]!=-1&&v[s]!=c){
            cout<<-1<<endl;
            return 0;
        }else{
            v[s]=c;
        }
    }
    if(n==1){
        cout<<max(v[1],0)<<endl;
        return 0;
    }    

    if(v[1]==0){
        cout<<-1<<endl;
        return 0;
    }
    if(v[1]==-1) v[1]=1;
    REP(i,n){
        cout << max(v[i],0);
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
H,W,N = gets.split.map(&:to_i)
sr,sc = gets.split.map(&:to_i)
S = gets.chomp
T = gets.chomp

i = 0
l = r = sc
u = d = sr
while i < N
  s = S[i]
  t = T[i]
  l -= 1 if s=='L'
  r += 1 if s=='R'
  u -= 1 if s=='U'
  d += 1 if s=='D'
  if l < 1 || W < r || u < 1 || H < d
    puts 'NO'
    exit 0
  end
  r -= 1 if t=='L' && 1 < r
  l += 1 if t=='R' && l < W
  d -= 1 if t=='U' && 1 < d
  u += 1 if t=='D' && u < H
  i += 1
end

puts 'YES'


Measured memory_bytes: 2632
#include <iostream>
#include <stdio.h>
using namespace std;

int main(int argc, char *argv[])
{
    int b, f, r, v;
    int house[3][10][4] = {0};

    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d %d %d %d", &b, &f, &r, &v);
        house[f - 1][r - 1][b - 1] += v;
    }

    for (int j = 0; j < 3; j++)
    {
        //printf("%d", house[j][0][0]);
        for (int k = 0; k < 10; k++)
        {
            printf(" %d", house[j][k][0]);
        }
        printf("\n");
    }

    for (int i = 1; i < 4; i++)
    {
        for (int m = 0; m < 20; m++)
        {
            printf("%c", '#');
        }
        printf("\n");

        for (int j = 0; j < 3; j++)
        {
            //printf("%d", house[j][0][i]);
            for (int k = 0; k < 10; k++)
            {
                printf(" %d", house[j][k][i]);
            }
            printf("\n");
        }
    }
    return 0;
}



Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(ll i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(ll i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;


int main() {
  int n, W; cin >> n >> W;
  V w(n), v(n);
  rep(i, n) cin >> w[i] >> v[i];

  map<int, int> dp;
  dp[0] = 0;

  rep(i, n) for (auto itr = rbegin(dp); itr != rend(dp); ++itr) {
    int x, y;
    tie(x, y) = *itr;
    if (x+w[i] <= W) chmax(dp[x+w[i]], y+v[i]);
  }

  int ans = 0;
  for (auto &e : dp) chmax(ans, e.second);
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 384
#include <bitset>
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

int solve(vector<pair<int, int>> &keys, int n, vector<vector<int>> &memo,
          int s = 0, int offset = 0) {
  if (offset == keys.size()) {
    return bitset<32>(s).count() == n ? 0 : -1;
  }

  if (memo[s][offset] < -1) {
    int a = solve(keys, n, memo, s | keys[offset].second, offset + 1);
    int b = solve(keys, n, memo, s, offset + 1);
    if (a >= 0) {
      a += keys[offset].first;
    }
    memo[s][offset] = (a < 0 || b < 0) ? max(a, b) : min(a, b);
  }

  return memo[s][offset];
}

int main(int argc, const char *argv[]) {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> keys(m);
  for (auto &key : keys) {
    int b;
    key.second = 0;
    cin >> key.first >> b;
    for (int i = 0; i < b; i++) {
      int c;
      cin >> c;
      c--;
      key.second |= (1 << c);
    }
  }

  vector<vector<int>> memo(pow(2, n), vector<int>(m + 1, -2));
  cout << solve(keys, n, memo) << '\n';
  return 0;
}

Measured memory_bytes: 16512
#include<stdio.h>
#include<string.h>
int main(){
  char s[1030],*c;
  int f=0,l;
  fgets(s,1025,stdin);
  c=strtok(s," ,.");
  l=strlen(c);
  if(2<l&&l<7){
    printf("%s",c);
    f=1;
  }
  while(c=strtok(NULL," ,.")){
    l=strlen(c);
    if(2<l&&l<7){
      if(f)printf(" ");
      printf("%s",c);
      f=1;
    }
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 524
import java.time.Instant;
import java.util.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

public class Main {
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();

		int ans=0;

		if(A>12){
			ans=B;
		} else if(A>5 && A<13){
			ans=B/2;
		}else if(A<6){
			ans=0;
		}

		System.out.println(ans);
	}
}

Measured memory_bytes: 23892
#include <stdio.h>

#define N 91

int m, n;
int max;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

//	マップ, 座標, 歩数
void getWay(char map[N][N], int x, int y, int cost)
{
	int i;
	
	if (max < cost) max = cost;
	map[x][y] = 0;
	
	for (i = 0; i < 4; i++){
		int nx = x + dx[i];
		int ny = y + dy[i];
		
		if (nx >= 0 && ny >= 0 && nx < m && ny < n){
			if (map[nx][ny] == 1){
				getWay(map, nx, ny, cost + 1);
			}
		}
	}
	map[x][y] = 1;
}

int main(void)
{
	int i, j;
	char map[N][N];
	
	
	scanf("%d", &m);
	scanf("%d", &n);
	
	while (m != 0){
		
		for (i = 0; i < m; i++){
			for (j = 0; j < n; j++){
				scanf("%d", &map[i][j]);
			}
		}
		
		for (i = 0; i < m; i++){
			for (j = 0; j < n; j++){
				if (map[i][j] == 1){
					getWay(map, i, j, 1);
				}
			}
		}
		
		printf("%d\n", max);
		max = 0;
		
		
		scanf("%d", &m);
		scanf("%d", &n);
	}
	return (0);
}

Measured memory_bytes: 608
def main():
    n = int(input())
    h_list = list(map(int, input().split()))
 
    dp = [100000]*n
 
    dp[0] = 0
    for i in range(1,n):
 
        tmp_dp1 = 1000000
        tmp_dp2 = 1000000
        if i - 1 >= 0:
            tmp_dp1 = dp[i-1] + abs(h_list[i] - h_list[i-1])
 
        if i - 2 >= 0:
            tmp_dp2 =  dp[i-2] + abs(h_list[i] - h_list[i-2])
        dp[i]=min(tmp_dp1, tmp_dp2)
    print(dp[n-1])
main()

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

using namespace std;
using ll=long long;
using vi=vector<int>;
using vl=vector<ll>;
using vs=vector<string>;

#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define repr(i, a, n) for (int i = (n); i >= (a); --i)

template<typename T,typename U>
void Inparray(T &f,U n){
  for(int i=0;i<n;i++) cin>>f[i];
}

template<typename T,typename U>
void Printarray(T f,U n){
  for(int i=0;i<n;i++) i!=n ? cout<<f[i]<<" " : cout<<f[i];
}

void flagfunc(bool flag,string A,string B){
  flag ? cout<<A<<endl : cout<<B<<endl;
}

void flag2func(bool flag){
  flag ? cout<<"Yes"<<endl : cout<<"No"<<endl;
}

void flag3func(bool flag){
  flag ? cout<<"YES"<<endl : cout<<"NO"<<endl;
}

ll f(ll n,ll x){
  if(n>=0)return n/x+1;
  return 0;
}
int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll a,b,x;cin>>a>>b>>x;
  cout<<f(b,x)-f(a-1,x)<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

typedef struct{
    int label[6];
}dice;

void roll_south( int* );
void roll_north( int* );
void roll_east( int* );
void roll_west( int* );
int match( int*, int*, int  );

int main(){
	char direct[101] = {'\0'};
	int times = 0;
	int front = 0;
	int top = 0;
	int roll_cnt = 0;
    int i, j;
    dice dice1;
	dice dice2;
	int ans = 0;
    
    for( i = 0; i < 6; i++ ){
        scanf( "%d", &dice1.label[i] );
    }
	for( i = 0; i < 6; i++ ){
        scanf( "%d", &dice2.label[i] );
    }

	for( i = 0; i < 6; i++ ){
		for( j = 0; j < 4; j++ ){
			if( match( dice1.label, dice2.label, 6 ) == 1 ){
				ans = 1;
				goto end;
			}
			roll_north( dice1.label );
			roll_east( dice1.label );
			roll_south( dice1.label );
		}
		if( i % 2 == 0 ){
			roll_north( dice1.label );
		}
		else{
			roll_east( dice1.label );
		}
	}

end:
	if( ans == 0 ){
		printf( "No\n" );
	}
	else if( ans == 1 ){
		printf( "Yes\n" );
	}
	else{
	}

    return 0;
}

int match( int* a,int* b, int num  )
{
	int i = 0;
	int match = 1;

	for( i = 0; i < num; i++ ){
		if( a[i] != b[i] ){
			match = 0;
			break;
		}
	}

	return match;
}

void roll_south( int* dice )
{
    int work;
    
    work = dice[0];
    dice[0] = dice[4];
    dice[4] = dice[5];
    dice[5] = dice[1];
    dice[1] = work;
}
void roll_north( int* dice )
{
    int work;
    
    work = dice[0];
    dice[0] = dice[1];
    dice[1] = dice[5];
    dice[5] = dice[4];
    dice[4] = work;
}
void roll_east( int* dice )
{
    int work;
    
    work = dice[0];
    dice[0] = dice[3];
    dice[3] = dice[5];
    dice[5] = dice[2];
    dice[2] = work;
}
void roll_west( int* dice )
{
    int work;
    
    work = dice[0];
    dice[0] = dice[2];
    dice[2] = dice[5];
    dice[5] = dice[3];
    dice[3] = work;
}


Measured memory_bytes: 2112
H,W = map(int,input().split())
if H == 1 or W == 1:
    print(1)
elif H%2 == 0 and W%2 == 0:
    print(int((H/2)*W))
elif H%2 == 1 and W%2 ==1:
    print(int((H//2+1)*(W//2+1)+(H//2)*(W//2)))
elif H%2 == 0:
    print(int((H/2)*W))
else:
    print(int((W/2)*H))


Measured memory_bytes: 3060