akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int main(){
  string S, T;
  int cnt = 0;
  cin >> S >> T;
  for (int i = 0; i < S.size(); i++){
    if (S[i] == T[i]) cnt++;
  }
  if (T[S.size()] >= 'a' && T[S.size()] <= 'z') cnt++;
  if (cnt == T.size()) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

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

int main() {
	int n;
	ll r;
	cin >> n >> r;
	for (int i = 1; i < n; i++) {
		ll t;
		cin >> t;
		r *= t / gcd(r, t);
	}
	cout << r << endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringJoiner;

public class Main{
    public static void main(String[] args) throws IOException{
        InputStreamReader inputStreamReader = new InputStreamReader(System.in);
        BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
        String input = bufferedReader.readLine();
        String inputs[] = input.split(" ");
        String result = String.join(" ", inputs[2], inputs[0], inputs[1]);
        System.out.println(result);
    }
}

Measured memory_bytes: 21076
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

n,k = get_nums_l()
hhh = get_nums_l()

print(len(list(filter(lambda h:h>=k, hhh))))

Measured memory_bytes: 50340
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <vector>
#include <random>
#include <utility>
#include <limits>
#include <list>

/* template start */
 
#define rep(i, a, b) for (long long i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()

#ifdef LOCAL
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  if(sizeof...(t)>0)std::cout<<" :";
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}

template<typename Num>
constexpr Num mypow(Num a, unsigned long long b) {
  if(b==0)return 1;
  if (a==0)return 0;
  Num x = 1;
  while (b > 0) {
    if(b & 1)x*=a;
    a*=a;
    b >>= 1;
  }
  return x;
}

/* template end */

using ll = long long;

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

  ll n;
  std::cin>>n;

  std::set<std::string> set;

  while(n--){
    std::string s;
    std::cin>>s;
    set.insert(s);
  }

  std::cout<<set.size()<<"\n";

  return 0;
}

Measured memory_bytes: 19244
package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	read  = bufio.NewReader(os.Stdin)
	write = bufio.NewWriter(os.Stdout)
)

func min(a, b int) int {
	if a <= b {
		return a
	}
	return b
}

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

func yesno(result bool) {
	if result {
		fmt.Fprintln(write, "Yes")
	} else {
		fmt.Fprintln(write, "No")
	}
}

func printansStr(result bool, a, b string) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

func printansInt(result bool, a, b int) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

func main() {
	defer write.Flush()

	var s int
	fmt.Fscan(read, &s)
	fmt.Fprintln(write, s*s*s)

}


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

ll N, P[100000];

int main(void) {
  cin >> N;
  REP(i, 0, N) cin >> P[i];

  ll ans = 0;
  REP(i, 0, N - 1) {
    if(P[i] == i + 1) {
      swap(P[i], P[i + 1]);
      ans++;
    }
  }
  if(P[N - 1] == N) ans++;

  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <limits.h>

int main(void){
    int n;
    scanf("%d",&n);
    long long a[n+2],l[n+2],r[n+2],ans=0;
    for (int i=0; i<n; i++){
        scanf("%lld",&a[i]);
    }
    for (int i=0; i<n; i++){
        long long tmp=i-1;
        while(tmp!=-1 && a[tmp]>a[i]){
            tmp=l[tmp];
        }
        l[i]=tmp;
    }
    for (int i=n-1; i>=0; i--){
        long long tmp=i+1;
        while(tmp!=n && a[tmp]>a[i]){
            tmp=r[tmp];
        }
        r[i]=tmp;
    }
    for (int i=0; i<n; i++){
        ans+=a[i]*(i-l[i])*(r[i]-i);
    }
    printf("%lld\n",ans);
	return 0 ;
}

Measured memory_bytes: 4864
#[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")
    };
}

fn main() {
    input! {
        s: String,
    }
    let splited: Vec<&str> = s.split("/").collect();
    let year: u64 = splited[0].parse().unwrap();
    let month: u64 = splited[1].parse().unwrap();
    // let day: u64 = splited[2].parse().unwrap();
    if year < 2019 {
        println!("Heisei");
    } else if year == 2019 {
        if month > 4 {
            println!("TBD");
        } else {
            println!("Heisei");
        }
    } else {
        println!("TBD");
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <vector>
#include <map>

#define for0(i, n) for (int i = 0; i < (int)(n); ++i) // 0 based indexing
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i) // 1 based indexing
#define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i) // closed interver from l to r r inclusive
#define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i) // reverse 0 based.
#define forr1(i, n) for (int i = (int)(n); i >= 1; --i) // reverse 1 based

//short hand for usual tokens
#define pb push_back
#define fi first
#define se second

// to be used with algorithms that processes a container Eg: find(all(c),42)
#define all(x) (x).begin(), (x).end() //Forward traversal
#define rall(x) (x).rbegin, (x).rend() //reverse traversal

// traversal function to avoid long template definition. Now with C++11 auto alleviates the pain.
#define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++)

// find if a given value is present in a container. Container version. Runs in log(n) for set and map
#define present(c,x) ((c).find(x) != (c).end())

//find version works for all containers. This is present in std namespace.
#define cpresent(c,x) (find(all(c),x) != (c).end())

#define sz(a) int((a).size())


using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    string s; cin>>s;
    int n = s.length();
    if(s[n-1] == 's') s += "es";
    else s += "s";
    cout<<s<<endl;
}



Measured memory_bytes: 3648
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>

const int MX = 202020,  MOD = 1000000007;
int C[MX], last[MX], dp[MX];

using namespace std;

int main() {
    int N;
    ignore = scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        ignore = scanf("%d", C+i);
    }
    for (int i = 0; i < MX; ++i)  last[i] = -1;
    dp[0] = 1;
    for (int i = 0; i < N; ++i) {
        //cout << "i: " << i << " color: " << C[i] << " last: " << last[C[i]] << endl;
        if (last[C[i]] != -1 && last[C[i]] != i-1 ) {
            dp[i+1] = (dp[i] + dp[last[C[i]]+1] ) % MOD;
        }
        else dp[i+1] = dp[i];
        last[C[i]] = i;
    
    }
    printf("%d\n", dp[N]);
    return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main(){
	string a;
	cin>>a;
	if(a[0]==a[1])
	cout<<"Bad"<<endl;
	else if(a[1]==a[2])
	cout<<"Bad"<<endl;
	else if(a[2]==a[3])
	cout<<"Bad"<<endl;
	else cout<<"Good"<<endl;
	return 0;
}

Measured memory_bytes: 256
while True:
    n, x = map(int, input().split())
    if n == x == 0:
        break
    cnt = 0
    for i in range(1, n+1):
        for j in range(i+1, n+1):
            for k in range(j+1, n+1):
                if i + j + k == x:
                    cnt += 1
    print(cnt)

Measured memory_bytes: 7660
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string ans="Yes";
  cin>>n;
  vector<string> s(n);
  cin>>s[0];
  for(int i=1;i<n;i++){
    cin>>s[i];
    if(s[i-1].at(s[i-1].size()-1)!=s[i].at(0)){ans="No"; break;}
  }
  for(int i=1;i<n;i++){
    for(int j=0;j<i;j++){
      if(s[i]==s[j]){ans="No"; break;}
    }
  }
  cout<<ans;
}
    

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

int main(){
  int N,M;cin>>N>>M;
  vector<int> L(M),R(M);
  for(int i=0;i<M;i++) cin>>L.at(i)>>R.at(i);
//  vector<bool> A(N,true);
  sort(L.begin(),L.end());
  sort(R.begin(),R.end());
  reverse(L.begin(),L.end());
  if(L.at(0)<=R.at(0)) cout<<R.at(0)-L.at(0)+1<<endl;
  else cout<<0<<endl;
}
  
  


Measured memory_bytes: 3984
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>

using namespace std;

int main(){
	int y,m,d;
	while(cin>>y>>m>>d){
		if(y < 1867 || y <= 1868 && (m <= 8 || m <= 9 && d <= 7)){
			puts("pre-meiji"); continue;
		} else if(y < 1911 || y <= 1912 && (m <= 6 || m <= 7 && d <= 29)){
			printf("meiji %d %d %d\n",y - 1867,m,d); continue;
		} else if(y < 1925 || y <= 1926 && (m <= 11 || m <= 12 && d <= 24)){
			printf("taisho %d %d %d\n",y - 1911,m,d); continue;
		} else if(y < 1988 || y <= 1989 && (m == 1 && d <= 7)){
			printf("showa %d %d %d\n",y - 1925,m,d); continue;
		} else {
			printf("heisei %d %d %d\n",y - 1988,m,d); continue;
		}
	}
    return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <cstdio>

using namespace std;

string S;

long long all_sum = 0;

void search(int i, int j, int sum)
{
		if(i == S.length())
		{
				all_sum += (sum + stoll(S.substr(j)));
		}
		else
		{
				search(i+1, i, sum + stoll(S.substr(j, i-j)));
				search(i+1, j, sum);
		}
}


int main(int argc, char const* argv[])
{
		cin >> S;

		search(1,0,0);
		cout << all_sum << endl;

		return 0;
}


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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , "; logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */
int n;
lint a[MAX];
vector<int> to[MAX];
vector<lint> dp;
int ans[MAX];

void dfs(int s, int p=-1){
    auto itr = lower_bound(all(dp), a[s]);
    lint tmp = *itr; *itr = a[s];
    auto itr2 = lower_bound(all(dp), INF-1);
    ans[s] = itr2 - dp.begin();

    for(int t : to[s]){
        if(t == p) continue;
        dfs(t, s);
    }
    *itr = tmp;
}

int main(){
    cin >> n;
    rep(i, n) cin >> a[i];
    rep(i, n-1){
        int a, b; cin >> a >> b; a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    dp = vector<lint>(n);
    rep(i, n) dp[i] = INF;

    dfs(0);
    rep(i, n) out(ans[i]);
}

Measured memory_bytes: 29544
#include <stdio.h>
#include<algorithm>
using namespace std;

#define MAX 1400

int dp[MAX][MAX],G[MAX][MAX];

int getLargestSquare(int h,int w){
    int maxWidth = 0;
    for(int i = 0;i < h;++i){
        for(int j = 0;j < w;++j){
            // 1が汚れたタイルなので、面積は0に、0は綺麗なタイルなので、面積が1になる
            dp[i][j] = (G[i][j] + 1) % 2;
            // 面積が1の場合、最大面積を計算する処理がスルーされるので、面積を暫定でいれる
            maxWidth |= dp[i][j];
        }
    }

    for(int i = 1;i < h;++i){
        for(int j = 1;j < w;++j){
            // 汚れている状態
            if(G[i][j]){
                dp[i][j] = 0;
            }else{
                // 左上,上,左の最小値の+1がdp[i][j]の正方形の最大面積となる
                dp[i][j] = min(dp[i-1][j-1],min(dp[i-1][j],dp[i][j - 1])) + 1;
                maxWidth = max(maxWidth,dp[i][j]);
            }
        }
    }
    return maxWidth * maxWidth;
}

int main(){
    int h,w;
    scanf("%d %d",&h,&w);
    
    for(int i = 0;i < h;++i){
        for(int j = 0;j < w;++j){
            // 地面の状態
            scanf("%d",&G[i][j]);
        }
    }
    
    printf("%d\n",getLargestSquare(h,w));
    return 0;
}



Measured memory_bytes: 18008
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 200100;
const int MOD = 1e9+7;
int p[MAXN];
int main() {
	string n;
	int k;
	cin >> n >> k;
	int sum = 0;
	int len = n.size();
	int n_fi = n[0] - '0';
	if(k == 1){
		for(int i = 1; i <= 9;i++){
			if(i <= n_fi){
				sum += len;
			}else{
				sum += len -1;
			}
		}
	}
	if(k == 2){
		sum = (len - 1)*(len - 2) /2 * 81;
		sum += (n_fi - 1) * 9 * (len - 1);
		for(int i = 1; i < len; i++){
			for(int j = 1; j<= 9; j++){
				string now = string (len,'0');
				now[0] = n[0];
				now[i] = j + '0';
				if(now <= n)
					sum++;
			}
		}
	}
	if(k == 3){
		sum = (len - 1) * (len - 2) * (len - 3) / 6 * 729;
		sum += (n_fi - 1) * 81 * (len - 1)*(len - 2) /2;
		for(int i = 1; i < len;i++){
			for(int j = 1; j <= 9; j++){
				for(int ii = i+1; ii < len; ii++){
					for(int jj = 1; jj <= 9; jj++){
						string now = string (len,'0');
						now[0] = n[0];
						now[i] = j+'0';
						now[ii] = jj+'0';
						if(now <= n)
						sum++;
					}
				}
			}
		}

	}
	cout << sum << endl;
	return 0;
}

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

typedef long long ll;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (1e9+7)
#define rep(i,n) for(ll i=0; i<(ll)n;i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)

/*--------------------------------------------*/

int main(){
  ll n, m;
  cin >> n >> m;
  
  priority_queue<ll> pq;
  
  ll a;
  
  rep(i,n){
      cin >> a;
      pq.push(a);
  }
  
  rep(i,m){
      a = pq.top();
      pq.pop();
      a/=2;
      pq.push(a);
  }
  
  ll ans = 0;
  
  while(!pq.empty()){
      ans += pq.top();
      pq.pop();
  }
  
  cout << ans << endl;
  
  
  
}

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

int N;
int D[100];

void input() {
    cin >> N;
    for (int i = 0; i < N; ++i) cin >> D[i];
}

int main() {
    input();
    int cnt = 0;
    int beforeVal = 0;
    sort(D, D + N, greater<int>());  // a[0:N] を大きい順にソート

    for(int i = 0; i < N; i++){
        if (beforeVal != D[i]){
            cnt++;
        }
        beforeVal = D[i];
    }
    cout << cnt << endl;
    return 0;
}

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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
#define Size(n) (n).size()

typedef long long ll;

using namespace std;

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

//long long int kaizyo(long long int hh){
  //  cmp=1;
    //while(hh>1){
      //  cmp=(cmp*hh)%MOD;
        //hh--;
    //}
    //return cmp;
//}
//long long int ruizyo(long long int aa, long long int bb){
  //  if(aa==0){
    //    return 1;
    //}
    //else if(aa%2==0){
      //  long long int tt=ruizyo(aa/2,bb);
        //return (tt*tt)%MOD;
    //}
    //else{
      //  return (ruizyo(aa-1,bb)*bb)%MOD;
    //}
//}フェルマ－のア


//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

//bool f[100001];//1000000以下の素数を調べよう！
//rrep(i,2,100001){
  //      f[i]=false;
    //}
//rrep(i,2,100001){
  //      if(!f[i]){
    //        for(int j=i+i;j<=100000;j+=i){
      //          f[j]=true;
        //    }
        //}
    //}
    //for(int i=3;i<=100000;i+=2){
      //  if(!f[i]){
        //    c[i]++;
      //  }
   // }

//visited=vector<vector<bool>>(10,vector<bool>(10,false));アを全部falseに


long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=true;

//-------------------------↓↓↓↓↓↓----------------------------

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

       cin >> a >> b >> c;
       for(int i=a;i<=100000;i+=a){
           pos=i;
           if(pos%b==c){
               Cout("YES");
               return 0;
           }
       }
       Cout("NO");
       
return 0;
}


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

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

    string s2;
    for (int i = 0; i < s.length(); i++)
    {
        char c = s[i];
        if (c == ',')
        {
            s2 += ' ';
        }
        else
        {
            s2 += c;
        }
    }
    cout << s2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 110
using namespace std;
int h,w;
char mp[N][N];
int col[N][N];
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};

void paint(int y,int x,int c){
  col[y][x] = c;
  int ch = mp[y][x];

  for(int i=-1;i<=1;i++)
    for(int j=-1;j<=1;j++){
      int ny = y + i;
      int nx = x + j;
      if(nx<0||ny<0||nx>=w||ny>=h||mp[ny][nx]!=ch||col[ny][nx]!=-1) continue;
      if(ch == '.' && i!=0 && j!=0) continue; 
      paint(ny,nx,c);
    }
}

vector<vector<int> >mkG(){

  cin>>h>>w;
  memset(mp,'.',sizeof(mp));
  if(!h&&!w) exit(0);
  for(int i=1;i<=h;i++)
    for(int j=1;j<=w;j++) cin>>mp[i][j];
  h+=2,w+=2;
  
  vector< vector<int>> res;
  memset(col,-1,sizeof(col));

  paint(0,0,0);
  int cnt = 1;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++){
      if(col[i][j] != -1)continue;
      res.push_back(vector<int>());
      for(int k=0;k<4;k++) {
	int ny = i+dy[k];
	int nx = j+dx[k];
	if(nx<0||ny<0||nx>=w||ny>=h||col[ny][nx]==-1)continue;
	
	res[col[ny][nx]].push_back(cnt);
	break;
      }
      paint(i,j,cnt++);
    }
  return res;
}




string GtoS(int pos,vector<vector<int>> &G){
  string res;

  priority_queue<string> Q;
  if(pos<(int)G.size())
    for(int nx:G[pos])Q.push(GtoS(nx,G));
  
  while(!Q.empty()){ res+=Q.top();Q.pop();}
  return '0'+res+'1';
}



int main(){
  while(1){
    vector<vector<int>> G1=mkG();
    vector<vector<int>> G2=mkG();
    string s1 = GtoS(0,G1);
    string s2 = GtoS(0,G2);
    cout<<(s1==s2? "yes":"no")<<endl;
  }
  return 0;
}

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

using namespace std;

#define ll long long
#define ull unsigned long long
#define vll vector<ll>
#define pii pair<int, int>
#define vii vector<pii>
#define vs vector<string>
#define vb vector<bool>
#define vi vector<int>
#define vd vector<double>
#define vvi vector< vector<int> >
#define vvii vector< vector< pii > >
#define ld long double
#define mapii map<int, int>
#define mapsi map<string, int>
#define erep(i, x, n) for (auto i = x; i<=(ll)(n); i++)
#define rep(i, x, n) for(auto i = x; i<(ll)(n); i++)
#define INF  LLONG_MAX
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define pi  acos(-1)
#define mod(n,m) ((n % m + m) % m)
#define eps (1e-8)
#define reset(n, m) memset(n, m, sizeof n)
#define endl '\n'
#define output freopen("output.txt", "w", stdout)
#define mp(x, y, z) {x, {y, z}}

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

	ll a, b;
	cin >> a >> b;

	vi vec;
	while(b)
	{
		int rem = b%10;
		vec.push_back(rem);
		b /= 10;
	}

	for(int i = sz(vec)-1; i>=0; i--)
	{
		a = a*10 + vec[i];
	}

	ll x = sqrt(a);
	if (x*x == a)
		cout << "Yes";
	else cout << "No";

	return 0;
}


Measured memory_bytes: 256
# Author: cr4zjh0bp
# Created: Sun Mar 22 23:25:40 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n = ni()
a = na()

print(max(a) - min(a))

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

int main() {
    string s, sub;
    int K, cost;
    cin >> s >> K;
    vector<string> v;

    for (int i = 0; i < s.length(); i++) {
        for (int j = 1; j <= K; j++) {
            sub = s.substr(i, j);
            v.push_back(sub);
        }
    }

    sort(v.begin(), v.end());
    v.erase(std::unique(v.begin(), v.end()), v.end());

    cout << v[K - 1] << endl;

    return 0;

}

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

constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

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

/*-------------------------------------------*/

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

    ll n, mn = inf, sum = 0;

    cin >> n;
    rep(i, n) {
        ll a, b;
        cin >> a >> b;
        sum += a;
        if(a > b) chmin(mn, b);
    }

    cout << max(0LL, sum - mn) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
	long long a,b,x,st,en,ans=0;
	cin>>a>>b>>x;
	if(a%x==0) st=a/x;
	else st=a/x+1;
	en=b/x;
	printf("%lld",en-st+1);return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include  <iostream>
#include  <algorithm>
#include  <climits>
#include  <vector>
#include  <string>
#include  <cstring>
#include  <stack>
#include  <queue>
#include  <cmath>
#include  <iomanip>
#include  <set>
#include  <map>
#include  <new>
#include <cstdint>
#include <cctype>
#include  <cstdio>
using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define lrep(i,n,m)  for(int i = n; i < m; i++)

using ll = long long;
using ld = long double;
using Vii = vector<vector<int> >;
using Gjudge = vector<vector<bool>>;
using Vi = vector<int>;
using Vl = vector<ll>;
using Vd = vector<double>;
using Vld = vector<long double>;
using Vll = vector<vector<ll> >;
using Vldd = vector<vector<ld> >;
using Vs = vector<string>;
using Vb = vector<bool>;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Pli = pair<ll, int>;
using VPi = vector<Pi>;
using VPl = vector<Pl>;
using VPli = vector<Pli>;
using Ti = tuple<int, int, int>;
using Tl = tuple<ll, ll, ll>;

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

const int Mod = static_cast<int>(1e9 + 7);
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;
const int dx[4] = { 1,0,-1,0 };
const int dy[4] = { 0,1,0,-1 };


int main()
{
	int n;
	cin >> n;
	Vi A(n);
	rep(i, n) cin >> A[i];
	sort(A.begin(), A.end());
	for (int i = 1; i < n; i++) {
		if (A[i] == A[i - 1]) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
}


Measured memory_bytes: 3996
#include <vector>
            #include <list>
            #include <map>
            #include <set>
            #include <queue>
            #include <deque>
            #include <stack>
            #include <bitset>
            #include <algorithm>
            #include <functional>
            #include <numeric>
            #include <utility>
            #include <sstream>
            #include <iostream>
            #include <iomanip>
            #include <cstdio>
            #include <cmath>
            #include <cstdlib>
            #include <ctime>
            #include <string>
            #include <climits>
            #include <tuple>
            using namespace std;
            typedef long long ll;
            typedef pair<int,int> P;
            typedef tuple<int,int,int,int> T;
             
             
             
             
            int bit[100003],n;
            int sum(int i){
                int s=-1;
                while(i>0){
                    s=max(bit[i],s);
                    i-=i&-i;
                }
                return s;
            }
            void add(int i,int x){
                while(i<=n){
                    bit[i]=max(bit[i],x);
                    i+=i&-i;
                }
            }
            int main(){
                int a,b;
                cin>>a>>b;
                if((a+b)==15)cout<<'+'<<endl;
                else if ((a*b)==15) cout<<'*'<<endl;
                else cout<<'x'<<endl;
                return 0;
            }

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

int main(int argc, char* argv[]){
    char c[3][3];
    for(int i = 0; i < 3; i++){
        scanf("%s", c[i]);
    }
    cout << c[0][0] << c[1][1] << c[2][2] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    string S;
    cin >> S;
    if (N % 2 != 0) {
        cout << "No" << endl;
        return 0;
    }
    if (S.substr(0, N / 2) == S.substr(N / 2, N / 2)) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}

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

int main() {
        int i, j;
        int x, y, s;
        while (cin >> x >> y >> s) {
                if (x == 0 && y == 0 && s == 0) break;
                int ans = -1;
                for (i = 1; i < s - 1; i ++) {
                        for (j = 1; j < s - 1; j ++) {
                                int ii = (i * (100 + x)) / 100;
                                int jj = (j * (100 + x)) / 100;
                                if (ii + jj == s) {
                                        int res = (i * (100 + y)) / 100;
                                        res += (j * (100 + y)) / 100;
                                        ans = max(ans, res);
                                }
                        }
                }
                cout << ans << endl;
        }
        return 0;
}

Measured memory_bytes: 3076
using System;
using System.Linq;

namespace AtCoderCS
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();
            var inputArray = input.Split(' ');
            var N = long.Parse(inputArray[0]);
            var K = long.Parse(inputArray[1]);

            if (N % K == 0)
            {
                Console.WriteLine(0);
                return;
            }

            N = (N % K);

            while (N > Math.Abs(N - K))
            {
                N = Math.Abs(N - K);
            }
            Console.WriteLine(N);
        }
    }
}


Measured memory_bytes: 11092
def check(P,w,n):
    i = 0
    for j in range(k):
        s = 0
        while s + w[i] <= P:
            s += w[i]
            i += 1
            if i == n:
                return n
    return i

s = input().split(" ")
n = int(s[0])
k = int(s[1])
w = []
for i in range(n):
    a = int(input())
    w.append(a)

left = 0
right = 100000 * 10000
while right - left > 1:
    mid = int((right + left) / 2)
    v = check(mid,w,n)
    if v >= n:
        right = mid
    else:
        left = mid
print(right)

Measured memory_bytes: 11660
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long mod = 1e9 + 7;
const int iINF = 0x3f3f3f3f;
const long long INF = 1LL << 60;
using namespace std;

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

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

int main()
{
  ll a, b, n;
  cin >> a >> b >> n;

  ll tmp = min(b - 1, n);
  cout << tmp * a / b << endl;
  return 0;
}


Measured memory_bytes: 3588
#include<iostream>
#include<cstdio>
using namespace std;
const int N=5005;
int n,k,m,h[N],cnt,ans=1e9,sm;
struct qwe
{
	int ne,no,to;
}e[N];
int read()
{
	int r=0,f=1;
	char p=getchar();
	while(p>'9'||p<'0')
	{
		if(p=='-')
			f=-1;
		p=getchar();
	}
	while(p>='0'&&p<='9')
	{
		r=r*10+p-48;
		p=getchar();
	}
	return r*f;
}
void add(int u,int v)
{
	cnt++;
	e[cnt].ne=h[u];
	e[cnt].no=u;
	e[cnt].to=v;
	h[u]=cnt;
}
void dfs(int u,int fa,int de)
{
	if(de>m)
		sm++;
	for(int i=h[u];i;i=e[i].ne)
		if(e[i].to!=fa)
			dfs(e[i].to,u,de+1);
}
int main()
{
	n=read(),k=read(),m=k/2;
	for(int i=1;i<n;i++)
	{
		int x=read(),y=read();
		add(x,y),add(y,x);
	}
	if(k&1)
	{
		for(int i=1;i<=cnt;i+=2)
		{
			sm=0;
			dfs(e[i].no,e[i].to,0);
			dfs(e[i].to,e[i].no,0);
			ans=min(ans,sm);
		}
	}
	else
	{
		for(int i=1;i<=n;i++)
		{
			sm=0;
			dfs(i,0,0);
			ans=min(ans,sm);
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long a,b,x,ans;
	scanf("%lld%lld%lld",&a,&b,&x);
	if(a==0){
		ans=(b/x)+1;
		}
	else {
	    ans=(b/x)-(a-1)/x;	
	}
	printf("%lld",ans);
}

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

bool linearSearch(int A[], int key, int size) {
	int i = 0;
	A[size] = key;
	while (A[i] != key) i++;
	return i != size;
}

int main() {
	int size, query, queryNum, count = 0;

	cin >> size;
	int* A = new int[size + 1];
	for (int i = 0; i < size; i++) scanf("%d", &A[i]); 
	
	cin >> queryNum;
	for (int i = 0; i < queryNum; i++) {
		scanf("%d", &query);
		if (linearSearch(A, query, size)) count++;
	}

	cout << count << endl;

	delete[] A;
}

Measured memory_bytes: 3188
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

ll S;

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

  ll x1 = 0, y1 = 0;
  ll x2 = 1e9, y2 = 1;

  // S = x2 * y3 - x3
  ll y3 = ceil((double)S / (double)x2);
  ll x3 = x2 * y3 - S;

  cout << x1 << " " << y1 << " ";
  cout << x2 << " " << y2 << " ";
  cout << x3 << " " << y3 << endl;
  return 0;
}

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

const ll MOD = 1000000007;
const int mask = (1 << 18) - 1;

int N, X, Y, Z;
int dp[42][1 << 18];

inline bool ban(int bit)
{
    if (!((bit >> Z) & 1))           return false;
    if (!((bit >> (Z + Y)) & 1))     return false;
    if (!((bit >> (Z + Y + X)) & 1)) return false;
    return true;
}

int main() {
    cin >> N >> X >> Y >> Z;
    
    for (int i = 1; i <= 10; ++i) {
	dp[0][1 << i] = 1;
    }

    for (int i = 1; i < N; ++i) {
	rep(j, 1 << 18) {
	    for (int k = 1; k <= 10; ++k) {
		int bit = (ll)(j << k) & mask;
		bit |= 1 << k;

		if (!ban(bit)) {
		    dp[i][bit] = (dp[i][bit] + dp[i - 1][j]) % MOD;
		}
	    }
	}
    }

    ll ret = 0;
    rep(i, 1 << 18) ret = (ret + dp[N - 1][i]) % MOD;

    ll all = 1;
    rep(i, N) all = all * 10 % MOD;

    ret = (all - ret + MOD) % MOD;
    cout << ret << endl;

    return 0;
}

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

int main() {
    int n, x;
    cin >> n >> x;
    vector<int> L(n);
    vector<int> D(n + 1);
    rep(i, n) { cin >> L[i]; }
    int ans = 1;
    for(int i = 1; i <= n; i++) {
        D[i] = D[i - 1] + L[i - 1];
        if(D[i] > x) {
            break;
        }
        ans++;
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int points = Integer.parseInt(sc.next());
        int dimensions = Integer.parseInt(sc.next());
        
        int[][] coordinate = new int[points][dimensions];
        
        for (int i = 0; i < points; i++) {
            for (int j = 0; j < dimensions; j++) {
                coordinate[i][j] = Integer.parseInt(sc.next());
            }
        }

        int intCount = 0;
        for (int i = 0; i < (points - 1); i++) {
            for (int j = i + 1; j < points; j++) {
                int pointDistance = 0;

                for (int dimension = 0; dimension < dimensions; dimension++) {
                    pointDistance += Math.abs(Math.pow(coordinate[i][dimension] - coordinate[j][dimension], 2));
                }

                double distance = Math.sqrt(pointDistance);
                if ((distance % 1) == 0) {
                    intCount++;
                }
            }
        }

        System.out.println(intCount);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  int h,w,k;
  cin>>h>>w>>k;

  int sy,sx,gy,gx;
  cin>>sy>>sx>>gy>>gx;
  sy--;sx--;gy--;gx--;

  vector<string> st(h);
  for(int i=0;i<h;i++) cin>>st[i];

  vector<set<int>> H(h),W(w);
  vector<set<int>> U(h),V(w);

  for(int i=0;i<h;i++){
    U[i].emplace(-1);
    U[i].emplace(w);
    H[i].emplace(-2);
    H[i].emplace(w+1);
  }
  for(int j=0;j<w;j++){
    V[j].emplace(-1);
    V[j].emplace(h);
    W[j].emplace(-2);
    W[j].emplace(h+1);
  }

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(st[i][j]=='@'){
        U[i].emplace(j);
        V[j].emplace(i);
      }else{
        H[i].emplace(j);
        W[j].emplace(i);
      }
    }
  }

  using P = pair<int, int>;
  queue<P> que;
  vector dp(h,vector(w,-1));
  auto push=[&](int i,int j,int d){
    // cerr<<i<<' '<<j<<':'<<d<<' '<<dp[i][j]<<endl;
    assert(dp[i][j]<0);
    dp[i][j]=d;
    que.emplace(i,j);
    H[i].erase(j);
    W[j].erase(i);
  };

  push(sy,sx,0);

  while(!que.empty()){
    auto [y,x]=que.front();que.pop();
    int nd=dp[y][x]+1;
    // cerr<<y<<' '<<x<<':'<<dp[y][x]<<"-------"<<endl;
    {
      int b=*U[y].lower_bound(x);
      while(!H[y].empty()){
        int ny=y;
        int nx=*H[y].lower_bound(x);
        if(abs(b-x)<abs(nx-x) or abs(nx-x)>k) break;
        push(ny,nx,nd);
      }
    }
    {
      int b=*--U[y].lower_bound(x);
      while(!H[y].empty()){
        int ny=y;
        int nx=*--H[y].lower_bound(x);
        if(abs(b-x)<abs(nx-x) or abs(nx-x)>k) break;
        push(ny,nx,nd);
      }
    }
    // cerr<<"::::::"<<endl;
    {
      int b=*V[x].lower_bound(y);
      while(!W[x].empty()){
        int ny=*W[x].lower_bound(y);
        int nx=x;
        // for(int yy:W[x]) cerr<<yy<<endl;
        // cerr<<b<<":"<<ny<<endl;
        if(abs(b-y)<abs(ny-y) or abs(ny-y)>k) break;
        push(ny,nx,nd);
      }
    }
    {
      int b=*--V[x].lower_bound(y);
      while(!W[x].empty()){
        int ny=*--W[x].lower_bound(y);
        int nx=x;
        if(abs(b-y)<abs(ny-y) or abs(ny-y)>k) break;
        push(ny,nx,nd);
      }
    }
  }

  cout<<dp[gy][gx]<<newl;
  return 0;
}


Measured memory_bytes: 387072
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"

int N;
int X, Y, Z, A, B, C;
vector<long long int>getx() {
	vector<long long int>cs(X);
	cs[A] = 0;
	{
		int nc = 0;
		for (int x = A + 1; x < X; ++x) {
			nc++;
			nc %= N;
			cs[x] = nc;
		}
	}
	{
		int nc = 0;
		for (int x = A - 1; x >= 0; --x) {
			nc++;
			nc %= N;
			cs[x] = nc;
		}
	}
	vector<long long int>nums;
	for (int i = 0; i < N; ++i) {
		nums.emplace_back(count(cs.begin(), cs.end(), i));
	}
	vector<long long int>nums2(N);
	nums2[0] = 1;
	vector<long long int>ans(N);
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			ans[(i + j) % N] += nums[i] * nums2[j];
		}
	}
	
	return ans;
}
vector<long long int>getxy() {
	vector<long long int>cs(Y);
	cs[B] = 0;
	{
		int nc = 0;
		for (int y = B + 1;y < Y; ++y) {
			nc++;
			nc %= N;
			cs[y] = nc;
		}
	}
	{
		int nc = 0;
		for (int y = B - 1; y >= 0; --y) {
			nc++;
			nc %= N;
			cs[y] = nc;
		}
	}
	vector<long long int>nums;
	for (int i = 0; i < N; ++i) {
		nums.emplace_back(count(cs.begin(), cs.end(), i));
	}
	vector<long long int>nums2(getx());
	vector<long long int>ans(N);
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			ans[(i + j) % N] += nums[i] * nums2[j];
		}
	}
	return ans;
}
vector<long long int>getxyz() {
	vector<long long int>cs(Z);
	cs[C] = 0;
	{
		int nc = 0;
		for (int z = C + 1; z < Z; ++z) {
			nc++;
			nc %= N;
			cs[z] = nc;
		}
	}
	{
		int nc = 0;
		for (int z = C - 1; z >= 0; --z) {
			nc++;
			nc %= N;
			cs[z] = nc;
		}
	}
	vector<long long int>nums;
	for (int i = 0; i < N; ++i) {
		nums.emplace_back(count(cs.begin(), cs.end(), i));
	}
	vector<long long int>nums2(getxy());
	vector<long long int>ans(N);
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			ans[(i + j) % N] += nums[i] * nums2[j];
		}
	}
	return ans;
}

int main() { 
	cin >> X >> Y >> Z >> A >> B >> C;
	cin >> N;
	vector<long long int>ans=getxyz();
	for (int i = 0; i < N; ++i) {
		cout << ans[i];
		if (i != N - 1)cout << " ";
		else cout << endl;
	}

	return 0;
}

Measured memory_bytes: 26252
N, M = map(int, input().split())
to = [[] for i in range(N+1)]
for i in range(M):
    a, b = map(int, input().split())
    to[a].append(b)

S, T = map(int, input().split())

from collections import deque

q = deque([(S, 0)])
v = [[-1] * 3 for i in range(N+1)]

while q:
    a, t = q.popleft()
    b = t % 3
    if v[a][b] != -1:
        continue
    v[a][b] = t
    t += 1
    for x in to[a]:
        q.append((x, t))
    #print(q)


if v[T][0] == -1:
    print("-1")
else:
    print(v[T][0] // 3)

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

int main() {
    int n, m;
    cin >> n >> m;
    priority_queue<int> a;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        a.push(x);
    }
    while (!a.empty() && m > 0) {
        int x = a.top();
        a.pop();

        if (x > 1) {
            a.push(x / 2);
        }
        --m;
    }

    long long sum = 0;
    for (; !a.empty(); a.pop()) {
        sum += 1LL * a.top();
    }
    cout << sum << "\n";
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rep1(i, n) for(ll i = 1; i < n+1; i++)
#define all(A) A.begin(),A.end()
typedef long long ll;

bool isPrime(ll a){
  if(a == 1) return false;
  if(a == 2) return true;
  if(a%2 == 0) return false;
  for(ll i=3;i*i<=a;i += 2){
    if(a%i == 0) return false;
  }
  return true;
}

int main(){
  ll n,p;
  cin >> n >> p;
  if(n == 1){
    cout << p << endl;
    return 0;
  }
  map<ll,ll> mp;
  ll range = p;
  for(ll i=2;i*i<=range;i++){
    if(i > p) break;
    if(!isPrime(i))continue;
    if(p%i == 0){
      while(p%i == 0){
        mp[i] ++;
        p /= i;
      }
    }
  }
  ll ans = 1;
  for(auto p : mp){
    while(p.second >= n){
      p.second -= n;
      ans *= p.first;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3624
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_A main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


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

    int N = 3;
    vi A(N); REP(i,N) cin >> A[i];
    sort(A.begin(), A.end());

    int ans = A[0]*A[1]/2;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
X, Y, Z, K = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

queue = [(A[0]+B[0]+C[0], 0, 0, 0)]
ans = [(A[0]+B[0]+C[0], 0, 0, 0)]

for i in range(K):
    cake = max(queue, key=lambda x: x[0])
    queue.remove(cake)
    a, b, c = cake[1], cake[2], cake[3]
    for j in range(3):
        aa = a + [1, 0, 0][j]
        bb = b + [0, 1, 0][j]
        cc = c + [0, 0, 1][j]
        if aa < X and bb < Y and cc < Z:
            tmp = A[aa]+B[bb]+C[cc]
            if (tmp, aa, bb, cc) not in ans:
                ans.append((tmp, aa, bb, cc))
                queue.append((tmp, aa, bb, cc))

ans.sort(reverse=True)
for i in range(K):
    print(ans[i][0])


Measured memory_bytes: 4724