akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define MAXN 3010
#define pii pair<int, int>
#define pb push_back
typedef long long ll;

using namespace std;

int n;
double dp[MAXN][MAXN], p[MAXN], ans;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> p[i];
    }
    dp[0][0] = 1.0 - p[0];
    dp[0][1] = p[0];
    if(n == 1){
        cout << p[0];
        return 0;
    }
    for(int i = 1; i < n; i++){
        for(int j = 0; j <= i + 1; j++){
            dp[i][j] = dp[i - 1][j] * (1 - p[i]);
            if(j > 0) dp[i][j] += dp[i - 1][j - 1] * p[i];
            if(i == n - 1 and j > n / 2) ans += dp[i][j];
        }
    }
    cout << fixed << setprecision(9) << ans;
}

Measured memory_bytes: 69120
using System;

namespace AOJ.Volume1
{
    public class OhajikiGame
    {
        public static int Main()
        {
            while (true)
            {
                int n = int.Parse(Console.ReadLine());
                if (n == 0) { break; }

                var jiro = new int[n];
                var input = Console.ReadLine().Split(' ');
                for (int i = 0; i < n; i++) { jiro[i] = int.Parse(input[i]); }

                // ゲーム開始
                int oha = 32;
                int jiro_sel = 0;
                bool taro_turn = true;
                while (oha > 0)
                {
                    if (taro_turn)
                    {
                        oha = oha - ((oha - 1) % 5);
                        taro_turn = false;
                    }
                    else
                    {
                        oha = oha - jiro[jiro_sel];
                        if (oha < 0) { oha = 0; }

                        jiro_sel++;
                        if (jiro_sel % n == 0) { jiro_sel = 0; }
                        taro_turn = true;
                    }
                    Console.WriteLine(oha);
                }
            }
            return 0;
        }
    }
}

Measured memory_bytes: 9156
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; (int)(i) < n; i++)

using namespace std;

const double pi = acos(-1);
int main() {
  double a, b, h, m, ans;
  cin >> a >> b >> h >> m;
  h = (60*h + m) * (pi / 360);
  m *=  (pi / 30);
  double ang = abs(h - m); 
  double dx = a*sin(h) - b*sin(m);
  double dy = a*cos(h) - b*cos(m);
  ans = sqrt(dx*dx + dy*dy);
  printf("%.10f\n", ans);
}

Measured memory_bytes: 4152
#include<iostream>

using namespace std;

int N;
int A[30];

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

    bool flag = false;

    for(int i = 0;i < N;i++){
        flag = false;
        for(int j = 0; j < i; j++){
            if(A[i] < A[j]){
                flag = true;
            }
        }
        if(!flag){
            total++;
        }
    }

    cout << total << endl;
}

Measured memory_bytes: 256
N = int(input())
X = []
for i in range(0, N):
    x = list(map(int, input().split()))
    X.append(x)
dp = []
for i in range(0, N+1):
    dp.append([0, 0, 0])
for i in range(1, N+1):
    for j in range(0, 3):
        for k in range(0, 3):
            if j == k:
                continue
            else:
                dp[i][k] = max(dp[i][k], dp[i-1][j]+X[i-1][k])
print(max(dp[N]))


Measured memory_bytes: 47328
#include<iostream>
#include<cmath>

using namespace std;

int main() {
	long long x, y;
	cin >> x >> y;
	if (x*y >= 0) {
		if (y >= x)
			cout << abs(y - x) << endl;
		else if (y == 0)
			cout << abs(x) + 1 << endl;
		else if (x == 0)
			cout << abs(y) + 1 << endl;
		else
			cout << abs(abs(y) - abs(x)) + 2 << endl;
	}
	else {
		cout << abs(abs(y) - abs(x)) + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

const int mod = 1000000007;

int N;
int a[25][25];
int dp[1 << 21];
int bitcnt[1 << 21];

int main()
{
	cin >> N;

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

	dp[0] = 1;

	for (int S = 1; S < (1 << N); ++S) {
		bitcnt[S] = bitcnt[S >> 1] + (S & 1);

		for (int l = 0; l < N; ++l) {
			if ((S >> l & 1) == 0) continue;
			dp[S] += dp[S - (1 << l)] * a[bitcnt[S] - 1][l];
			dp[S] %= mod;
		}
	}

	cout << dp[(1 << N) - 1] << endl;
}


Measured memory_bytes: 16640
def p_b():
    N = int(input())
    p_n = list(map(int, input().split()))

    p_sort = sorted(p_n)
    cnt = 0

    for a, b in zip(p_n, p_sort):
        if a != b:
            cnt += 1

    if cnt == 0 or cnt == 2:
        print("YES")
    else:
        print("NO")


if __name__ == '__main__':
    p_b()


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

int main(){
    int r,c;
    int i,j;
    int d[101][101];
    int cc=0;
    int cr=0;
    
    cin >> r >> c;
    
    for (i=0;i<r;i++){
        for (j=0;j<c;j++){
            cin >> d[i][j];
            cc = cc + d[i][j];
            if (j==c-1)d[i][j+1]=cc;
        }
        cc =0;
    }
    
    for (j=0;j<c+1;j++){
        for (i=0;i<r;i++){
            cr = cr + d[i][j];
            if (i==r-1)d[i+1][j]=cr;
        }
        cr =0;
    }
    
    for (i=0;i<r+1;i++){
        for (j=0;j<c+1;j++){
            if (j==c){
                cout << d[i][j] << endl;;
            }else{
                cout << d[i][j] <<' ';
            }
        }
    }
    
    return 0;
}

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

int main() {
int n;
cin >> n;
long long a[n];
long long sum1[n], sum2 = 0, sum = 0;
for(int i = 0; i < n; ++i){
	cin >> a[i];
	sum += a[i];
	sum1[i] = sum;
}
long long ans = LLONG_MAX;
for(int i = 0; i < n; ++i){
	long long a = sum1[i];
	long long b = sum - sum1[i];
	long long x = abs(a-b);
	ans = min(x, ans);
}
cout << ans;
return 0;
}

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

int main() {
    unordered_set<int> visit;
    for(int i = 1; i <= 9; i++) {
        for(int j = 1; j <= 9; j++) {
            visit.insert(i*j);
        }
    }
    int n;
    cin >> n;
    if (visit.count(n) > 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}





int main() {

	ll N, M, X, Y;
	cin >> N >> M >> X >> Y;
	ll MX = X, mY = Y;
	rep(i, N) {
		ll x;
		cin >> x;
		MX = max(MX, x);
	}
	rep(i, M) {
		ll y;
		cin >> y;
		mY = min(y, mY);
	}
	if (mY > MX) {
		cout << "No War" << endl;
	}
	else {
		cout << "War" << endl;
	}


}



Measured memory_bytes: 3556
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------

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

    cout << 180 * (n - 2) << endl;
}

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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	char y;
	int ret=0;
	string s="CODEFESTIVAL2016";
	for (char &x : s) {
		cin>>y;
		if(x!=y) ret++;
	}
	cout<<ret<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
using namespace std;
int main() {
    string s;
    cin >> s;
	int a[26];
	memset(a, 0, sizeof(a));
	for (int i = 0; i < s.size(); i++) {
		char c = s[i];
		a[c-'a'] ++;
	}
	
	bool flag = true;
	for (int i = 0; i < 26; i++) {
		if (a[i] & 1) {
			flag = false;
			break;
		}
	}
	if (flag) 
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <map>
#include <cmath>
using namespace std;
 
typedef long long i64;
const int MAX_N = 100005;
const i64 LIM = 20000000000LL;
 
int pr[MAX_N], tot;
i64 S[MAX_N];
 
void init_prime() {
  static bool vis[MAX_N];
  for (int i = 2; i < MAX_N; ++i) 
    if (!vis[i]) {
      pr[++tot] = i;
      for (int j = i; j < MAX_N; j += i)
	vis[j] = 1;
    }
}
 
int N;
 
map<i64, i64> back, NUM;
map<i64, i64>::iterator iter;
 
bool mul(i64 &x, i64 y) {
  if ((double) LIM / x < y) return false;
  x *= y;
  return true;
}
 
int main() {
  init_prime();
  
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) scanf("%lld", &S[i]);
 
  int res = 0;
  
  for (int i = 1; i <= N; ++i) {
    i64 temp = S[i], anti = 1;
    bool flag = 1;
    for (int j = 1; 1LL * pr[j] * pr[j] * pr[j] <= temp; ++j) 
      if (temp % pr[j] == 0) {
	int cnt = 0;
	while (temp % pr[j] == 0) temp /= pr[j], S[i] /= pr[j], cnt++;
	cnt %= 3;
	if (cnt == 1) S[i] *= pr[j], flag &= mul(anti, pr[j] * pr[j]);
	else if (cnt == 2) S[i] *= pr[j] * pr[j], flag &= mul(anti, pr[j]);
      }
 
    int x = sqrtl(temp);
    if (1LL * x * x == temp) flag &= mul(anti, x);
    else flag &= mul(anti, temp * temp);
    
    if ((1LL * x * x != temp && temp > 1000000000) || !flag) {
      res++;
      continue;
    }
    
    NUM[S[i]]++, back[S[i]] = anti, back[anti] = S[i];
  }
 
  for (iter = back.begin(); iter != back.end(); ++iter) {
    if (iter->first == 1) {
      res++;
      continue;
    }
    if (iter->first > iter->second) continue;
    res += max(NUM[iter->first], NUM[iter->second]);
  }
 
  printf("%d\n", res);
  
  return 0;
}

Measured memory_bytes: 21760
#include<bits/stdc++.h>
using namespace std;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}


typedef pair<int, int> pii;

const int MAX = 200005;
int h[MAX];
int n;
long long a[MAX], dp[MAX];

typedef struct item * pitem;

struct item {
    int key, prior;
    long long val, maximo = 0;
    item * l, * r;
    item() { }
    item (int key, int prior, long long val) : key(key), prior(prior), l(NULL), r(NULL), val(val){ }
};

typedef item * pitem;

long long maximo (pitem t) {
    return t ? t-> maximo : 0;
}

void upd_maximo (pitem t) {
    if (t)
        t->maximo = max(t->val, max(maximo(t->l), maximo(t->r)));
}

void split (pitem t, int key, pitem & l, pitem & r) {
    if (!t)
        l = r = NULL;
    else if (key <= t->key)
        split (t->l, key, l, t->l),  r = t;
    else
        split (t->r, key, t->r, r),  l = t;
    upd_maximo(t);
}

void insert (pitem & t, pitem it) {
    if (!t)
        t = it;
    else if (it->prior > t->prior)
        split (t, it->key, it->l, it->r),  t = it;
    else
        insert (it->key < t->key ? t->l : t->r, it);
    upd_maximo(t);
}

void merge (pitem & t, pitem l, pitem r) {
    if (!l || !r)
        t = l ? l : r;
    else if (l->prior > r->prior)
        merge (l->r, l->r, r),  t = l;
    else
        merge (r->l, l, r->l),  t = r;
    upd_maximo(t);
}

void erase (pitem & t, int key) {
    if (t->key == key)
        merge (t, t->l, t->r);
    else
        erase (key < t->key ? t->l : t->r, key);
    upd_maximo(t);
}

long long query(pitem &t, int h){
    pitem l, r;
    split(t, h, l, r);
    long long ans = maximo(l);
    merge(t, l, r);
    return ans;
}

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

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

    long long val, rta = 0;
    pitem treap = NULL;
    for(int i = 0; i<n; ++i){
        val = query(treap, h[i]);
        //error(val, i);
        val+=a[i];
        pitem p = new item(h[i], rand(), val);
        insert(treap, p);
        rta = max(rta, val);

    }
    cout<<rta<<"\n";
}


Measured memory_bytes: 15344
#include<bits/stdc++.h>
using namespace std;
int main(){
  	int n,i;
  	cin>>n;
  	int a[n];
  	map<int,int> mp;
  	for(i=0;i<n-1;++i){
      	cin>>a[i];
      	mp[a[i]]++;
    }
  	for(i=1;i<=n;++i)
      cout<<mp[i]<<"\n";
}	


Measured memory_bytes: 13784
{-# OPTIONS_GHC -O #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ViewPatterns #-}

import Data.List (scanl, unfoldr, foldl')
import qualified Data.ByteString.Char8 as B
import qualified Data.IntSet as S

import Control.Monad
import Control.Monad.ST
import Data.STRef
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as MV

cntInv :: [Int] -> Int
cntInv xs' = runST $ do
  cnt <- newSTRef 0 :: ST s (STRef s Int)
  xs  <- V.unsafeThaw $ V.fromList xs' :: ST s (MV.STVector s Int)
  len <- pure $ MV.length xs
  buf <- MV.new len :: ST s (MV.STVector s Int)
  --
  forM_ [(cs,ix)|cs<-takeWhile(<len)$iterate(*2)1, ix<-[0,cs*2..len-cs-1]] $ \(cs,ix) -> do
    lbuf <- pure $ MV.unsafeSlice ix cs xs
    rbuf <- pure $ MV.unsafeSlice (ix+cs) ((min len (ix+cs*2))-(ix+cs)) xs
    dc <- merge lbuf rbuf buf 0 0 0 0
    modifySTRef' cnt (+dc)
  --
  readSTRef cnt
  --
  where
    merge :: MV.STVector s Int -> MV.STVector s Int -> MV.STVector s Int -> Int ->Int -> Int -> Int -> ST s Int
    merge lbuf@(MV.length->llen) rbuf@(MV.length->rlen) buf ixl ixr ix !cnt
      | ixl == llen && ixr == rlen = do
        forM_ [0..llen-1] $ \i -> MV.unsafeRead buf i >>= MV.unsafeWrite lbuf i
        forM_ [0..rlen-1] $ \i -> MV.unsafeRead buf (llen+i) >>= MV.unsafeWrite rbuf i
        return cnt
      --
      | ixl == llen = MV.unsafeRead rbuf ixr >>= MV.unsafeWrite buf ix >> merge lbuf rbuf buf ixl (ixr+1) (ix+1) cnt
      --
      | ixr == rlen = MV.unsafeRead lbuf ixl >>= MV.unsafeWrite buf ix >> merge lbuf rbuf buf (ixl+1) ixr (ix+1) cnt
      --
      | True = do
        lv <- MV.unsafeRead lbuf ixl
        rv <- MV.unsafeRead rbuf ixr
        if lv<=rv
          then MV.unsafeWrite buf ix lv >> merge lbuf rbuf buf (ixl+1) ixr (ix+1) cnt
          else MV.unsafeWrite buf ix rv >> merge lbuf rbuf buf ixl (ixr+1) (ix+1) (cnt+llen-ixl)

si as x = cntInv $ scanl (\ac a->if a>=x then ac+1 else ac-1) 0 as

bsearch f (a,b)
  | a+1 == b = a
  | f m  = bsearch f (m,b)
  | True = bsearch f (a,m)
  where m = (a + (b-a)`div`2)

ff av as tn x = niv >= (tn+1)`div`2
  where
    niv = (-) tn $ si as $ av V.! x

main=do
  n<-readLn::IO Int
  !as<-unfoldr (B.readInt.B.dropWhile(==' '))<$>B.getLine::IO[Int]
  let !av = V.fromList $ S.toAscList $ S.fromList as
  let !tn = (n*(n+1))`div`2
  print $ (V.!) av $ bsearch (ff av as tn) (-1,V.length av)

Measured memory_bytes: 29052
#include <bits/stdc++.h>
#define int long long
using namespace std;
int N,K,h[100000+10]={},ans=1145141919810;

signed main(){
  cin >> N >> K;
  for(int i=0;i<N;i++){
    cin >> h[i];
  }
  sort(h,h+N);
  for(int i=0;i<=N-K;i++){
    ans=min(ans,h[K-1+i]-h[i]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
    string s, S;
    cin >> s;
    int N = s.size();
    s += '.';
    for(int i = 0; i < N; i++) {
        if(s[i] == 'B' && s[i + 1] == 'C') {
            S += 'D';
            i++;
        } else
            S += s[i];
    }
    N = S.size();
    ll A = 0, ans = 0;
    for(int i = 0; i < N; i++) {
        if(S[i] == 'A')
            A++;
        else if(S[i] == 'D')
            ans += A;
        else
            A = 0;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 776
#include<stdio.h>
#include<stdlib.h>
#include<bits/stdc++.h>
#define ll long long
#define fast_io cin.tie(0);cout.tie(0);ios::sync_with_stdio(0)
#define MOD 1000000007
using namespace std;

int main(){
	fast_io;
	ll n,l;
	cin>>n>>l;
	vector<ll> a;
	int z = 0;
	ll pc = 0;
	ll nc = 0;
	ll sp = INT_MAX;
	ll sn = INT_MAX;
	for(int i=1;i<=n;i++){
        ll x;
        x = l+i-1;
        a.push_back(x);
        if(x == 0){
            z=1;
        }
        if(x>0){
            pc++;
            sp = min(sp,x);
        }
        if(x<0){
            nc++;
            sn = min(sn,abs(x));
        }
	}
	ll ans = 0;
	if(z){
        for(int i=0;i<a.size();i++){
            ans+=a[i];
        }
        cout<<ans;
        return 0;
	}
	if(pc==0){
        for(int i=0;i<a.size();i++){
            if(abs(a[i])!=sn){
                ans+=a[i];
            }
        }
        cout<<ans;
        return 0;
	}
	else{
        for(int i=0;i<a.size();i++){
            if(a[i]!=sp){
                ans+=a[i];
            }
        }
        cout<<ans;
        return 0;
	}
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

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

const long long MOD = 1e9+7;

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

int main() {
    int n;
    cin >> n;
    vector<vector<int>> x(2, vector<int>(n));
    rep(i, 2) rep(j, n) cin >> x[i][j];

    const int INF = 1000;
    vector<vector<int>> dp(1 << n, vector<int>(n + 1, INF));
    dp[0][n] = 0;
    rep(bit, 1 << n) rep(i, n + 1) rep(j, n) {
        if (bit >> j & 1) continue;

        int cnt = popcnt(bit);
        int last_num = 0;
        if (i < n) last_num = x[abs(cnt - 1 - i) % 2][i];
        int new_num = x[abs(cnt - j) % 2][j];
        if (last_num <= new_num) {
            int rev = 0;
            repr(k, j, n) if (bit >> k & 1) rev++;
            chmin(dp[bit | (1 << j)][j], dp[bit][i] + rev);
        }
    }

    int ans = INF;
    rep(i, n) chmin(ans, dp[(1 << n) - 1][i]);
    if (ans == INF) cout << -1 << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 30976
def lcm(a,m):
    from fractions import gcd
    x = a[0]
    for i in range(1, len(a)):
        
        x = (x * a[i]) // gcd(x, a[i])
        if x > m:
            return m+1
    return x

def count2div(n):
    count=0
    while not n%2:
        n/=2
        count+=1
    return count

n,m = map(int, input().split())
a = list(map(int, input().split()))
b = [i//2 for i in a]
c = [0 for i in a]
b_f = True
for i in range(n):
    c[i] = count2div(b[i])
for i in range(n-1):
    if c[i] != c[i+1]:
        b_f = False
lcm = lcm(b,m)
i=1
count=0
if m >= lcm:
    m-=lcm
    count = m//(lcm*2) + 1
if b_f:
    print(count)
else:
    print(0)

Measured memory_bytes: 15060
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

typedef pair<int, int> P;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int H, W, h, w;
    cin >> H >> W >> h >> w;
    cout << (H - h) * (W - w) << endl;
    return 0;
}


Measured memory_bytes: 888
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int x = sc.nextInt();
		sc.close();
		System.out.println(k*500>=x?"Yes":"No");
	}

	public static int arrayMax(int[] array) {
		int ans = Integer.MIN_VALUE;
		for (int i = 0; i < array.length; i++) {
			if (array[i] > ans)
				ans = array[i];
		}
		return ans;
	}

	public static int[] arrayInt(Scanner sc, int n) {
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		return array;
	}

	public static long[] arrayLong(Scanner sc, int n) {
		long[] array = new long[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextLong();
		}
		return array;
	}

	public static double[] arrayDouble(Scanner sc, int n) {
		double[] array = new double[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextDouble();
		}
		return array;
	}
}


Measured memory_bytes: 21716
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U& u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U& u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
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; }

std::vector<ll> enum_div(ll n)//nの約数を列挙
{
	std::vector<ll> ret;
	for (ll i = 1; i * i <= n; ++i)
	{
		if (n % i == 0)
		{
			ret.push_back(i);
			if (i * i != n)
			{
				ret.push_back(n / i);
			}
		}
	}
	return ret;
}


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N;
	cin >> N;
	vll V = enum_div(N);
	ll ans = 0;
	REP(i, SZ(V)) {
		if (V[i] == 1)continue;
		ll x = V[i] - 1;
		ll p = N / x;
		if (N % x == p) {
			ans += V[i] - 1;
		}
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
  int64_t a,b,k;
  cin >> a >> b >> k;
  if( a >= k ){
    a -= k;
  }else if( a+b <= k ){
    a = 0;
    b = 0;
  }else{
    b -= k-a;
    a = 0;
  }
  cout << a << " " << b << endl;
  return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    total = 0
    for i in range(1,n+1):
        if i % 3 == 0 and i % 5 == 0:
            pass
            #print("FizzBuzz")
        elif i%3 == 0:
            pass
            #print("Fizz")
        elif i%5 == 0:
            pass
            #print()
        else:
            total += i
    print(total)



if __name__ == '__main__':
    main()


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

int main() {
	int n, m, a, b, c, d, i, j, k, x[32][32];
	cin >> n >> m;
	for(i = 1; i <= n; i++)
		for(j = 1; j <= n; j++)
			x[i][j] = 1001001001;	for(i = 0; i < m; i++) {
		scanf("%d,%d,%d,%d", &a, &b, &c, &d);
		x[a][b] = c;
		x[b][a] = d;
	}
	for(k = 1; k <= n; k++)
		for(i = 1; i <= n; i++)
			for(j = 1; j <= n; j++)
				if (x[i][j] > x[i][k] + x[k][j]) x[i][j] = x[i][k] + x[k][j];
	scanf("%d,%d,%d,%d", &a, &b, &c, &d);
	cout << c - d - x[a][b] - x[b][a] << endl;
	return 0;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
using namespace std;
const int M=2e5 +10;
long long a[M],b[M],n;
int main(){
	cin >> n;
	for(long long i=1;i<=n;i++){
		int x,y;
		cin >> x >> y;
		a[i]=y-x;b[i]=x+y;
	}
	sort(1+a,a+1+n);
	sort(b+1,b+n+1);
	long long ans = max(a[n]-a[1],b[n]-b[1]);
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 6752
#include <bits/stdc++.h>
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define deb(x) cout<<#x<<"="<<x<<endl;
#define endl '\n'
#define M 1000000007
#define int long long
#define max_n 1000000

using namespace std;

void solve()
{
	ll n,m;
	cin>>n>>m;
	ll h[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>h[i];
	}
	vector<ll> g[n];
	ll ans[n]={0};
	for (int i = 0; i < m; ++i)
	{
		ll x,y;
		cin>>x>>y;
		x--,y--;
		g[x].push_back(y);
		g[y].push_back(x);
		if(h[x]>h[y])
		ans[x]++;
		if(h[y]>h[x])
		ans[y]++;
	}
	ll sans=0;
	for (int i = 0; i < n; ++i)
	{
		if(ans[i]==g[i].size())
		sans++;
	}
	cout<<sans<<endl;
}

int32_t main() 
{
	IOS	
	ll T=1;
	// cin>>T;
	for(ll i=1;i<=T;++i)
	{		
		// cout<<"Case #"<<i<<": ";
    	solve();
	}
	return 0;
}

Measured memory_bytes: 11064
N, A, B, C = map(int, input().split())
mod = int(1e+9 + 7)
p = mod - 2
ax = []
while p != 0:
  ax = [p%2] + ax[:]
  p //= 2

def prod(l, num):
  n1 = 1
  for i in range(len(l)):
    if l[i] == 1:
      n1 *= num
      n1 %= mod
    if i != len(l)-1:
      n1 *= n1
      n1 %= mod
  return n1
nn = N - 1
bx = []
while nn != 0:
  bx = [nn%2] + bx[:]
  nn //= 2
invC = prod(ax, 100-C)
AN, BN, CN = 1, 1, prod(bx, 100 - C)
s1, s2 = 0, 0
p1 = 1
for i in range(N):
  p1 *= (i+1)
  p1 %= mod
p2 = p1
for i in range(N):
  s1 += p1 * BN * CN
  s1 %= mod
  s2 += p1 * AN * CN
  s2 %= mod
  if i != N - 1:
    p1 *= (N + 1 + i) * prod(ax, i+1)
    p1 %= mod
  CN *= invC
  CN %= mod
  AN *= A
  AN %= mod
  BN *= B
  BN %= mod

s1, s2 = (N * 100 * AN) * s1, (N * 100 * BN) * s2
S = (s1 + s2) % mod
S *= (prod(bx, (invC*invC)%mod) * prod(ax, p2) * (invC * invC)) % mod
print(S%mod)

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

int main(){
  
  int a, b, c;
  cin >> a >> b >> c;
  
  if (a==b+c || b==a+c || c==a+b){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
ll MOD=1e9+7;
#define INF 2*1e18
#define N 600010
using namespace std;
vector<int> G[N];
int a[N];
int check[N]={};
int t[N][2]={};
void erase(int x){
    check[x]=0;
    int f=a[x];
    rep(i,G[x].size()){
        t[G[x][i]][f]--;
        if(t[G[x][i]][f]==0&&check[G[x][i]])erase(G[x][i]);
    }
}
main(){
    int n,m;
    cin>>n>>m;
    string s;
    cin>>s;
    
    rep2(i,1,n){
        if(s[i-1]=='A')a[i]=1;
        else a[i]=0;
    }
    pii p[N];
    rep(i,m){
        int c,d;
        cin>>c>>d;
        p[i].first=c;p[i].second=d;
        G[c].pb(d);G[d].pb(c);
    }

    rep2(i,1,n){
        rep(j,G[i].size()){
            t[i][a[G[i][j]]]++;
        }
        if(t[i][0]>0&&t[i][1]>0){
            check[i]=1;
        }
        else erase(i);
    }
    int ans=0;
    rep2(i,1,n){
        ans=ans|check[i];
    }
   if(ans)cout<<"Yes";else cout<<"No";
}


Measured memory_bytes: 29444
n=int(input())
d=dict()
for i in map(int,input().split()):
  if i not in d:
    d[i]=1
  else:
    d[i]+=1
ans=[0,0]
for i in d.keys():
  for _ in range(d[i]//2):
    ans.append(i)
ans.sort(reverse=1)
print(ans[0]*ans[1])

Measured memory_bytes: 23564
def read_input():
    s = input()
    return s

def submit():
    s = read_input()

    for i, (l, r) in enumerate(zip(s, s[1:])):
        if l == r:
            print('{} {}'.format(i + 1, i + 2))
            return

    for i, (l, r) in enumerate(zip(s, s[2:])):
        if l == r:
            print('{} {}'.format(i + 1, i + 3))
            return

    print('-1 -1')


if __name__ == '__main__':
    submit()


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

#define uint        unsigned int
#define ld          long double
#define int         long long
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        400005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
//#define mod         1000000007
#define pqueue      priority_queue<int>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>

using namespace std;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//const int md = 998244353;

/*const int mod = 998244353;
int power(int a,int n)
{
    if(n == 1)return a%mod;
    if(n == 0)return 1;
    if(n&1)return ((a%mod)*(power((a*a)%mod,n/2))%mod)%mod;
    return power((a*a)%mod,n/2)%mod;
}
*/
int cnt[maxn];
int solve(int sum,int tot){

    return sum+tot*tot;
}

signed main()
{
    showoff;
    int n,k;
    cin >> n >> k;
    vector<pii>v;
    FOR(i,0,n){
    int t,d;
    cin >> t >> d;
    v.pb({-1*d,t});
    }
    sort(v.begin(),v.end());
    int sum = 0,tc = 0;
    FOR(i,0,k){
    sum += -1*v[i].f;
    if(cnt[v[i].se] == 0)tc++;
    cnt[v[i].se]++;
    }
    int ptr = k-1,ans = solve(sum,tc);
    FOR(i,k,n){
    if(cnt[v[i].se] > 0)continue;
    while(ptr >= 0 && cnt[v[ptr].se] == 1){
        --ptr;
    }
    if(ptr >= 0){
        sum = sum+v[ptr].f-v[i].f;
        tc = tc+1;
        ans = max(ans,solve(sum,tc));
        ++cnt[v[i].se];
        --cnt[v[ptr].se];
        --ptr;
    }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 2672
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define STRINGIFY(n) #n
#define TOSTRING(n) STRINGIFY(n)
#define PREFIX "#" TOSTRING(__LINE__) "| "
#define debug(x) \
{ \
  std::cout << PREFIX << #x << " = " << x << std::endl; \
}

std::ostream& output_indent(std::ostream& os, int ind) {
  for(int i = 0; i < ind; i++) os << " ";
  return os;
}

template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p);
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v);

template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p) {
  return (os << "(" << p.first << ", " << p.second << ")");
}
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
  os << "[";
  for(int i = 0;i < v.size();i++) os << v[i] << ", ";
  return (os << "]");
}

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); }
template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
template<class Cond> struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  template<class T> bool operator()(T& a, const T& b) const { if(cond(a, b)) { a = b; return true; } return false; }
};
template<class Cond> chain<Cond> make_chain(Cond cond) { return chain<Cond>(cond); }

int main() {
  i64 L, R;
  cin >> L >> R;
  i64 d;
  cin >> d;
  i64 ans = 0;
  rep(i,L,R + 1) {
    if(i % d == 0) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3592
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>

using namespace std;

using ll = long long;
#define REP(i, n) for(int (i) = 0;(i) < (n);(i)++)
#define all(x) (x).begin(),(x).end()

struct Node{
    int c;
    bool accept;
    vector<int> nextid;
    Node(int c):c(c),accept(false){
      nextid.assign(26,-1);
    }
};
vector<Node> g;

bool match(int tmp,int c){
  return (g[tmp].nextid[c] != -1) && g[g[tmp].nextid[c]].accept;
}
void insert(string& s){
  int tmp = 0;
  for(int i = 0;i < s.size();i++){
    int& nid = g[tmp].nextid[s[i] - 'a'];
    if(nid == -1){
      nid = g.size();
      g.emplace_back(s[i] - 'a');
    }
    tmp = nid;
  }
  g[tmp].accept = true;
}

ll ans;

void func(string s){
  int sz = s.size();
  vector<int> last(26,-1);
  for(int j = sz - 1;j >= 0;j--) {
    if(last[s[j] - 'a'] == -1){
      last[s[j] - 'a'] = j;
    }
  }
  int tmp = 0;
  for(int j = 0;j < sz;j++){
    for(int c = 0;c < 26;c++){
      if(j <= last[c] && match(tmp,c)){
        ans++;
      }
    }
    int nid = g[tmp].nextid[s[j] - 'a'];
    if(nid == -1) break;
    else tmp = nid;
  }
  insert(s);
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<string> a(n);
  for(int i = 0;i < n;i++){
    cin >> a[i];
    reverse(all(a[i]));
  }
  sort(a.begin(),a.end(),[](string& s,string& t){
    return s.size() < t.size();
  });

  g.emplace_back(0); // Trie木の根ノードを0とする

  for(int i = 0;i < n;i++){
    func(a[i]);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 144704
S = input()
T = input()
count = 0
lenS = len(S)
lenT = len(T)
ans = lenT

for j in range(lenS - lenT + 1):
  count = lenT
  for i in range(lenT):
    if S[i+j] == T[i]:
      count -= 1
  if count < ans:
    ans = count
      
print(ans)

Measured memory_bytes: 9032
#include<bits/stdc++.h>
#define ll long long
const int N=100005;
using namespace std;
int n,a[105],k,ans;
int main(){
	cin>>n>>k;
	for(int i=1;i<=k;i++)
	{
		int d,c;
		cin>>d;
		for(int j=1;j<=d;j++)
		    cin>>c,a[c]++;
	}
	for(int i=1;i<=n;i++)
	    if(a[i]==0) ans++;
	cout<<ans;
    return 0;
}

Measured memory_bytes: 3568
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import itertools
import math
import sys

INF = float('inf')


def solve(N: int, K: int, p: "List[int]"):
    return sum(sorted(p)[:K])


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(solve(N, K, p))


if __name__ == '__main__':
    main()


Measured memory_bytes: 75136
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();
        System.out.println(Math.max(0, c-(a-b)));
    }
}


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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = 1e9+7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

ll f(ll s){
	if(s%4==1) return 1;
	if(s%4==3) return 0;
	if(s%4==0) return s;
	return s+1;

}


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	ll a,b;
	cin >>a >>b;
	
	ll z1 = a? f(a-1): 0;
	ll z2 = b? f(b): 0;
	cout << (z2 ^ z1) <<"\n";
	

	return 0;
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()

num = defaultdict(int)

for _ in range(N):
	A = INT()
	num[A-1] ^= 1

ans = 0
for x in num:
	ans += num[x]

print(ans)
	

Measured memory_bytes: 17196
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}


macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: u32 = sc.cin();
    let k: u32 = sc.cin();
    put!(if n%k>0{1}else{0});
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


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

template<typename T, T INF>
class MinCostFlow{
public:
  //辺を表す構造体(行き先、容量、コスト、逆辺)
  
  struct edge{
    int to,cap;
    T cost;
    int rev;
    edge();
    edge(int to,int cap,T cost,int rev):to(to),cap(cap),cost(cost),rev(rev){}
  };
  
  int V;                          //頂点数
  vector<vector<edge> > G;        //グラフの隣接リスト表現
  vector<T> dist;             //最短距離
  vector<int> prevv,preve;        //直前の頂点と辺

  MinCostFlow():V(-1){}
  MinCostFlow(int V):V(V), G(V), dist(V), prevv(V), preve(V){};
  
  // fromからtoへ向かう容量cap、コストcostの辺をグラフに追加する。
  void add_edge(int from,int to,int cap ,T cost){
    assert(from>=0 && to >= 0);
    assert(from<V && to<V);
    G[from].push_back((edge){to,cap,cost,(int)G[to].size()});
    G[to].push_back((edge){from,0,-cost,(int)G[from].size()-1});
  }
  
  //sからtへの流量fの最小費用流を求める
  //流せない場合-1を返す
  T flow(int s, int t, int f){
    T res = 0;

    while(f>0){
      //ベルマンフォード法により,s-t間最短路を求める
      fill(dist.begin(),dist.end(),INF);
      dist[s] = 0;
      bool update = true;
      while(update){
        update = false;
        for(int v=0; v<V ;v++){
          if(dist[v]==INF) continue;
          for(int i=0; i<(int)G[v].size(); i++){
            edge &e = G[v][i];
            if(e.cap > 0 && dist[e.to] > dist[v] + e.cost) {
              if(abs(dist[e.to] - dist[v] - e.cost) < 1e-8) continue; //double演算用
              dist[e.to] = dist[v] + e.cost;
              prevv[e.to] = v;
              preve[e.to] = i;
              update = true;
            }
          }
        }
      }

      if(dist[t]==INF) return -1; //これ以上流せない。
    
      //s−t間短路に沿って目一杯流す
      int d = f;
      for(int v=t; v!=s; v=prevv[v]) d = min(d, G[prevv[v]][preve[v]].cap);
      f -= d;
      res += d * dist[t];
      for(int v=t; v!=s; v=prevv[v]){
        edge &e = G[prevv[v]][preve[v]];
        e.cap -= d;
        G[v][e.rev].cap += d;
      }
    }
    return res;
  }
};


int main(){
  int V, E, F;
  cin>>V>>E>>F;

  MinCostFlow<long long, 1LL<<55> f(V);
  for(int i=0;i<E;i++){
    int u, v, c, d;
    cin>>u>>v>>c>>d;
    f.add_edge(u, v, c, d);
  }

  int ans = f.flow(0, V-1, F);
  cout<<ans<<endl;

}



Measured memory_bytes: 3184
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,A,B; cin >> N >> A >> B;
    string S; cin >> S;
    int a = 0,b =0;
    REP(i,N){
        if(S[i] == 'a'){
            if(a < A+B){
                cout << "Yes" << endl;
                a++;
            }
            else{
                cout << "No" << endl;
            }
        }
        else if(S[i] == 'b'){
            if(b < B && a < A+B){
                dump("hoge")
                cout << "Yes" << endl;
                a++;
                b++;
            }
            else{
                cout << "No" << endl;
            }
        }
        else{
            cout << "No" << endl;
        }
    }

}

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

using namespace std;

typedef long long LL;

const int N = 1010;

int a, b, k;

int main()
{
    cin >> a >> b >> k;
    if(b - a + 1 <= 2 * k)
        for(int i = a; i <= b; i++)
            cout << i << endl;
    else
    {
        for(int i = a; i < a + k; i++)
            cout << i << endl;
        for(int i = b - k + 1; i <= b; i++)
            cout << i << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long ll;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
using namespace std;
int main(int argc, char const *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int a;
  vector<int> v;
  REP(i,3){
    cin>>a;
      v.pb(a);
  }
  VSORT(v);
  cout <<v[0]<<" "<<v[1]<<" "<<v[2]<<endl;


  return 0;
}



Measured memory_bytes: 3172
#include <cstdio>

int main() {
	char x[1001] = {};
	int sum, i;


	while (1) {
		sum = 0;

		scanf("%s", x);

		if (x[0] == '0') break;

		for (i = 0; x[i] != '\0'; i++) {
			sum += x[i] - '0';
		}

		printf("%d\n", sum);
	}
	

	return 0;
}



Measured memory_bytes: 2712
n = int(input())
memo = [-1]*(n+1)
memo[0] = 1
memo[1] = 1

def fib(n):
    if memo[n] != -1:
        return memo[n]
    else:
        ans = fib(n-1)+fib(n-2)
        memo[n] = ans
        return ans

print(fib(n))


Measured memory_bytes: 5600
H, W=map(int, input().split())
A=[list(map(int, input().split())) for _ in range(H)]
B=[list(map(int, input().split())) for _ in range(H)]
AB=[[abs(A[i][j]-B[i][j]) for j in range(W)] for i in range(H)]

G=[[[0]*(80*162) for j in range(W)] for i in range(H)]
G[0][0][AB[0][0]]=1
sumi=[[0]*W for i in range(H)]
  
from collections import deque

def f(data):
  i=data[0]
  j=data[1]
  owari=(i+j+1)*80+1
  if i<H-1 and j<W-1:
    for k in range(owari):
      if G[i][j][k]>0:
        G[i+1][j][k+AB[i+1][j]]=1
        G[i+1][j][abs(k-AB[i+1][j])]=1
        G[i][j+1][k+AB[i][j+1]]=1
        G[i][j+1][abs(k-AB[i][j+1])]=1
    if sumi[i+1][j]==0:
      q.append([i+1, j])
      sumi[i+1][j]=1
    if sumi[i][j+1]==0:
      q.append([i, j+1])
      sumi[i][j+1]=1
  elif i>=H-1 and j<W-1:
    for k in range(owari):
      if G[i][j][k]>0:
        G[i][j+1][k+AB[i][j+1]]=1
        G[i][j+1][abs(k-AB[i][j+1])]=1
    if sumi[i][j+1]==0:
      q.append([i, j+1])
      sumi[i][j+1]=1
  elif i<H-1 and j>=W-1:
    for k in range(owari):
      if G[i][j][k]>0:
        G[i+1][j][k+AB[i+1][j]]=1
        G[i+1][j][abs(k-AB[i+1][j])]=1
    if sumi[i+1][j]==0:
      q.append([i+1, j])
      sumi[i+1][j]=1
    
q=deque()
q.append([0, 0])
while len(q)>0:
  data=q.popleft()
  f(data)
  
out=0
while G[-1][-1][out]==0:
  out+=1
print(out)

Measured memory_bytes: 684296