akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn main() {
    input!{
      s: chars,
    }
    let n = s.len();
    if s[0] != '1' {
        return println!("{}", -1);
    }
    if s[n-1] == '1' {
        return println!("{}", -1);
    }

    for i in 1..n+1 {
        if !(n >= i+1) {
            break;
        }
        let j = n-i;
        if s[i-1] != s[j-1] {
            return println!("{}", -1);
        }
    }

    let mut leafs = vec![0];
    for i in 1..n-1 {
        if s[i] == '1' {
            for &l in leafs.iter() {
                println!("{} {}", l+1, i+1);
            }
            leafs = vec![i];
        } else {
            leafs.push(i);
        }
    }
    println!("{} {}", n-1, n);
}


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

int main(){
    int n ;
    cin >> n ;
    vector<int> a(n) ;
    for (int i = 0; i < n; i++)
    {
        cin >> a.at(i) ;
    }
    int max = 0 ;
    int maxnum = 0 ;
    for (int i = 0; i < n; i++)
    {
        if (max < a.at(i))
        {
            max = a.at(i) ;
            maxnum = i ;
        }
        
    }
    a.at(maxnum)= 0 ;
    int max2 = 0 ;
    for (int i = 0; i < n; i++)
    {
        if (max2 < a.at(i))
        {
            max2 = a.at(i) ;
        }
        
    }
    for (int i = 0; i < n; i++)
    {
        if (i == maxnum)
        {
            cout << max2 << endl ;
        }else
        {
            cout << max << endl ;
        }
        
        
    }
    
    
    
}

Measured memory_bytes: 2432
const MAX_N: usize = 100100;
fn solve() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let k: u32 = sc.read();
    let ss: Vec<char> = sc.chars();
    let mut sum : Vec<u32> = vec![0; n];


    if ss[0] == '0' {
        sum[0] = 1;
    }
    for i in 1..n {
        if ss[i - 1] == '1' && ss[i] == '0' {
            sum[i] = 1;
        }
    }
    for i in 0..n - 1 {
        sum[i + 1] += sum[i];
    }
    let mut result = 1;
    for i in 0..n {
        let mut left = 0;
        let mut right = n + 10;
        while right - left > 1 {
            let med = (right + left) / 2;
            if i + med >= n {
                right = med;
                continue;
            }
            let mut cost = sum[i + med];
            if i >= 1 {
                cost -= sum[i - 1];
            }
            if i != 0 && ss[i] == '0' {
                cost += 1;
            }
            if cost <= k {
                left = med;
            } else {
                right = med;
            }
        }
        result = std::cmp::max(result, left + 1);
    }
    println!("{}", result);
}

fn main() {
    std::thread::Builder::new()
        .stack_size(256 * 1024 * 1024) // 64MB
        .spawn(|| solve())
        .unwrap()
        .join()
        .unwrap();
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self.stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self.stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}

Measured memory_bytes: 8572
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  string s;
  cin >> s;
  int n = s.size();
  cout << s[0] << n - 2 << s[n - 1] << endl;
  return 0;
}

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

int main(){
    int n;
    cin >> n;
    int a[n],max=0,keep=0,sum=0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        sum += a[i];
        if(max < a[i]){
            max = a[i];
            keep = i;
        }
    }
    if(sum-a[keep] <= a[keep]){
        cout << "No";
    }else{
        cout << "Yes";
    }
}

Measured memory_bytes: 256
mod = 10**9+7
fac = [1]
fac_in = [1]
for i in range(1,5*10**5+1):
    fac.append((fac[-1]*i)%mod)
    fac_in.append((fac_in[-1]*pow(i,mod-2,mod))%mod)

def comb(a,b):
    return (fac[a]*fac_in[b]*fac_in[a-b])%mod

def perm(a,b):
    return (fac[a]*fac_in[a-b])%mod

n,m = map(int,input().split())
ans = perm(m,n)
ans1 = 0
for i in range(n+1):
    ans1 += (comb(n,i)*perm(m-i,n-i))*(-1)**i
    ans1 %= mod
ans *= ans1
print(ans%mod)

Measured memory_bytes: 149512
// 解き直し.
// https://img.atcoder.jp/abc150/editorial.pdf
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
const LL MOD = 1e9 + 7;
const LL MAX = 202020;
LL C[MAX];

int main(){
    
    // 1. 入力情報.
    int N;
    scanf("%d", &N);
    rep(i, N) scanf("%lld", &C[i]);
    
    // 2. 解説通り.
    sort(C, C + N, greater<LL>());
    
    // 3. 解説の数式を計算.
    LL a = 1, b = 0;
    rep(i, N - 1) a *= 4, a %= MOD;
    rep(i, N) b += C[i] * (LL)(i + 2), b %= MOD;
    LL ans = a * b % MOD;
    
    // 4. 出力.
    printf("%lld\n", ans);
    return 0;
    
}

Measured memory_bytes: 1792
#include<stdio.h>
#include <sstream>
#include <iostream>
#include <cstdlib>
#include <string.h>

using namespace std;

#define BUF_SIZE 1024

int count = 0;

void insertionSort(int array[],int n,int g){
	int v,j;
	for(int i = g;i < n; i++){
		v = array[i];
		j = i - g;
		while(j >= 0 && array[j] > v){
			array[j+g] = array[j];	//??°??????????????§???????????????
			j = j - g;
			count++;
		}
		array[j+g] = v;
	}
}

void shellSort(int array[],int n){
	int m = 0;
	int s = 1;

	while((n/s) > 0){
		s *= 2;
		m++;	//2^(mult-1)?????§?????????????????¨???????¨?
	}

	int G[20];

	for(int k = 0,t = 1; k < m; k++){
		G[k] = n/t;
		t *= 2;
	}

	for(int i = 0; i < m;i++){
		insertionSort(array,n,G[i]);
	}

	printf("%d\n",m);
	for(int i = 0; i < m; i++){
		if(i != m-1){
			printf("%d ",G[i]);
		}else{
			printf("%d\n",G[i]);
		}
	}
	printf("%d\n",count);
	for(int i = 0; i < n; i++){
		printf("%d\n",array[i]);
	}

}

int main(int argc,char* argv[]){
	char buf[BUF_SIZE];
	int n = atoi(fgets(buf,BUF_SIZE,stdin));
	int array[1000000];

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

	shellSort(array,n);

}

Measured memory_bytes: 5072
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
typedef long long ll;
using namespace std;
int main()
{
  int n;
  cin >> n;
  int tmp;
  int ans = 10000;
  REP(i,n){
    cin >> tmp;
    int num = 0;
    while(tmp %2 == 0){
      tmp /= 2;
      num ++;
    }
    ans = min(num,ans);
  }
  cout << ans << endl;
}


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

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int delta=0;
  if((min(b, d) - max(a, c)) > 0)
  delta = min(b, d) - max(a, c);
  
  cout << delta << endl;
 return 0;
}

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

#include <vector>
using namespace std;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

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

typedef long long ll;

void solve(long long K) {
    vector<ll> a;
    for (int i = 1; i <= 9; i++) {
        a.push_back(i);
    }

    while (1) {
        if (K <= a.size()) {
            cout << a[K - 1] << endl;
            return;
        }
        K -= a.size();
        vector<ll> old;
        swap(old, a);
        for (ll x : old) {
            for (int i = -1; i <= 1; i++) {
                int d = x % 10 + i;
                if (d < 0 || d > 9) {
                    continue;
                }
                ll nx = x * 10 + d;
                a.push_back(nx);
            }
        }
    }
}

int main() {
    long long K;
    scanf("%lld", &K);
    solve(K);
    return 0;
}


Measured memory_bytes: 1712
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define db(x) (cerr << #x << ": " << (x) << '\n')
#define cps CLOCKS_PER_SEC
#define tests(t) int t; cin >> t; while(t--)
#define iceil(n, x) (((n) + (x) - 1) / (x))
#define eb emplace_back
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define sz size()
#define all(v) (v).begin(), (v).end()
#define uni(v) sort(all(v)), (v).erase(unique(all(v)), (v).end())
#define fi first
#define se second
#define bitcount(x) __builtin_popcount(x)
#define bit(x) (1LL << x)
#define PI acos(-1.0)
#define EPS 1e-9

#define mod 1000000007
#define maxn 1000005

using namespace std;

using namespace __gnu_pbds;
template<class key, class cmp = std::less<key>>
using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
///All indexing is 0-based
///methods: find_by_order(k); & order_of_key(k);
///To make it an ordered_multiset, use pairs of (value, time_of_insertion)
///to distinguish values which are similar

typedef long long ll;
typedef double ld;
typedef pair<int, int> par;

ll N,a,b,c,d;

int main()
{
    #ifdef acm
    freopen("a.in","r",stdin);
    #endif // acm
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> N;

    if(N%10 == 0 || N%10 == 1 || N%10 == 6 || N%10 == 8)
        cout << "pon" << "\n";
    else
        if(N%10 == 3)
            cout << "bon" << "\n";
        else
            cout << "hon\n";














}


Measured memory_bytes: 3612
#include <iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[n];
  for(int i = 0; i < n; i++)cin >> a[i];
  int c[9];
  for(int i = 0; i < 9; i++)c[i]=0;
  for(int i = 0; i < n; i++){
    if(a[i]<400){
      c[0]++;
      continue;
    }
    if(a[i]<800){
      c[1]++;
      continue;
    }
    if(a[i]<1200){
      c[2]++;
      continue;
    }
    if(a[i]<1600){
      c[3]++;
      continue;
    }
    if(a[i]<2000){
      c[4]++;
      continue;
    }
    if(a[i]<2400){
      c[5]++;
      continue;
    }
    if(a[i]<2800){
      c[6]++;
      continue;
    }
    if(a[i]<3200){
      c[7]++;
      continue;
    }
    c[8]++;
  }
  int count = 0;
  for(int i = 0; i < 8; i++){
    count+=min(1, c[i]);
  }
  cout << max(1,count) << ' ' << count+c[8] << endl;
  return 0;
}


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

int main(){
    int n;
    cin >> n;
    int ans = 0;
    int mx = 0;
    int cur;
    for (int i=0;i<n;i++){
        cin >> cur;
        mx = max(mx,cur);
        if (mx==cur)ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){ 
  int K; 
  cin >> K;
  int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51}; 
  cout << a[K-1] << endl;
 return 0; 
}

Measured memory_bytes: 256
//BISMILLAH
#include <bits/stdc++.h>
using namespace std;
int main(){
    
     int i,j,k,ans = 0;
     cin >> k;
     for(i = 1;i<=1e7;i++){
         ans = ((ans * 10) + 7) % k;
         if(ans == 0) {
             cout << i << endl;
             return 0;
         }
     }
      cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using pi = pair<int,int>;

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

struct State{
    int pa,pb,pc;
};

const int N = 16*16;
const int INF = 19191919;
int dp[N][N][N];

int solve(int w, int h, int n){
    cin.ignore();
    vector<string> f(h);
    rep(i,h) getline(cin, f[i]);

    auto cv = [&](pi p){
        return p.fi*w+p.se;
    };

    int sa=0,sb=0,sc=0,ga=0,gb=0,gc=0;
    rep(i,h)rep(j,w){
        if(f[i][j]=='a') sa = cv({i,j});
        if(f[i][j]=='b') sb = cv({i,j});
        if(f[i][j]=='c') sc = cv({i,j});
        if(f[i][j]=='A') ga = cv({i,j});
        if(f[i][j]=='B') gb = cv({i,j});
        if(f[i][j]=='C') gc = cv({i,j});
    }

    auto cand = [&](int p){
        int y = p/w, x = p%w;

        vector<int> ret;
        ret.pb(p);

        rep(d,4){
            int ny = y+dy[d], nx = x+dx[d];
            if(0<=ny && ny<h && 0<=nx && nx<w && f[ny][nx]!='#') ret.pb(cv({ny,nx}));
        }
        return ret;
    };

    rep(i,N)rep(j,N)rep(k,N) dp[i][j][k] = INF;
    dp[sa][sb][sc] = 0;
    queue<State> que;
    que.push({sa,sb,sc});
    while(!que.empty()){
        State now = que.front();
        que.pop();

        vector<int> da = cand(now.pa), db = cand(now.pb), dc = cand(now.pc);

        for(int A:da)for(int B:db)for(int C:dc){
            if(B != 0){
                if(B == A) continue;
                if(now.pa == B && now.pb == A) continue;
            }
            if(C != 0){
                if(C == A || C == B) continue;
                if(now.pa == C && now.pc == A) continue;
                if(now.pb == C && now.pc == B) continue;
            }

            if(dp[A][B][C] > dp[now.pa][now.pb][now.pc]+1){
                dp[A][B][C] = dp[now.pa][now.pb][now.pc]+1;
                if(A==ga && B==gb && C==gc) return dp[A][B][C];
                que.push({A,B,C});
            }
        }
    }
    assert(false);
}

int main(){
    int w,h,n;
    while(cin >>w >>h >>n,w){
        cout << solve(w,h,n) << endl;
    }
    return 0;
}



Measured memory_bytes: 71524
#include <bits/stdc++.h>
#define maxn 200005
#define MOD 1000000007
#define INF 10000000

using namespace std;

#define ll long long
#define pii pair<ll, ll>
#define piii pair<pii, ll>
#define ft first
#define sd second

void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}

bool check(ll x, ll i){
    while(x%i == 0){
        x/=i;
    }
    if(x%i == 1) return true;
    return false;
}

void solve(){
    ll n;
    cin >> n;
    ll ans = 0;
    for(ll i = 1; i <= sqrt(n-1); i++){
        if((n-1)%i == 0){
            if( i > 1) ans++;
            if(i != (n-1)/i) ans++;
        }
    }
    for(ll i = 1; i <= sqrt(n); i++){
        if((n%i) == 0){
            if(i > 1 && check(n, i)) ans++;
            if(i != (n)/i && check(n, n/i)) ans++;
        }
    }
    cout << ans;

}

int main()
{
    solve();
}



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

int main(){
  string a, b;
  cin >> a >> b;

  if ((a == "H" && b == "H") || (a == "D" && b == "D")){
    cout << "H" << endl;
  }
  else
  {
    cout << "D" << endl;
  }
  
}

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

int max(int a,int b)
{
 if(a>=b) return a;
 else return b;
}

int main()
{
 int N,M;
 long int K;
 cin >> N >> M >> K;
 long int sum_A[N+1];
 long int sum_B[M+1];
 sum_A[0] = 0;
 sum_B[0] = 0;

 int s_max = 0;
 long int tmp1 = 0;

 int t_max = 0;
 long int tmp2 = 0;

 for(int i=0;i<N;i++){
     long int a_i; cin >> a_i;
     tmp1 += a_i;
     if(tmp1 <= K) s_max++;
     sum_A[i+1] = tmp1;
 }
 for(int i=0;i<M;i++){
     long int b_i; cin >> b_i;
     tmp2 += b_i;
     if(tmp2 <= K) t_max++;
     sum_B[i+1] = tmp2;
 }

 int ans = 0;
 for(int i=0;i<=s_max;i++){
     long int rest = K-sum_A[i];
     int left = 0;
     int right = t_max;
     while(left<=right){
         int mid = (int)(left+right)/2;
         if(sum_B[mid]<=rest) left = mid+1;
         else right = mid-1;
     }
     ans = max(ans,i+left-1);
 }
 cout << ans << endl;
 return 0;
}

Measured memory_bytes: 6728
#include <iostream>
#include <vector>
#include <assert.h>
#include <map>
#include <cmath>
#include <algorithm>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <set>
#include <climits>

using namespace std;

const int N = 4;
const int N2 = 16;

static const int dx[4] = {0, -1, 0, 1};
static const int dy[4] = {1, 0, -1, 0};
static const char dir[4] = {'r', 'u', 'l', 'd'}; 


struct Node
{
	vector<int> puzzle;
	int space;
	int md;
};

class Npuzzle
{
private:
	Node s_node;
	int limit;
	vector<vector<int> > md;
	vector<int> path;
	int ans;
public:
	Npuzzle() {
		s_node = Node();
		vector<int> in;
		for (int i = 0; i < N2; ++i)
		{
			int tmp;
			cin >> tmp;
			if(tmp == 0) {
				tmp = N2;
				s_node.space = i;
			}
			in.push_back(tmp);
		}
		s_node.puzzle = in;
		set_md();
		s_node.md = get_md_sum(s_node.puzzle);
	}

	int get_md_sum(const vector<int>& puzzle) {
		int sum = 0;
		for (int i = 0; i < N2; ++i)
		{
			if(puzzle[i] == N2) continue;
			sum += md[i][puzzle[i]-1];
		}
		return sum;
	}

	void set_md() {
		md = vector<vector<int> >(N2, vector<int>(N2, 0));
		for (int i = 0; i < N2; ++i)
		{
			for (int j = 0; j < N2; ++j)
			{
				md[i][j] = abs(i / N - j / N) + abs(i % N - j % N);
			}
		}
	}

	bool dfs(Node cur_n, int depth, int pre) {
		if(cur_n.md == 0 ) {
			ans = depth;
			return true;
		}
		if(depth + cur_n.md > limit) return false;
		int s_x = cur_n.space / N;
		int s_y = cur_n.space % N;
		for (int i = 0; i < 4; ++i)
		{
			Node new_n = cur_n;
			int new_x = s_x + dx[i];
			int new_y = s_y + dy[i];
			if(new_x < 0  || new_y < 0 || new_x >= N || new_y >= N) continue; 
			if(max(pre, i) - min(pre, i) == 2) continue;
			int num = new_n.puzzle[new_x * N + new_y] - 1;
			// cout << dir[i] << endl;
			new_n.md -= md[new_x * N + new_y][new_n.puzzle[new_x * N + new_y] - 1];
			new_n.md += md[s_x * N + s_y][new_n.puzzle[new_x * N + new_y] - 1];
			swap(new_n.puzzle[new_x * N + new_y], new_n.puzzle[s_x * N + s_y]);
			// cout << new_n.space << endl;
			// cout << s_x << " "<< s_y << endl;
			// cout << new_x << " "<< new_y << endl;
			new_n.space = new_x * N + new_y;
			assert(get_md_sum(new_n.puzzle) == new_n.md);
			// return dfs(new_n, depth+1, i);
			if(dfs(new_n, depth + 1, i)){
				path[depth] = i;
				return true;
			}
		}
		return false;
	}

	void ida_star() {
		for (limit = s_node.md; limit < 1000; ++limit)
		{
			path.resize(limit);
			if(dfs(s_node, 0, -10)) {
				cout << limit << endl;
				string str = "";
				for (int i = 0; i < limit; ++i)
				{
					str += dir[path[i]];
				}
				// cout << str << endl;
				return;
			}
		}
	}

	void exec() {
		ida_star();
	}
};


int main() {
	Npuzzle np = Npuzzle();
	np.exec(); 
}

Measured memory_bytes: 3224
#include <stdio.h>
int main(void){
    int i;
    char str[256];
     scanf("%s",str);
        if (str[0] == 'Y' && str[1] == 'A' && str[2] == 'K' && str[3] == 'I' ){
            printf("Yes");
        } 
        else{
                printf("No");
        } 
    return 0;
}

Measured memory_bytes: 128
def solve():
  N = int(input())
  A = [list(map(int, input().split())) for _ in range(N)]
  mod = 10**9+7
  dp = [[0]*(1<<N) for _ in range(N+1)]
  dp[N][-1] = 1
  for S in range((1<<N)-1,-1,-1):
    i = sum([1&(S>>k) for k in range(N)])
    for j in range(N):
      if not (S>>j)&1: #jがSに含まれないなら
        if A[i][j]==1:
          dp[i][S] += dp[i+1][S+(1<<j)]
          dp[i][S] %= mod
  return dp[0][0]
print(solve())

Measured memory_bytes: 435212
#include <bits/stdc++.h>
#define ll long long
#define pq priority_queue
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
const ll MAX=510000;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};
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 main(){
    ll N;
    cin>>N;
    while(N){
        int a=N%10;
        if(a==7){
            cout<<"Yes"<<endl;
            return 0;
        }
        N/=10;
    }
    cout<<"No"<<endl;
}


Measured memory_bytes: 3628
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> p = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            p.add(sc.nextInt());
        }

        int cnt = 0;
        int cnt2 = 0;
        boolean adj = false;
        for (int i = 0; i < n; i++) {
            if (p.get(i) == i + 1) {
                cnt++;
                if (adj) {
                    cnt2++;
                    adj = false;
                    continue;
                }
                adj = true;
                continue;
            }
            adj = false;
        }

        cnt -= 2 * cnt2;
        if (cnt <= 0) {
            cnt = 0;
        }
        int ans = cnt + cnt2;
        System.out.println(ans);
    }
}


Measured memory_bytes: 61676
#include <iostream>
#include <map>
#include <vector>
#define int long long
typedef long long ll;
using namespace std;

signed main(){
    ll n=100, X;
    double n1=100;
    int i=0;

    cin >> X;
    while(n<X){
        n = n1 * 1.01;
        n1 = n;
        i++;
    }
    cout << i << endl;
    return 0;
}

Measured memory_bytes: 3632
n, m = map(int, input().split())

problem = [False] * n
count_wa = [0] * n


for _ in range(m):
    num, res = input().split()
    num = int(num) - 1

    if res == 'AC':
        problem[num] = True

    else:
        if problem[num] == False:
            count_wa[num] += 1
        else:
            continue

a = sum(problem)
b = 0

for i in range(n):
    if problem[i] == True:
        b += count_wa[i]

print(a, b)


Measured memory_bytes: 4596
n, k = map(int, input().split())
r, s, p = map(int, input().split())
score = {"r": p, "s": r, "p": s}
t = list(input())
ans = 0

for i in range(k):
    u = t[i::k]
    m = len(u)
    dp = [[0] * 3 for j in range(m+1)]
    for j in range(m):
        dp[j+1][0] = max(dp[j][1], dp[j][2]) + (score[u[j]] if u[j] == "r" else 0)
        dp[j+1][1] = max(dp[j][0], dp[j][2]) + (score[u[j]] if u[j] == "s" else 0)
        dp[j+1][2] = max(dp[j][0], dp[j][1]) + (score[u[j]] if u[j] == "p" else 0)
    ans += max(dp[m])

print(ans)


Measured memory_bytes: 24080
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  int n_2 = 0;
  int n_4 = 0;
  rep(i,N){
    int x;cin >> x;
    if((x&3) == 0)++n_4;
    else if((x&1) == 0) ++n_2;
  }
  N -=  max(0,n_2-1);
  YesNo(n_4>=N/2);
  return 0;
}


Measured memory_bytes: 256
H, W, N = gets.split.map(&:to_i)
#H, W, N = 10**5, 10**5, 10**5
points = {}
memo = Hash.new(0)
ans = Array.new(10, 0)
ans[0] = (W - 2) * (H - 2)
N.times do |i|
    a, b = gets.split.map(&:to_i)
    #a, b = i, i
    (a-1..a+1).each do |ap|
        next if ap < 2 || ap > H - 1
        (b-1..b+1).each do |bp|
            next if bp < 2 || bp > W - 1
            code = ap*W+bp
            ans[memo[code]] -= 1
            memo[code] += 1
            ans[memo[code]] += 1
        end
    end
end

(0..9).each do |i|
    puts ans[i]
end

Measured memory_bytes: 60028
#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;
}();
// freopen("input.txt", "r", stdin);

bool valid(string s, string t) {
    for(int i = 0; i < t.size(); i++) {
        if (s[i] == '?' || s[i] == t[i])
            continue;
        return false;
    }
    return true;
}
int main() {
    string s, t;
    cin >> s >> t;
    if (t.size() > s.size()) {
        cout << "UNRESTORABLE" << endl;
    } else {
        string ans = "";
        for(int i = 0; i <= s.size()-t.size(); i++) {
            if (valid(s.substr(i, t.size()), t)) {
                string tmp = s;
                for(int j = 0; j < t.size(); j++)
                    tmp[i+j] = t[j];
                for(char& c: tmp)
                    if (c == '?')
                        c = 'a';
                if (ans == "" || tmp < ans)
                    ans = tmp;
            }
        }
        if (ans == "")
            cout << "UNRESTORABLE" << endl;
        else
            cout << ans << endl;
    }
    return 0;
}




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

int main() {
  int N, a, b;
  a=0;
  b=0;
  string S;
  cin >> N >> S;
  for(int i=0; i<N; i++) {
    cin >> S.at(i);
  }
  for(int i=0; i<N; i++) {
    if(S.at(i)=='I') {
      a++;
    }
    if(S.at(i)=='D') {
      a--;
    }
    if(a>b) {
      b++;
    }
  }
  cout << b << endl;
}

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

using namespace std;

typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

struct ipt
{
    int x;
    int y;
    int h;
};

bool hso(const ipt& l, const ipt&r)
{
    return l.h > r.h;
}


int calc(int cx, int cy, int x, int y)
{
    return abs(cx - x) + abs(cy - y); 
}

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

    vector<ipt> v;

    REP(i, N)
    {
        int x,y,h;
        cin >> x >> y >> h;
        v.push_back({x, y, h});
    }

    sort(v.begin(), v.end(), hso);

    REP(cx, 101)
    {
        REP(cy, 101)
        {
            bool ok = true;
            int h = 0;
            REP(vc, v.size())
            {
                if(h == 0)
                {
                    h = v[vc].h + 
                    calc(cx, cy, v[vc].x, v[vc].y);
                }
                else
                {
                    int c = v[vc].h + 
                    calc(cx, cy, v[vc].x, v[vc].y);
                    if(h > calc(cx, cy, v[vc].x, v[vc].y))
                    {
                        if(c != h)
                        {
                            ok = false;
                            break;
                        }
                    }
                    else
                    {
                        if(v[vc].h != 0)
                        {
                            ok = false;
                            break;
                        }
                    }
                }
            }
            if(ok)
            {
                cout << cx << " "
                << cy << " "
                << h << endl;
                return 0;
            }
        }
    }

    return 0;
}



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

signed main(void)
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	vector<long double>a(n);
	for (int i = 0; i < n; i++)cin >> a[i];
	for (int i = 0; i < n; i++)a[i] = 1 / a[i];
	long double ans = 0;
	for (int i = 0; i < n; i++)ans += a[i];
	cout << setprecision(12);
	cout << 1 / ans;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
// #define int long long
#define pb push_back
#define fi first
#define se second
#define FF first
#define SS second
#define INF 2e18;
#define mp make_pair
#define ll long long
#define pii pair<int,int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define endl '\n'
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define sz(s) (int)s.size()
#define all(x) x.begin(), x.end()
typedef long double ld;

struct BipartiteMatcher{
    vector<vector<int>> G;
    vector<int> L, R, Viz;
    void init(int n, int m){
        G.clear(), L.clear(), R.clear(), Viz.clear();
        G.resize(n), L.resize(n, -1), R.resize(m, -1), Viz.resize(n, 0);
    }
    void AddEdge(int a, int b){ G[a].push_back(b); }
    bool Match(int node){
        if(Viz[node]) return 0;
        Viz[node] = 1;
        for(auto vec : G[node]){
            if(R[vec] == -1 || Match(R[vec])) {
                L[node] = vec;
                R[vec] = node;
                return 1;
            }
        }
        return 0;
    }
    int Solve(){
        bool ok = 1;
        while(ok){
            ok = 0;
            fill(Viz.begin(), Viz.end(), 0);
            fr(i, 0, L.size() - 1)
                if(L[i] == -1)
                    ok |= Match(i);
        }
        int ret = 0;
        fr(i, 0, L.size() - 1)
            ret += (L[i] != -1);
        return ret;
    }
} bm;

int a[105], b[105], c[105], d[105];


signed main()
{
    //freopen("inp.txt","r",stdin);
   // freopen("out.txt","w",stdout);
 
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    fr(i, 1, n) {
        cin >> a[i] >> b[i];
    }
    fr(i, 1, n) {
        cin >> c[i] >> d[i];
    }
    BipartiteMatcher bm;
    bm.init(n, n);
    fr(i, 0, n - 1) {
        fr(j, 0, n - 1) {
            if(a[i + 1] < c[j + 1] && b[i + 1] < d[j + 1]) {
                bm.AddEdge(i, j);
            }
        }
    }
    cout << bm.Solve() << endl;
    return 0;
}

Measured memory_bytes: 256
/*2019/07/29 */
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define MOD 1000000007
typedef long long int ll;
void llswap(ll *x,ll *y){ll temp;temp=*x;*x=*y;*y=temp;}
void swap(int *x,int *y){int tmp;tmp=*x;*x=*y;*y=tmp;}
int rmax(int x,int y){return x>y?x:y;}
int rmin(int x,int y){return x>y?y:x;}
ll llrmax(ll x,ll y){return x>y?x:y;}
ll llrmin(ll x,ll y){return x>y?y:x;}
int asc(const void *a,const void *b){return *(int*)a-*(int*)b;}
int desc(const void *a,const void *b){return *(int*)b-*(int*)a;}
/*
int asc_t(const void *a,const void *b){return ((user_t*)a)->score - ((user_t*)b)->score;}
int desc_t(const void *a,const void *b){return ((user_t*)b)->score - ((user_t*)a)->score;}
*/

int main(){
    int a,b,k;
    scanf("%d %d %d",&a,&b,&k);

    int x[1000],x_i=0;
    for(int i=a;i<a+k&&i<=b;i++){
        x[x_i++]=i;
    }
    for(int i=b-k+1;a<=i&&i<=b;i++){
        x[x_i++]=i;
    }

    int x2[1000],x2_i=0;
    for(int i=0;i<x_i-1;i++){
        if(x[i]==-1)continue;
        for(int j=i+1;j<x_i;j++){
            if(x[i]==x[j]){
                x[j]=-1;
            }
        }
    }
    for(int i=0;i<x_i;i++){
        if(x[i]!=-1){
            printf("%d\n",x[i]);
        }
    }
    
    

    return 0;
}

Measured memory_bytes: 128
import static java.util.Arrays.*;
import java.util.*;

public class Main{
	public static void main(String[] $){
		Scanner s=new Scanner(System.in);
		int A=s.nextInt(),B=s.nextInt(),n=s.nextInt();
		int[]a=new int[A],b=new int[B];
		setAll(a,i->s.nextInt());
		setAll(b,i->s.nextInt());

		int r=stream(a).min().getAsInt()+stream(b).min().getAsInt();
		for(int i=0;i<n;++i)
			r=Math.min(r,a[s.nextInt()-1]+b[s.nextInt()-1]-s.nextInt());
		System.out.println(r);
	}
}


Measured memory_bytes: 150816
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*) array, (T*) (array + N), val);
}
pii Dir [] = {
	{ 1,0 },{ 0,1 }
};


signed main() {
	vector<int> primes = { 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997 };
	int n;
	scanf("%d", &n);
	vector<int> cou(primes.size(),0);
	map<int, int> exts;
	rep(i, 1,n+1) {
		int cur = i;
		REP(j, primes.size()) {
			while (!(cur % primes[j])) {
				cou[j] ++;
				cur /= primes[j];
			}
		}
	}
	ll ans = 1;
	REP(j, primes.size()) {
		ans *= cou[j]+1;
		ans %= MODU;
	}
	printf("%d\n", ans);
	return 0;
}

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

using namespace std;

class Nutrient {
public:
	int id, p, q, r, sum;
};

int P, Q, R, C;
vector<Nutrient> ListInfo;


void solve() {
	vector<Nutrient>::iterator iter;

	for (iter = ListInfo.begin(); iter != ListInfo.end();) {
		if (iter->p <= P && iter->q <= Q && iter->r <= R && iter->sum <= C) {
			++iter;
			continue;
		}
		iter = ListInfo.erase(iter);
	}

	if (ListInfo.empty()) {
		cout << "NA" << endl;
		return;
	}
	for (iter = ListInfo.begin(); iter != ListInfo.end(); ++iter) {
		cout << iter->id << endl;
	}
}

int main() {
	int n;
	Nutrient temp;

	while (cin >> n, n) {
		ListInfo.clear();
		for (int i = 0; i < n; ++i) {
			cin >> temp.id >> temp.p >> temp.q >> temp.r;
			temp.sum = (temp.p + temp.r) * 4 + temp.q * 9;
			ListInfo.push_back(temp);
		}
		cin >> P >> Q >> R >> C;
		solve();
	}

	return 0;
}



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

int main(){
    int a,b,k;
    cin >> a >> b >> k;
    while(1){
        if(a%2!=0){
            --a;
        }
        a = a - a/2;
        b += a;
        k--;
        if(k==0) break;
        if(b%2!=0){
            --b;
        }
        b = b - b/2;
        a += b;
        k--;
        if(k==0) break;
    }
    cout << a << ' ' << b << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

const double EPS = 1e-10;

class Point{
public:
  double x,y;
  Point (double x = 0,double y = 0): x(x),y(y){}
  Point operator + (Point &p){ return Point(x+p.x,y+p.y);}
  Point operator - (Point &p){ return Point(x-p.x,y-p.y);}
  Point operator * (double k){ return Point(x*k,y*k);}
  bool operator < (const Point &p)const {
    if(x == p.x) return y < p.y;
    else return x < p.x;
  }

};
typedef Point Vector;

double cross(Vector a, Vector b){ return a.x * b.y - a.y * b.x;}

int Convex_Hull(vector<Point> v){
  vector<Point> c; //convex
  sort(v.begin(),v.end());
  c.assign(v.begin(),v.begin()+2);

  for(int i=2;i<v.size();i++){
    Vector a = c[c.size()-1] - c[c.size()-2];
    Vector b = v[i] - c[c.size()-2];

    while(cross(a,b) > EPS){
      c.pop_back();
      if(c.size() < 2) break;
      a = c[c.size()-1] - c[c.size()-2];
      b = v[i] - c[c.size()-2];
    }

    c.push_back(v[i]);
  }

  int n = c.size();
  c.push_back(v[v.size()-2]);

  for(int i=v.size()-3;i>=0;i--){
    Vector a = c[c.size()-1] - c[c.size()-2];
    Vector b = v[i] - c[c.size()-2];

    while(cross(a,b) > EPS){
      c.pop_back();
      if(c.size() < n + 1) break;
      a = c[c.size()-1] - c[c.size()-2];
      b = v[i] - c[c.size()-2];
    }

    c.push_back(v[i]);
  }
  c.pop_back();

  return c.size();
}

int main(){
  int n;
  while(cin >> n && n){
    vector<Point> v(n);
    for(int i=0;i<n;i++) scanf("%lf,%lf",&v[i].x,&v[i].y);
    cout << n - Convex_Hull(v) << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;

#define MP make_pair
#define PB push_back
#define FF first
#define SS second

#define FORN(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n) - 1; i >= 0; i--)

#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR0(A,n) { cout << #A << " = "; FORN(_,n) cout << A[_] << ' '; cout << endl; }

#define MOD 1000000007
#define INF 2000000000

int GLL(LL& x) {
    return scanf("%lld", &x);
}

int GI(int& x) {
    return scanf("%d", &x);
}

const int HOURS = 24;
int at[2 * HOURS];

int n, d;

map<int, int> cnt;

vector<int> idk;

int mask(int x) {
    return 1 << x;
}

bool contains(int s, int x) {
    return s & mask(x);
}

int calc() {
//    PR0(at, HOURS);
    for (int i = HOURS; i < 2 * HOURS; i++) at[i] = at[i-HOURS];

    int res = INF;

    int i = 0;

    while (i < 2 * HOURS) {
        int j = i+1;
        while (j < 2 * HOURS && !at[j]) j++;

        if (j == 2 * HOURS) {
            break;
        }
        else {
            res = min(res, j - i);
        }

        i = j;
    }

    return res;
}

int main() {
    GI(n);

    FORN(i, n) {
        GI(d);
        cnt[d]++;
    }

    memset(at, 0, sizeof at); at[0] = 1;

    if (cnt[0] > 0) {
        cout << 0 << "\n";
        return 0;
    }

    if (cnt[12] > 1) {
        cout << 0 << "\n";
        return 0;
    }
    else if (cnt[12] == 1) {
        at[12] = 1;
    }

    for (int i = 1; i <= 11; i++) {
        if (cnt[i] > 2) {
            cout << 0 << "\n";
            return 0;
        }
        else if (cnt[i] == 2) {
            at[i] = at[24-i] = 1;
        }
        else if (cnt[i] == 1) {
            idk.PB(i);
        }
    }

    int res = 0;

    int m = idk.size();

    FORN(i, mask(m)) {
        FORN(j, m) {
            if (contains(i, j)) {
                at[idk[j]] = 1;
                at[24-idk[j]] = 0;
            }
            else {
                at[24-idk[j]] = 1;
                at[idk[j]] = 0;
            }
        }

        res = max(res, calc());
    }

    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
bool prime[50001];
void eratos(void)
{
	memset(prime,true,sizeof(prime));
	prime[0]=false;
	prime[1]=false;
	for(int i=2;i*i<50001;i++)
	{
		if(!prime[i])continue;
		for(int j=i*2;j<50001;j+=i)
		{
			prime[j]=false;
		}
	}
	return;
}
int main()
{
	eratos();
	int n,count;
	while(scanf("%d",&n)!=EOF)
	{
		if(n==0)break;
		count =0;
		for(int i=1;i<n/2+1;i++)
		{
			if(prime[i]&&prime[n-i])count++;
		}
		cout << count << endl;
	}
	return 0;
}

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

int main()
{
	int n, m = 0;
	long x;
	long a[100];

	cin >> n >> x;

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

	sort(a, a + n);

	while (x - a[m] >= 0 && m < n - 1) {
		x -= a[m];
		m++;
	}

	if (x == a[m])
		m = n;

	cout << m << endl;

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int read(){
	int ans=0,f=1,c=getchar();
	while(c<'0'||c>'9'){if(c=='-') f=-1; c=getchar();}
	while(c>='0'&&c<='9'){ans=ans*10+(c-'0'); c=getchar();}
	return ans*f;
}
int l,r,ll,rr,ans;
int f[1007];
int main(){
	l=read(); r=read(); ll=read(); rr=read();
	for(int i=l;i<r;i++) f[i]++;
	for(int i=ll;i<rr;i++) f[i]++;
	for(int i=0;i<=150;i++) if(f[i]==2) ans++;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
import numpy as np
N = int(input())
K = int(input())
X = np.array(list(map(int, input().split())))

distance_B = np.abs(X - K)
total_distance = 0
for x, b in zip(X, distance_B):
    if x > b:
        total_distance += 2*b
    else:
        total_distance += 2*x

print(total_distance)


Measured memory_bytes: 12428
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

//using namespace __gnu_pbds;
using namespace std;

typedef  long long ll;
typedef long double ld;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define endl "\n"
#define ioss ios::sync_with_stdio(0);cin.tie(0);
#define pb push_back
#define eb emplace_back



double startTime;
double gct()//get_current_time
{
    return ((double)clock()-startTime)/CLOCKS_PER_SEC;
}

void suraj();

int main()
{
    startTime=(double)clock();
    //freopen("input.txt","r",stdin);
    //freopen("output.txt,"w",stdout);
    //ioss
    //int t;cin>>t;while(t--)
    suraj();
    //suraj2();
    //suraj3();
    //suraj4();
    return 0;
}




































void suraj(){
ll n,w;cin>>n>>w;
vector<int>weight(n),value(n);
for(int i=0;i<n;i++){
    cin>>weight[i]>>value[i];
}
ll sum=0;
for(ll i:value)sum+=i;
//vector<int>dp(n*1000+1);
vector<ll>dp(sum+1);
for(int i=0;i<=sum;i++){
    dp[i]=1e13;
}
//dp[i] is the minimum weight  for getting a value exactly equal to i;
//ASSUMPTIONS FOR IMPOSSIBLE VALUES.cz corresponding values were not present in the input
dp[0]=0;
//cout<<"HI"<<endl;
for(int i=0;i<n;i++){
    for(int j=sum-value[i];j>=0;j--){
        dp[j+value[i]]=min(dp[j+value[i]],dp[j]+weight[i]);
    }
    //for(int k=0;k<=sum;k++)cout<<dp[k]<<" ";cout<<endl;
}
int ans=0;
for(int i=0;i<=sum;i++){
    if(dp[i]<=w){
        ans=max(ans,i);
    }
}
cout<<ans<<endl;
}













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

#define int long long

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int X;
	cin >> X;
	for (int i = X; i <= 2 * X; i++) {
		bool f = 1;
		for (int j = 2; j * j <= i; j++) {
			if (i % j == 0) {
				f = 0;
				break;
			}
		}
		if (f) {
			cout << i;
			return 0;
		}
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

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

Measured memory_bytes: 3632