akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>

using namespace std;

int main() {
	int n, l; cin >> n >> l;
	int sum = 0, mini = 500;
	for (int i = 1; i <= n; ++i) {
		sum += l + i - 1;
		mini = abs(mini) > abs(l + i - 1) ? l + i - 1 : mini;
	}
	cout << sum - mini << endl;

	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict,deque
H, W = map(int,input().split())
MAP = []
for _ in range(H):
    MAP.append(tuple(map(str,input())))

move = [[0,1],[0,-1],[1,0],[-1,0]]
MAX = 0 

def bfs(s):
    global MAX
    stack = deque([])
    stack.append(tuple(s))
    depth =dict()
    depth[tuple(s)] = 0
    while stack:
        v = stack.popleft()
        for m in move:
            a = tuple([v[0]+m[0], v[1] + m[1]])
            if a[0] < H and a[0] >=  0 and a[1] < W and a[1] >= 0:
                if MAP[a[0]][a[1]] == '.' and not a in depth:
                    stack.append(a)
                    depth[a] = depth[v] + 1

    for d in depth.values():
        MAX = max(MAX,d)


for i in range(0,H):
    for j in range(0,W):
        if MAP[i][j] == '.':
            bfs(tuple([i,j]))

for i in range(0,W):
    for j in range(0,H):
        if MAP[j][i] == '.':
            bfs(tuple([j,i]))

print(MAX)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
int main() {
	char C;
	cin >> C;
	if (C == 'a' || C == 'i' || C == 'u' || C == 'e' || C == 'o')
		cout << "vowel" << endl;
	else
		cout << "consonant" << endl;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    string s,t;cin >>s>>t;
    sort(all(s));
    sort(all(t));
    reverse(all(t));
    if(s<t)puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <stdint.h>
#include <vector>
#include <limits.h>
#include <utility>
#include <memory>
#include <set>
#include <map>

using namespace std;

using Group = set<int>;

inline uint64_t calc_convenience(Group& group)
{
  uint64_t island_count = group.size();
  return island_count * (island_count-1) / 2;
}

int main()
{
  int N,M;
  cin >> N >> M;

  vector<pair<int,int>> bridges;
  
  for (int m=0; m<M; ++m) {
    int a,b;
    cin >> a >> b;
    bridges.push_back(pair<int,int>(a,b));
  }

  map<int,shared_ptr<Group>> island2group;
  set<shared_ptr<Group>> groups;

  for (int n=0; n<N; ++n) {
    Group new_group = {n+1};
    auto ptr_new_group = make_shared<Group>(new_group);
    island2group[n+1] = ptr_new_group;
    groups.insert(ptr_new_group);
  }

  vector<uint64_t> conveniences = {0};

  for (int m=M-1; m>=0; m--) {
    auto bridge = bridges[m];
    int a = bridge.first, b = bridge.second;
    auto group_a = island2group[a];
    auto group_b = island2group[b];
    uint64_t convenience_prev = calc_convenience(*group_a) + calc_convenience(*group_b);
    if (group_a != group_b) {
      if (group_b->size() > group_a->size())
	swap(group_a,group_b);

      for (int island_b : *group_b) {
	group_a->insert(island_b);
	island2group[island_b] = group_a;
      }
      groups.erase(group_b);
      uint64_t convenience_now = calc_convenience(*group_a);
      conveniences.push_back(conveniences.back()+convenience_now-convenience_prev);
    } else {
      conveniences.push_back(conveniences.back());
    }
  }

  uint64_t final_convenience = conveniences.back();
  for (auto itr = conveniences.rbegin()+1; itr != conveniences.rend(); ++itr) {
    cout << final_convenience - *itr << endl;
  }
  
  return 0;
}

Measured memory_bytes: 26484
#include <iostream>
#include <algorithm>
#include <cstdlib>
using namespace std;
typedef long long int ll;
int main(){
  int n,k;
  cin >>n>>k;
  ll x[n];
  ll ans=10000000000;
  for(int i=0;i<n;i++) cin >>x[i];
  for(int i=0;i<n-k+1;i++){
     ans=min(ans,min(abs(x[i])+abs(x[i+k-1]-x[i]),abs(x[i+k-1])+abs(x[i+k-1]-x[i])));
  }
   cout<<ans<<endl;
}


Measured memory_bytes: 1024
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
int main(){
  string s;
  cin>>s;
  for(int i=0;i<s.size();i++){
    if(s[i]=='?')cout<<'D';
    else cout<<s[i];
  }
  cout<<"\n";
}

Measured memory_bytes: 3748
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
using namespace std;

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

string s[8];
int z;
const int dx[12] = {0,  0,  0, 1, 2, 3, 0, 0, 0, -1, -2, -3};
const int dy[12] = {-1,-2, -3, 0, 0, 0, 1, 2, 3, 0, 0, 0};

void dfs(int x, int y) {
  s[y][x] = '0';
  rep(zz,12) {
    int tx = x + dx[zz], ty = y + dy[zz];
    if (tx < 0 || ty < 0 || tx >= 8 || ty >= 8) continue;
    if (s[ty][tx] == '1') dfs(tx, ty);
  }
}

void solve() {
  int bx, by;
  rep(i,8) cin>>s[i];
  cin>>bx>>by;
  bx--; by--;
  
  dfs(bx, by);
  cout<<"Data "<<z<<":"<<endl;
  rep(i,8) cout<<s[i]<<endl;
}

int main (int argc, char const* argv[]) {
  int n; cin>>n;
  for(z=1;z<=n;z++) solve();
  return 0;
}

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

using namespace std;

typedef long long int ll;
typedef pair<int,int> P;

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int main()
{
	int r;
	cin>>r;
	cout<<r*r<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
long long int a[2010]={0};
long long int b[2010][2010]={0};
int main(){   long long int n,x,i,j,sum,minx,temp;
    scanf("%lld %lld",&n,&x);
    for(i=1;i<=n;i++)
        scanf("%lld",&a[i]);
    for(i=1;i<=n;i++){
        b[i][0]=a[i];
        for(j=1;j<n;j++){
            temp=i-j;
            if(temp<=0)
                temp=n+temp;
            b[i][j]=min(b[i][j-1],a[temp]);
        }
    }
    minx=0x3f3f3f3f3f3f3f3f;
    for(i=0;i<n;i++){
        sum=0;
        for(j=1;j<=n;j++)
            sum+=b[j][i];
        sum+=i*x;
        minx=min(sum,minx);
    }
    printf("%lld\n",minx);
}




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

void printArray(int a[], int n) {
    string sep = "";
    for (int i = 0; i < n; i++) {
        cout << sep << a[i];
        sep = " ";
    }
    cout << endl;
}

void swap(int* a, int* b) {
    int tmp = *a;
    *a = *b;
    *b = tmp;
}

int bubbleSort(int a[], int n) {
    int numOfSwap = 0;
    bool flag = true;
    while (flag) {
        flag = false;
        for (int i = n - 1; i > 0; i--) {
            if (a[i - 1] > a[i]) {
                swap(&a[i - 1], &a[i]);
                numOfSwap++;
                flag = true;
            }
        }
    }
    return numOfSwap;
}

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

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

    int numOfSwap = bubbleSort(a, n);

    printArray(a, n);
    cout << numOfSwap << endl;
}

Measured memory_bytes: 3144
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;
const int INF=1e9;

int main(){
    int n, k, a[50];
    cin>>n>>k;
    for(int i=0; i<n; i++) cin>>a[i];
    sort(a, a+n, greater<int>());
    int ans=0;
    for(int i=0; i<k; i++) ans+=a[i];
    cout<<ans<<endl;
    
}


Measured memory_bytes: 256
program main
  integer(8) :: A,B,C,K
  integer(8) :: i,j
  read(*,*) A,B,C,K
  if ( K-A > 0) then
     if (K-A-B > 0 ) then
        write(*,'(i0)') A-(K-A-B)
     else
        write(*,'(i0)') A
     end if
  else 
     write(*,'(i0)')  K
  end if
end program main


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

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef unordered_set<int> si;
typedef pair<int, int> pp;
typedef vector<pp> vpp;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#define all(e) (e).begin(), (e).end()
#define pb push_back


template <typename T>
void printV(vector<T> A) {
    if (A.empty()) cerr << "EMTPY\n";
    else { 
        cerr << "[";
        for (int i = 0; i < A.size() -1 ; ++i) {
            cerr << A[i] << ", ";
        }
        if (A.size()) cerr << A.back() << "]\n";
    }
}


template <typename T>
void printVV(vector<vector<T>> A) {
    cerr << "[";
    for (auto v : A) {
        printV<T>(v);
    }
    cerr << "]";
}

template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cerr << name << ": " << arg1 << endl;
}

template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&& ...args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << ": " << arg1 << " |";
    __f(comma + 1, args...);
}

int main(int argc, char **argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int k, a, b; cin >> k >> a >> b;
    for (int i = a; i <= b; ++i) {
        if (i % k == 0) {
            cout << "OK\n";
            return 0;
        }
    }
    cout << "NG\n";
    return 0;
}



Measured memory_bytes: 3648
#include <string.h>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <istream>
#define INF 2147483647
#define LLINF 9223372036854775807
typedef long long ll;
using namespace std;
int main(){
//  cout<<fixed<<setprecision(1)<<1<<endl;
	int n;
	cin>>n;
	cout<<(n+1000-1)/1000*1000-n<<endl;
	return 0;
}

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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

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

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

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


Measured memory_bytes: 256
#include <cstdio>

#define NUM 128
#define STOP 10000

int main(void) {
	while(1) {
		int n, a, b, c, x, y[NUM], frame, num = 0;
		scanf("%d %d %d %d %d", &n, &a, &b, &c, &x);
		if(!n) break;
		for(int i = 0; i < n; i++) {
			scanf("%d", &y[i]);
		}
		for(frame = 0; frame <= STOP; frame++) {
			if(y[num] == x) num++;
			x = (a * x + b) % c;
			if(num == n) break;
		}
		if(frame > STOP) frame = -1;
		printf("%d\n", frame);
	}
	return 0;
}

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

int main()
{
    ll n,i,j,cnt=1,k=1,w1,w2,w3,t,a,b,c,d,e,s,r;
   /* freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);*/
	cin>>n>>k;
	ll h[n];
	ll dp[n];
	for(i=0;i<n;i++)
    {
        dp[i]=1e9;
    }
	for(i=0;i<n;i++)
    {
        cin>>h[i];
    }
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<=i+k&&j<n;j++)
        {
            dp[j]=min(dp[j],dp[i]+abs(h[j]-h[i]));
        }
    }
    cout<<dp[n-1];


    return 0;
}


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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define REP(i, n) for(ll i = 0LL; i < (ll)(n); i++)
#define REPR(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define FOR(i, n, m) for(ll i = (ll)n; i < (ll)(m); i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define PRINT(x) std::cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dx[8] = {0,1,0,-1, 1, -1, 1, -1}, dy[8] = {1,0,-1,0,1,1,-1,-1};

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) os << v[i] << " ";  
    return os; 
}

template <typename T1, typename T2> 
ostream& operator<<(ostream& os, const map<T1, T2>& m) 
{ 
    for (auto p : m) os << "<" << p.first << ", " << p.second << "> "; 
    return os; 
}

int main()
{
  string T;
  cin >> T;
  REP(i, T.size()) {
    if (T[i] == '?') cout << 'D';
    else cout << T[i];
  }
  cout << endl;
  return 0;
} 


Measured memory_bytes: 3732
n = int(input())
h = list(map(int, input().split()))
dp = [10**4 + 1] * n

# 初期条件
dp[0] = 0
dp[1] = abs(h[1] - h[0])

# dp値の更新
# ルートごとのスコアを比較して、最小のスコアで更新する
for i in range(2, n):
    c = [10**4 + 1] * 2
    c[0] = dp[i-1] + abs(h[i] - h[i-1])
    c[1] = dp[i-2] + abs(h[i] - h[i-2])
    dp[i] = min(c)

# 最小コストの表示
print(dp[n-1])

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

using namespace std;

vector <pair <int,int>> Solve(int L, int R)
{
    vector <pair <int,int>> Res;

    while(L < R)
    {
        Res.emplace_back(L, R);
        L++;
        R--;
    }

    return Res;
}

int main()
{
    int n, m;   cin >> n >> m;

    n = 2 * m + 1;

    vector <pair <int,int>> Ans1 = Solve(1, m);
    vector <pair <int,int>> Ans2 = Solve(m + 1, n);

    for(pair <int,int> p : Ans1)    printf("%d %d\n", p.first, p.second);
    for(pair <int,int> p : Ans2)    printf("%d %d\n", p.first, p.second);
}


Measured memory_bytes: 4320
#include <iostream>
#include <string>
#include <cassert>
using namespace std;
typedef long long ll;
int a[1000010],b[1000100],cnt[3] = {};
const int MX = 1000010;
ll cnt1[MX] = {},cnt2[MX];
void solve(int n){
    int i,j;
    for(i=1;i<=MX;i++){
        j = i;
        while(j%2==0){
            j /= 2;
            cnt1[i]++;
        }
    }
    cnt2[0] = 0;
    for(i=1;i<=n - 1;i++){
        cnt2[i] = cnt2[i - 1] + cnt1[n - i] - cnt1[i];
    }
}

ll nck(ll n, ll k){
    if(cnt2[k]) return 0;
    return 1;
}


string s;
int main(){
    int i,n;
    cin >> n >> s;
    for(i=0;i<n;i++){
        a[i] = s[i] - '0';
    }
    solve(n - 1);
    for(i=0;i<n - 1;i++){
        a[i] = max(a[i] - a[i + 1],a[i + 1] - a[i]);
    }
    if(n==2){
        cout << a[0] << endl;
        return 0;
    }
    for(i=0;i<n - 1;i++){
        cnt[a[i]]++;
    }
    bool flag = false;
    if(cnt[1]==0){
        flag = true;
        for(i=0;i<n - 1;i++){
            if(a[i]) a[i] = 1;
        }
    }
    for(i=0;i<n;i++){
        a[i] %= 2;
    }
    int ans = 0;
    for(i=0;i<n - 1;i++){
        (ans += nck(n - 2,i)*a[i]) %= 2;
    }
    if(flag){
        if(ans) cout << 2 << endl;
        else cout << 0 << endl;
    }else{
        cout << ans << endl;
    }
}


Measured memory_bytes: 22788
n=int(input())
m=int((n**(1/2))//1+1)
l=[]
for i in list(range(m+1))[:0:-1]:
  if n%i==0:
    l.append(max(len(str(i)),len(str(n//i))))
  if len(l)==3:
    break
print(min(l))

Measured memory_bytes: 7668
#include<cstdio>
#include<cstring>
using namespace std;
char s[200500];
int main(){
	scanf("%s",s+1);int n=strlen(s+1);
	if (s[1]!='1'||s[n]!='0') return printf("-1"),0;
	for (int i=1;i<n;i++)
	if (s[i]=='1'&&s[n-i]!='1') return printf("-1"),0;
	int last=1;
	for (int i=2;i<n;i++){
		if (s[i]=='1') {
			printf("%d %d\n",last,i);
			last=i;
		}else 
		printf("%d %d\n",last,i);
	}
	printf("%d %d\n",1,n);
	return 0;
}

Measured memory_bytes: 1408
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::{i32, i64, u32, u64, f64};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{VecDeque, HashMap, BTreeMap, HashSet, BTreeSet};
#[allow(unused_imports)]
use std::io::{stdout, Write, BufWriter};
#[allow(unused_imports)]
use std::mem::{swap};
//#[allow(unused_imports)]
//use proconio::marker::{Isize1, Usize1, Bytes, Chars};

//#[proconio::fastout]
fn main() {
    input!{
        s: String,
    }
    let mut s = s.chars().map(|c| c.to_digit(10).unwrap()).collect::<Vec<_>>();
    let mut i = 0;
    let mut ans = 0;
    while i + 1 < s.len() {
        if s[i] != s[i + 1] {
            s.remove(i);
            s.remove(i);
            ans += 2;
            i = 0;
            continue;
        }
        i += 1;
    }
    println!("{}", ans);
}




Measured memory_bytes: 4352
#include <iostream>

#include<queue>

#include<string.h>

using namespace std;

int main(){

    queue <int> q;

    int h,w,n;

    long ans=0;

    char map[1000][1000];

    int d[1000][1000];

    int x,fx,mx[]={0,1,0,-1};

    int y,fy,my[]={1,0,-1,0};

    cin>>h>>w>>n;

    for(int i=0;i<h;i++){

        for(int o=0;o<w;o++){

            cin>>map[i][o];

            if(map[i][o]=='S'){

                q.push(i);

                q.push(o);

                x=o;

                y=i;

            }

        }

    }
    
    for(int i=1;i<=n;i++){
        memset(d,-1,sizeof(d));

        d[y][x]=0;

        while(!q.empty()){

            y=q.front();

            q.pop();

            x=q.front();

            q.pop();

            if(map[y][x]==i+48){

                ans=ans+d[y][x];

                while(!q.empty()){

                    q.pop();

                }

                q.push(y);

                q.push(x);

                break;

            }

            for(int o=0;o<4;o++){

                fy=y+my[o];

                fx=x+mx[o];

                if(fy>=0&&fy<h&&fx>=0&&fx<w&&map[fy][fx]!='X'&&d[fy][fx]==-1){

                    d[fy][fx]=d[y][x]+1;

                    q.push(fy);

                    q.push(fx);

                }

            }

        }

    }

    cout<<ans<<endl;

}

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

using namespace std;

vector<vector<int> > G;
vector<int> color;
long long b,w;

bool isBipartite(int v, int prev,int c) {
	color[v]=c;
	++(c==0?b:w);
	for(auto e:G[v]) {
		if(e==prev) continue;
		if(color[e]==c) return false;
		if(color[e]!=-1) continue;
		if(!isBipartite(e,v,1-c)) return false;
	}
	return true;
}

int main() {
	long long n,m; cin >> n >> m;
	G.resize(n);
	color.assign(n,-1);
	for(int i=0;i<m;++i) {
		int a,b; cin >> a >> b;
		--a, --b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	if(isBipartite(0,-1,0)) cout << b*w-m << endl;
	else cout << n*(n-1)/2-m << endl;
	
	return 0;
}


Measured memory_bytes: 6656
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define LL long long
#define PP std::pair<LL,LL>
int N,K;
LL x[100010];
std::vector<LL> m,p;
int main(){
	std::cin>>N>>K;
	m.push_back(0);
	for(int i=0;i<N;i++){
		LL x;
		std::cin>>x;
		m.push_back(x);
		if(x==0)K--;
	}
	LL ans = 1e15;
	std::sort(m.begin(),m.end());
	for(int i=0;i<=N-K;i++){
		if(m[i]<=0&&0<=m[i+K])
			ans=std::min(ans,m[i+K]-m[i] + std::min(m[i+K],-m[i]));
	}
	std::cout<<ans<<std::endl;
	return 0;
}

Measured memory_bytes: 1400
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value

N = ii()
A = sorted([ii() for _ in range(N)])

if N % 2:
    ans_1 = sum(A[N//2+1:])*2 - sum(A[:N//2+1])*2
    ans_1 += A[N//2-1] + A[N//2]
    ans_2 = sum(A[N//2:])*2 - sum(A[:N//2])*2
    ans_2 -= A[N//2] + A[N//2+1]
    print(max(ans_1, ans_2))
else:
    ans = sum(A[N//2:])*2 - sum(A[:N//2])*2
    ans -= A[N//2] - A[N//2-1]
    print(ans)

Measured memory_bytes: 8300
n = int(input())
d = input().split()
m = int(input())
t = input().split()
dic = {}

for a in range(n):
  if d[a] not in dic:
    dic[d[a]] = 1
  else:
    dic[d[a]] += 1

con = 0

for b in range(m):
  if t[b] not in dic or dic[t[b]] == 0:
    print("NO")
    break
  elif t[b] in dic:
    dic[t[b]] -= 1
    con += 1

if con == m:
  print("YES")


    

Measured memory_bytes: 54104
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
using namespace std;

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

int calc_sugar(int k, int rem){
  int final_i = 0, final_j = 0;
  int mx = 0;
  for(int i=0; ; ++i){
    for(int j=0; ;++j){
      if((D*j) > (E*k) || (D*j) > rem)
        break;
      if((C*i + D*j) > (E*k) || (C*i + D*j) > rem)
        continue;
      int pp = C*i + D*j;
      if(pp > mx)
        mx = pp, final_i = i, final_j = j;
    }
    if((C*i) > (E*k) || (C*i) > rem)
      break;
  }
  return C*final_i + D*final_j; 
}

double calc_density(int w, int s){
  return s*1.0/(s+w)*1.0;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> A >> B >> C >> D >> E >> F;
  int res_sugar_water = 0, res_sugar = 0, ww = 0;
  double mx = 0.0;
  for(int i=0; ; ++i){
    for(int j=0; ; ++j){
      int water = (i*A + j*B)*100;
      if(water >= F)
        break;
      ww = max(ww, water);
      int sugar = calc_sugar(i*A+j*B, F - water);
      double p = calc_density(water, sugar);
      if(p > mx){
          mx = p;
          res_sugar_water = water + sugar;
          res_sugar = sugar;
      }
    }
    if(i*A >= F){
      break;
    }
  }
  if(res_sugar_water == 0 && res_sugar == 0)
    res_sugar_water = ww;
  cout << res_sugar_water << " " << res_sugar << "\n";
  return 0;  
}



Measured memory_bytes: 256
t,*g=open(0);h,w=map(int,t.split());v=[[0]*w for _ in range(h)];v[0][0]=1;q=[(0,0)]
while q:
	a,b=q.pop(0)
	for c,d in((-1,0),(0,-1),(1,0),(0,1)):
		x=a+c;y=b+d
		if w>x>=0<=y<h and v[y][x]<1 and g[y][x]==".":q+=[(x,y)];v[y][x]=v[b][a]+1
t=v[-1][-1];print((-1,h*w-sum(c.count("#")for c in g)-t)[t>0])

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

using namespace std;

#define debug(x) '[' << #x << " is: " << x << "] "
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.precision(10);
	cout << fixed;

	int n,k;
	cin>>n>>k;
	int ans = 0;
	while(n){
		ans ++;
		n/=k;
	}
	cout << ans << '\n';
}


Measured memory_bytes: 256
import java.util.Scanner;

/**
 * https://abc058.contest.atcoder.jp/tasks/arc071_b
 */
public class Main {

	static final int MOD = 1000000007;
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		long[] x = new long[N];
		long[] y = new long[M];
		for(int i=0; i<N; i++) x[i] = Long.parseLong(sc.next());
		for(int i=0; i<M; i++) y[i] = Long.parseLong(sc.next());
		sc.close();
		
		
		long xsum = 0;
		long ysum = 0;
		for(int i=0; i<N; i++){
			xsum = ( xsum - ((long)N-2*(long)i-1)*x[i]%MOD ) %MOD;
		}
		for(int i=0; i<M; i++){
			ysum = ( ysum - ((long)M-2*(long)i-1)*y[i]%MOD ) %MOD;
		}
		
	
		System.out.println(xsum*ysum%MOD);

	}

}

Measured memory_bytes: 49812
ac_cnt = 0
wa_cnt = 0
tle_cnt = 0
re_cnt = 0

for _ in range(int(input())):
	res = input()
	if res == 'AC':
		ac_cnt += 1
	elif res == 'WA':
		wa_cnt += 1
	elif res == 'TLE':
		tle_cnt += 1
	else:
		re_cnt += 1

print("AC x {}".format(ac_cnt))
print("WA x {}".format(wa_cnt))
print("TLE x {}".format(tle_cnt))
print("RE x {}".format(re_cnt))

Measured memory_bytes: 9188
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5]){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < b; i++)
using namespace std;

int main() {
    long long x, y;
    cin >> x >> y;

    long long ans = 0, cur = y;
    while (y >= x) {
        y /= 2;
        ans++;
    }

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

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)























int main() {
	ll n;
	cin >> n;
	vector<ll> a(n);
	vector<pair<ll, ll>> v(n);
	REP(i, n) {
		cin >> a[i];
		v[i] = { a[i], i };
	}
	sort(v.begin(), v.end(), greater<pair<ll, ll>>());
	vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, -INF));
	dp[0][0] = 0;
	REP(i, n) {
		REP(j, i + 1) {
			dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + v[i].first * abs(j - v[i].second));
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + v[i].first * abs((n - 1 - (i - j)) - v[i].second));
		}
	}
	cout << *max_element(dp[n].begin(), dp[n].end()) << endl;
}

Measured memory_bytes: 34676
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(N)]
res = 0
for i in range(N):
  temp = C
  for j in range(M):
    temp += A[i][j] * B[j]
  if temp > 0:
    res += 1
print(res)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>

int main(int argc, char* argv[])
{
  std::string str;
  std::cin >> str;

  std::sort(str.begin(), str.end());
  if (str == "abc") {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    N,M = map(int, input().split())
    PY = [list(map(int, input().split())) for i in range(M)]
    for i in range(M):
        PY[i].append(i)
    PY = sorted(PY, key=lambda x:x[1])
    PY = sorted(PY, key=lambda x:x[0])
    
    now = PY[0][0]
    num = 0
    for i in range(M):
        if PY[i][0] == now:
            num += 1
        else:
            now = PY[i][0]
            num = 1
        P = str(PY[i][0])
        stnum = str(num)
        ID = "0"*(6 - len(P)) + P + "0"*(6 - len(stnum)) + stnum
        PY[i].append(ID)
    PY = sorted(PY, key=lambda x:x[2])
    
    for i in range(M):
        print(PY[i][3])
    
    
    
    
    
    
main()

Measured memory_bytes: 97628
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<(n);++i)
#define REP(i,a,b) for(ll i=(a);i<(b);++i)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ld EPS=10e-8;
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

ll dp[107][100007];

int main(){
    ll N,W;cin>>N>>W;
    pair<ll,ll> wv[107];
    rep(i,N){
        cin >> wv[i+1].first >> wv[i+1].second;
    }
    rep(i,W+1){
        dp[0][i]=0;
    }
    rep(j,N+1){
        dp[j][0]=0;
    }
    REP(i,1,N+1){
        REP(j,1,W+1){
            if(wv[i].first>j){
                dp[i][j]=dp[i-1][j];
            }
            else{
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-wv[i].first]+wv[i].second);
            }
        }
    }
    cout << dp[N][W]  << endl;
}

Measured memory_bytes: 80128
#include<iostream>
#include<map>
#include<string>
#include<functional>
using namespace std;
int n,q,m;
int A[20];
int solve(int i,int m){
    if(m==0) return 1;
    if(i>=n) return 0;
    int flag = solve(i+1,m)||solve(i+1,m-A[i]);
    return flag;
}
int main(){
    cin>>n;
    for(int i=0;i<n;++i){
        cin>>A[i];
    }
    cin>>q;
    int B[q];
    for(int j=0;j<q;++j){
        cin>>m;
        if(solve(0,m)){
            cout<<"yes"<<endl;
        }
        else cout <<"no"<<endl;
    }
}



Measured memory_bytes: 3112
n = int(input())
x = list(map(int, input().split()))
ans1 = 0
ans2 = 0
xa = sum(x) // n
for i in x:
    ans1 += (abs(i-xa))**2

for i in x:
    ans2 += (abs(i-xa-1))**2

print(min(ans1, ans2))


Measured memory_bytes: 3060
class UnionFind:
  def __init__(self, n):
    self.n = [-1]*n
    self.r = [0]*n
    self.co = n

  def find_root(self, x):
    if self.n[x] < 0:
      return x
    else:
      self.n[x] = self.find_root(self.n[x])
      return self.n[x]

  def unite(self, x, y):
    x = self.find_root(x)
    y = self.find_root(y)
    if x == y:
      return
    elif self.r[x] > self.r[y]:
      self.n[x] += self.n[y]
      self.n[y] = x
    else:
      self.n[y] += self.n[x]
      self.n[x] = y
      if self.r[x] == self.r[y]:
        self.r[y] += 1
    self.co -= 1

  def same(self, x, y):
    return self.find_root(x) == self.find_root(y)

  def size(self, x):
    return -self.n[self.find_root(x)]

  def set_count(self):
    return self.co

import sys
input = lambda:sys.stdin.readline().rstrip()

n, m = map(int, input().split())
uf = UnionFind(n)
for _ in range(m):
  a, b = map(int, input().split())
  uf.unite(a-1, b-1)
print(uf.set_count()-1)

Measured memory_bytes: 11604
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>
#include <cassert>
#include <bitset>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define EL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

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


signed main() {
	int t;
	std::cin >> t;
	rep(tt,t) {
		int a,b,c,d;
		std::cin >> a >> b >> c >> d;
		if(b>a) print("No");
		else if(b>d) print("No");
		else if(c>=b) print("Yes");
		else {
			int g=gcd(b,d);
			if(c<b-g+a%g) print("No");
			else print("Yes");
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         cout<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
#define endl            "\n"


 
void fastIO()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}


void solve()
{
    string str;

    cin>>str;

    if(str.length()>=6&&str[2]==str[3]&&str[4]==str[5])
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
}
 
 
 
int32_t main()
{
    fastIO();
    //w(t)
    {
        solve();
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#define	MOD  1000000007;
using namespace std;

int pow(int A, int B)
{
	if (B % 2 == 1)
	{
		return pow(A*A, B / 2)* A;
	}
	else if (B == 0)
	{
		return 1;
	}
	else if (B % 2 == 0)
	{
		return pow(A*A, B / 2);
	}
}
int main()
{
	int N, K;
	cin >> N >> K;

	int M = pow(K - 1, N - 1);

	cout << K * M;

	return 0;
}

Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n = int(input())
    a = list(map(int, input().split()))
    cnt = [0] * (max(a)+3)
    
    for i in a:
        cnt[i-1] += 1
        cnt[i] += 1
        cnt[i+1] += 1
        
    print(max(cnt))
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 20884
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rrep(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr ll INF = (ll)1e9;
constexpr ll mod = (ll)1e9 + 7;
constexpr double PI = 3.1415926535897932;
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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

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

const int A = 1000010;
int main() {
	init();

	int N; cin >> N;
	vector<int>vec(N);
	vector<int>c(A, 0);
	rep(i, 0, N) {
		cin >> vec[i];
		c[vec[i]]++;
	}
	bool ok = true;
	rep(i, 2, A) {
		int cnt = 0;
		for (int j = i;j < A;j += i) {
			cnt += c[j];
		}
		if (cnt >= 2)ok = false;
	}
	ll g = vec[0];
	rep(i, 0, N)g = gcd(g, vec[i]);
	if (ok) {
		puts("pairwise coprime");
		return 0;
	}
	else if (g == 1) {
		puts("setwise coprime");
	}
	else {
		puts("not coprime");
	}

	return 0;
}

Measured memory_bytes: 11112
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long
#define ld long double
#define MAX 1000000000
#define MOD 1000000007
#define MOD2 998244353
long long binpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin>>t;
    for(int cc=1;cc<=t;cc++){
        //cout<<"Case #"<<cc<<": ";
        int n;
        cin>>n;
        string s[n];
        for(int i=0;i<n;i++)
            cin>>s[i];
        sort(s,s+n);
        int ans=1;
        for(int i=1;i<n;i++){
            if(s[i]!=s[i-1])
                ans++;
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 9908
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
int main()
{
	char a[110];//,cnt=0;
	int cnt=0;
	scanf("%s",&a);
	int n=strlen(a);
	for(register int i=0;i<=n;i++)
	{
		if(a[i]=='C')
		{ 
			for(register int j=i+1;j<=n;j++)
			if(a[j]=='F')
			{
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

MOD = 998244353
N, A, B, K = lr()
answer = 0
# A * x + B * y = K
# nCx * nCy

def cmb(n, k):
    if k < 0 or k > n: return 0 
    return fact_N * fact_inv[k] % MOD * fact_inv[n-k] % MOD

def cumprod(arr, MOD):
    L = len(arr); Lsq = int(L**.5+1)
    arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq)
    for n in range(1, Lsq):
        arr[:, n] *= arr[:, n-1]; arr[:, n] %= MOD
    for n in range(1, Lsq):
        arr[n] *= arr[n-1, -1]; arr[n] %= MOD
    return arr.ravel()[:L]

def make_fact(U, MOD):
    x = np.arange(U, dtype=np.int64); x[0] = 1
    fact = cumprod(x, MOD)
    x = np.arange(U, 0, -1, dtype=np.int64); x[0] = pow(int(fact[-1]), MOD-2, MOD)
    fact_inv = cumprod(x, MOD)[::-1]
    return fact, fact_inv

U = N + 100 # 階乗テーブルの上限
fact, fact_inv = make_fact(U, MOD)
fact_N = fact[N]

for x in range(N+1):
    temp = K-A*x
    if temp%B != 0:
        continue
    y = temp // B
    if y > N:
        continue
    if y < 0:
        break
    answer += cmb(N, x) * cmb(N, y)
    answer %= MOD

print(answer % MOD)


Measured memory_bytes: 24212
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define log(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline void print(T&& x){cout<<x<<endl;}// 改行付き出力
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return c-'0';}


// TODO: write
int main() {
  int n,k;cin>>n>>k;
  vector<bool> a(n,false);
  rep(i,k){
    int d;cin>>d;
    rep(j,d){
      int tmp;cin>>tmp;
      a[tmp-1] = true;
    }
  }
  int ans = 0;
  rep(i,n)ans += !a[i];
  print(ans);
  return 0; 
}


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

int main()
{
  int N;
  string s;

  cin >> s;
  N = s.size();
  for (int i = 0; i < N; i++)
  {
    if (i % 2 == 0)
      cout << s.at(i);
  }
  cout << endl;
}

Measured memory_bytes: 512
#include <cstdio>
#include <algorithm>

using namespace std;

typedef long long ll;

ll n, m, v, p;
ll a[100021];

bool Cmp(int x, int y) {
	return x > y;
}

bool Valid(int d) {
	if (d <= p) return true;
	for (int i = d; i >= 1; --i) {
		if (a[i] != a[d]) {
			d = i + 1;
			break;
		}
	}
	ll s = (p + n - d) * m;
	for (int i = p; i < d; ++i) {
		if (a[d] + m < a[i]) return false;
		s += (a[d] + m - a[i]);
	}
	return s >= m * v;
}

int main() {
	scanf("%lld%lld%lld%lld", &n, &m, &v, &p);
	for (int i = 1; i <= n; ++i)
		scanf("%d", &a[i]);
	sort(a + 1, a + n + 1, Cmp);
	// for (int i = 1; i <= n; ++i)
		// printf("%d ", a[i]);
	// printf("\n");
	int l = 1, r = n;
	while (l < r) {
		int mid = l + r + 1 >> 1;
		if (Valid(mid)) l = mid;
		else r = mid - 1;
	}
	printf("%d\n", l);
	return 0;
}

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

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb puah_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    int n; cin >> n;
    vector<int> lis(n+2, 0);
    REP(i, 0, n){cin >> lis[i+1];}
    vector<int> dif(n+1, 0);// ruiseki1(n+2, 0);
    ll sum = 0;
    REP(i, 0, n+1){
        dif[i] = abs(lis[i] - lis[i+1]);
        sum += dif[i];
    }
    //REP(i, 0, n+1){ruiseki[i+1] = ruiseki[i] + dif[i];}
    REP(i, 0, n){
        cout << sum - dif[i] - dif[i+1] + abs(lis[i] - lis[i+2]) << endl;
    }
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int n, k;
    cin >> n >> k;
    ll ans = k;
    for(int i = 1; i < n; i++)
        ans *= (k-1);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3620
from statistics import mean, median,variance,stdev
import sys
import math
import fractions

def j(q):
    if q==1: print("AC")
    else:print("WA")
    exit(0)


def ct(x,y):
    if (x>y):print("")
    elif (x<y): print("")
    else: print("")

def ip():
    return int(input())

#n = ip()                              #入力整数1つ
d,n= (int(i) for i in input().split())      #入力整数横2つ
#x,y,z = (int(i) for i in input().split())    #入力整数横3つ
#n,m,x,y= (int(i) for i in input().split())  #入力整数横4つ
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列

#jの変数はしようできないので注意
#xor は(a ^ b)でいける
if n == 100:
    print(pow(100,d)*101)
else :print(pow(100,d)*n)


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

int main(){
	int n;
	scanf("%d", &n);
	f(i, 0, n){
		int t;
		scanf("%d", &t);
		if (t & 1) { printf("first\n"); return 0; }
	}
	printf("second\n");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long t,n,k,i=0;
long long arr[10000005];
int main(){

    cin>>t;
    while(t--){

        cin>>k;
        if(k==0){
            cin>>n;     ///What is the element you want to insert??
            arr[i]=n;
            i++;
        }
        if(k==2){
            i--;
        }
        if(k==1){
                cin>>n;
           cout<<arr[n]<<endl;
        }


    }

}




Measured memory_bytes: 4600
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 5000000000000000000
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    int x[51], y[51];
    rep(i, N) cin >> x[i] >> y[i];
    int ans = INF2;
    rep(i, N) {
        rep(j, N) {
            if (x[i] > x[j]) continue;
            rep(k, N) {
                if(x[j] > x[k]) continue;
                rep(s, N) {
                    if(x[k] > x[s]) continue;
                    int L = min({x[i], x[j], x[k], x[s]});
                    int R = max({x[i], x[j], x[k], x[s]});
                    int U = min({y[i], y[j], y[k], y[s]});
                    int D = max({y[i], y[j], y[k], y[s]});
                    int cnt = 0;
                    rep(t, N) {
                        if(L <= x[t] && x[t] <= R && U <= y[t] && y[t] <= D) cnt++;
                        if(cnt >= K || cnt + N - t < K) break;
                    }
                    if(cnt >= K) ans = min(ans, (R - L) * (D - U));
                }
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
require 'pp'
m, d = gets.split.map &:to_i
cnt = 0
1.upto(m) do |mm|
  1.upto(d) do |dd|
    next if dd.to_s.size != 2
    next if dd.to_s[0].to_i < 2 || dd.to_s[1].to_i < 2
    cnt += 1 if dd.to_s[0].to_i * dd.to_s[1].to_i == mm
  end
end
p cnt


Measured memory_bytes: 2300