akhauriyash/Code-Regression huggingface dataset:
// 参考
// https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

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

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

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

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

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

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

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

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

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

// Test Code
macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r"5 5
" => r"5",

r"2 3
" => r"2",

r"11 30
" => r"11"
}

fn main() {
    println!("{}", solve(&stdin!()));
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        a: i32,
        b: i32,
    }

    let mut ans = 0;

    for i in 1..a + 1 {
        for j in 1..31 {
            if i == j {
                ans += 1;
                break;
            }
            if i == a && j == b {
                break;
            }
        }
    }

    ans.to_string()
}


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

using namespace std;

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

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

int n,m;
vi g[125252];
int indeg[125252];

int root;
int dist[125252];
int par[125252];

int main(){
  scanf("%d%d",&n,&m);
  REP(i,n-1+m){
    int a,b;
    scanf("%d%d",&a,&b); --a;--b;
    g[a].push_back(b);
    indeg[b]++;
  }
  REP(i,n)if(indeg[i]==0){
    root = i;
    par[root] = -1;
  }
  stack<int> S;
  dist[root] = 0;
  S.push(root);
  while(S.size()){
    int p = S.top(); S.pop();
    for(int to : g[p]){
      CHMAX(dist[to], dist[p]+1);
      if(--indeg[to]==0){
        S.push(to);
      }
    }
  }
  REP(i,n)for(int to : g[i]){
    if(dist[to] == dist[i]+1){
      par[to] = i;
    }
  }
  REP(i,n)printf("%d\n",par[i]+1);
  return 0;
}


Measured memory_bytes: 8064
#include<bits/stdc++.h>
#define MOD 1000000007
#define EPS (1e-10)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

bool is_prime[999984];
int prime[100000];
int main() {
	memset(is_prime, 1, sizeof(is_prime));
	int c = 0;
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i <= 999983; i++) {
		if (is_prime[i]) {
			prime[c++] = i;
			for (int j = i * 2; j <= 999983; j += i)is_prime[j] = false;
		}
	}
	int n;
	while (scanf("%d", &n), n) {
		int sum = 0;
		rep(i, n) {
			int p, m; scanf("%d%d", &p, &m);
			int a = upper_bound(prime, prime + c, p + m) - prime - 1;
			int b = lower_bound(prime, prime + c, p - m) - prime - 1;
			sum += a - b - 1;
		}
		printf("%d\n", sum);
	}
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    a[0] = 0;
    for(int i=1; i<n; i++){
        cin>>a[i];
    }
    sort(ALL(a));
    vector<int> ans(n+1);
    ans[0]= 0;
    int sum=0;
    for(int i=1;i<=n; i++){
        for (int j=sum; j<=n; j++){
            if(a[j+1]!=i){
                ans[i]=j-sum;
                sum=j;
                break;
            }
        }
    }
    rep(i,n){
        cout << ans[i+1] << endl;
    }
    return 0;
}

Measured memory_bytes: 4816
// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include<unordered_map>
#include <stack>
#include <random>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mapa make_pair
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

template<typename T>
void vdeb(std::vector<T> &da) {
    for (int i = 0;i < da.size();i++) {
        if (i == da.size() - 1) std::cout << da[i];
        else std::cout << da[i] << ' ';
    }
    std::cout << std::endl;
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
    for (int i = 0;i < da.size();i++) vdeb(da[i]);
    std::cout << std::endl;
}

using namespace std;

constexpr int MAX_N = 2500;

int main(){
    int n,m; cin >> n >> m;
    ll s; cin >> s;
    vector<vector<Pll>> da(MAX_N*n, vector<Pll>(0));
    rip(i,m,0){
        int u,v,a,b; cin >> u >> v >> a >> b;
        --u;--v;
        rip(j,MAX_N-a,0){
            da[u*MAX_N+j+a].push_back(mapa(v*MAX_N+j,b));
            da[v*MAX_N+j+a].push_back(mapa(u*MAX_N+j,b));
        }
    }
    rip(i,n,0){
        int c,d; cin >> c >>d;
        rip(j,MAX_N,0){
            da[i*MAX_N+j].push_back(mapa(MAX_N*i+min(2499, j+c), d));
        }
    }
    MinHeap<Pll> pq;
    vector<ll> ju(MAX_N*n,-1);
    // vdeb(da);
    pq.push({0, min(2499LL, s)});
    while(!pq.empty()){
        Pll now = pq.top();pq.pop();
        if(ju[now.second] != -1) continue;
        ju[now.second] = now.first;
        rip(i, da[now.second].size(),0){
            pq.push(mapa(now.first + da[now.second][i].second, da[now.second][i].first));
        }
    }
    rip(i,n,1){
        ll ans = LLONG_MAX/2;
        rip(j, MAX_N, 0){
            chmin(ans, ju[i*MAX_N+j]);
        }
        printf("%lld\n", ans);
    }
}

Measured memory_bytes: 26288
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");

		int a = Integer.parseInt(str[0]);
		int b = Integer.parseInt(str[1]);
		int c = Integer.parseInt(str[2]);

		if (a > b) {
			if (c < a && c > b) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		} else {
			if (c < b && c > a) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}
	}
}


Measured memory_bytes: 21204
import numpy as np
A= np.array([list(map(int,input().split())) for I in range (3)])

for I in range (3):
    j,k,l = A[1]-A[0]
    if not (j==k and k==l):
        print ( "No")
        quit()
    j,k,l = A[2]-A[0]
    if not (j==k and k==l):
        print ( "No")
        quit()
print("Yes")


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

int main(){
	int d,n,ans;
	cin>>d>>n;
	if(n==100)n=101;
	if(d==0){
		ans=n;
	}else if(d==1){
		ans=n*100;
	}else if(d==2){
		ans=n*10000;
	}
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 256
// Author : SAGORIKA DAS
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define CLEAR(a) memset(a,0,sizeof a)
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define fr freopen("input.txt", "r", stdin);
#define fw freopen("output.txt", "w", stdout);
#define debug(x) cerr << "#" << x <<"\n";
typedef long long LL;
typedef pair<int,int> pii;
const int MOD = 1e9 + 7;
const int MAX = 1e5 + 5;


int main() {
   // fr;fw;
    string s;
    cin >> s;
    int n = 0, e = 0, w = 0, st = 0;
    REP(i,s.size()){
    	if(s[i] == 'N') n++;
    	else if(s[i] == 'S') st++;
    	else if(s[i] == 'W') w++;
    	else e++;
    }

    if((n > 0 && st == 0) || (n == 0 && st > 0) || (w == 0 && e > 0) || (e == 0 && w > 0)){
    	cout <<"No";
    }
    else cout <<"Yes";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define MAX 300004

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    
    int n,k;
    cin>>n>>k;
    if( k <= (n+1)/2) cout<<"YES";
    else cout<<"NO";
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include<cmath>
#include <functional>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-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(){
  int N;
  cin >> N;
  vector<int> A(N);
  map<int,int> mp_A;
  map<int,int> cnt_A;
  for(int i=0; i<N; i++){
    cin >> A[i];
    mp_A[A[i]] = i+1;
    cnt_A[A[i]]++;
  }
  vector<int> B(N);
  map<int,int> mp_B;
  for(int i=0; i<N; i++){
    cin >> B[i];
    mp_B[B[i]]++;
  }
  set<int> pos;
  for(int i=0; i<N; i++) pos.emplace(i);
  vector<int> ans(N);
  queue<int> rem;
  bool can = true;
  priority_queue<P> que;
  for(auto m: mp_B){
    for(int j=0; j<m.second; j++){
      if(cnt_A[m.first]){
        que.emplace(cnt_A[m.first]+m.second,m.first);
      }else{
        que.emplace(0,m.first);
      }
    }
  }
  while(que.size()){
    int now = que.top().second;
    que.pop();
    auto itr = pos.lower_bound(mp_A[now]);
    if(itr == pos.end()){
      if(A[*pos.begin()] == now){
        can = false;
        break;
      }
      ans[*pos.begin()] = now;
      pos.erase(*pos.begin());
    }else{
      if(A[*itr] == now){
        can = false;
      }
      ans[*itr] = now;
      pos.erase(*itr);
    }
  }
  if(can){
    cout << "Yes\n";
    for(int i=0; i<N; i++){
      cout << ans[i] << " \n"[i+1==N];
    }
  }else{
    cout << "No\n";
  }
  return 0;
}


Measured memory_bytes: 45176
lst = [[v for v in map(int, input().split())] for _ in range(3)]
cnt = int(input())
for _ in range(cnt):
    v = int(input())
    for x in range(3):
        for y in range(3):
            if lst[x][y] == v:
                lst[x][y] = '*'
def bingo():
    for _ in range(3):
        if lst[_][0] == lst[_][1] == lst[_][2]:
            return print('Yes')
        if lst[0][_] == lst[1][_] == lst[2][_]:
            return print('Yes')
    if lst[0][0] == lst[1][1] == lst[2][2]:
        return print('Yes')
    if lst[0][2] == lst[1][1] == lst[2][0]:
        return print('Yes')
    else:
        return print('No')

bingo()


Measured memory_bytes: 3064
#include <stdio.h>
#include <math.h>

int a[200000];

int main(void) {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i ++) {
		scanf("%d", &a[i]);
	}
	int diffmax = a[1] - a[0];
	int min = a[0] < a[1] ? a[0] : a[1];
	for (int i = 2; i < n; i ++) {
		if (diffmax < a[i] - min) {
			diffmax = a[i] - min;
		}
		if (a[i] < min) {
			min = a[i];
		}
	}
	printf("%d\n", diffmax);
	return 0;
}

Measured memory_bytes: 1804
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        if(s == "E869120") ans++;
    }
    cout << ans << "\n";
    return 0;
}


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

int main() {
  int n,a,b,c,d; cin>>n>>a>>b>>c>>d;
  string s; cin>>s;
  string s_=s.substr(a-1,max(c,d)-a);
  
  bool bo=true,t=false;
  rep(i,s_.size()-1){
    if(c<=i&&i<=b){continue;}
    if(s_[i]==s_[i+1] && s_[i]=='#'){bo=false; break;}
  }
  
  if(d<c){
    string s__=s.substr(b-2,d-b+3);

    rep(i,s__.size()-2){
      if(s__[i]==s__[i+1] && s__[i]==s__[i+2] && s__[i]=='.'){t=true; break;}
    }
  }
  
  if(!bo){cout<<"No";}
  else if(c>d && !t){cout<<"No";}
  else{cout<<"Yes";}
}
      

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

int main() {
    int n, m;
    scanf("%d %d", &n, &m);

    int r = 2;
    for (int i = 1; i < m; i++) {
        r *= 2;
    }
    cout << 100 * r * (n - m) + 1900 * r * m << endl;
}

Measured memory_bytes: 3728
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

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


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

typedef long long ll;
ll const inf = 1e18;

struct Graph{
    map<int,vector<pair<int,ll>>> mp;
    vector<ll> x;
    vector<bool> check;

    Graph(int n) : x(n), check(n, false){}

    void insert(int a, int b, ll c){
        mp[a].push_back(make_pair(b, c));
    }

    bool dfs(int k){
        bool ret = true;
        check[k] = true;
        for(auto i : mp[k]){
            if(check[i.first]){
                if(x[i.first] != x[k] + i.second){
                    ret = false;
                    break;
                }
            }else{
                x[i.first] = x[k] + i.second;
                ret &= dfs(i.first);
            }
        }
        return ret;
    }

    string solve(){
        string ans = "Yes";
        for(auto itr = mp.begin(); itr != mp.end(); itr++){
            if(check[itr->first]){
                continue;
            }
            if(!dfs(itr->first)){
                ans = "No";
                break;
            }
        }
        return ans;
    }
};

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

    int n, m;
    cin >> n >> m;

    Graph g(n);

    for(int i=0; i<m; i++){
        int a, b;
        ll c;
        cin >> a >> b >> c;
        g.insert(a-1, b-1, c);
        g.insert(b-1, a-1, -c);
    }

    cout << g.solve() << endl;    

    return 0;
}

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

int main() {
	long N, A, B;
	cin >> N >> A >> B;
	long count = N / (A + B) * A;
	if (N % (A + B) < A) cout << count + N % (A + B) << endl;
	else cout << count + A << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 998244353;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
int add(int a, int b) {
	a += b;
	if (a >= mod) {
		return a - mod;
	}
	return a;
}
void add_self(int& a, int b) {
	a = add(a, b);
}
int mult(int a, int b) {
	return 1ll * a * b % mod;
}
int bin_pow(int a, int b) {
	if (b == 0) {
		return 1;
	}
	if (b % 2 == 0) {
		return bin_pow(mult(a, a), b / 2);
	}
	return mult(a, bin_pow(a, b - 1));
}
int inv(int a) {
	return bin_pow(a, mod - 2);
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	vector<int> a(5);
	for (int i = 0; i < 5; ++i) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	int answer = inf;
	do {
		int now = 0;
		for (int i = 0; i < 5; ++i) {
			while (now % 10 != 0) {
				++now;
			}
			now += a[i];
		}
		answer = min(answer, now);
	} while (next_permutation(a.begin(), a.end()));
	cout << answer << '\n';
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) x.begin(),x.end()
#define pll  pair <long long,long long>
#define ss second
#define ff first
#define inf 9223372036854775807
#define mod 1000000007
#define ld long double
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define bug(x) cout << #x <<": " << x << '\n';
const ll N=100001 ;
ll n,m ;
vector<ll>adj[N] ;
ll dp[N] ;
void dfs(ll node,ll parent)
{
     dp[node]=1 ;
    for(ll child:adj[node])
    {
        if(child==parent) continue ;

        dfs(child,node) ;

        dp[node]=(dp[node]*(dp[child]+1))%m ;
    }
}
void cal(ll node,ll parent,ll ct)
{
   dp[node]=(ct+1)%m ;

   //cout<<node<<" "<<parent<<endl ;
   vector<ll>temp,pre,suf ;
   for(ll child:adj[node])
   {
       if(child==parent) continue ;


       dp[node]=(dp[node]*(dp[child]+1))%m ;
       temp.pb(child) ;
      // cout<<child<<endl ;
   }
   //cout<<"sdfs" ;
   if(temp.size()>0)
   {
       ll n=temp.size() ;
       pre.resize(n) ;
       pre[0]=(dp[temp[0]]+1)%m ;
       for(ll i=1;i<n;i++)
       {
           pre[i]=(pre[i-1]*(dp[temp[i]]+1))%m ;
       }
       suf.resize(n) ;
       suf[n-1]=(dp[temp[n-1]]+1)%m ;
       for(ll i=n-2;i>=0;i--)
       {
           suf[i]=(suf[i+1]*(dp[temp[i]]+1))%m ;
       }
      // cout<<temp.size()<<endl ;

       for(ll k=0;k<temp.size();k++)
       {
           ll child=temp[k] ;

           ll ops=ct+1 ;
           if(k-1>=0) ops=(ops*pre[k-1])%m ;
           if(k+1<n) ops=(ops*suf[k+1])%m ;

           cal(child,node,ops) ;


       }
   }


}
int main()
{
    fast ;
    cin>>n>>m ;
    for(ll i=0;i<n-1;i++)
    {
        ll x,y ; cin>>x>>y ;
        adj[x].pb(y) ;
        adj[y].pb(x) ;
    }

    dfs(1,-1) ;

    cal(1,-1,0) ;
    for(ll i=1;i<=n;i++)
        cout<<dp[i]<<endl ;


}



Measured memory_bytes: 30412
//Jai Bhole Ki
#include <bits/stdc++.h>
using namespace std;
#define fast int fvariable = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
#define ll long long
#define LL unsigned ll
#define pb push_back
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";
#define debug cout<<"debugged\n";
#define minval -2e9
#define maxval 2e9
long double PI =3.14159265358979323846;
 
const ll M=1e9+7;
const ll inf=1e18;
const ll ms=2e5+5;
fast;
ll sum;
ll a,n,m;
void solve()
{
    cin>>n>>m;
    while(m--)
    {
        cin>>a;
        sum+=a;
    }
    if(sum>n)
        cout<<-1<<endl;
    else
        cout<<n-sum<<endl;
}
int main()
{
 // freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    //int t;cin>>t;while(t--)
    {
        solve();
    }
    return 0;
}

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

int main() {
  int n; cin >> n;
  unordered_map<string, int> mp;
    rep(i,n) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    mp[s]++;
  }
  ll ans = 0;
  for (auto& p : mp) {
    int s = p.second;
    ans += (ll)s*(s-1)/2;
  }
  cout << ans << endl;
  return 0;
}


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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define SORTG(v) sort(v.begin(),v.end(),greater<>())
#define SORT(v) sort(v.begin(),v.end())
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/3

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<string> Vs;

template<class T> void chmax(T& a, T b) {if(a<b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a>b){a=b;}}
void YesNo(int a){cout<<((a)?"Yes":"No")<<endl;}
void YESNO(int a){cout<<((a)?"YES":"NO")<<endl;}
void AorB(int a,string b,string c){cout<<((a)?b:c)<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
void start(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);}

signed main(){start();
    int r,d,x;
    cin>>r>>d>>x;
    Vi ans(11);
    ans[0]=x;
    REP(i,0,10){
        ans[i+1]=ans[i]*r-d;
    }
    REP(i,1,11) cout<<ans[i]<<endl;
}


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

typedef long long ll;

const int N = 100000;
const int mo = 1e9 + 7;

int n;
int a[N + 5], s[N + 5];
int fac[N + 5], inv[N + 5];

int fpm(int x, int y) {
    int res = 1;
    for(; y > 0; y >>= 1) {
        if(y & 1)
            res = (ll) res * x % mo;
        x = (ll) x * x % mo;
    }
    return res;
}

void init() {
    fac[0] = 1;
    for(int i = 1; i <= N; ++i) fac[i] = (ll) fac[i-1] * i % mo;
    inv[N] = fpm(fac[N], mo - 2);
    for(int i = N; i >= 1; --i) inv[i-1] = (ll) inv[i] * i % mo;
}

int ans = 0;
int main() {
    init();
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i) {
        scanf("%d", a + i);
        s[i-1] = (s[i-1] + a[i]) % mo;
        s[n-i] = (s[n-i] + a[i]) % mo;
        ans = (ans + 1ll * fac[n] * a[i]) % mo;
    }
    for(int k = n - 1; k >= 1; --k) {
        s[k] = (s[k] + s[k+1]) % mo;
        ans = (ans + 1ll * s[k] * fac[n] % mo * inv[k + 1] % mo * fac[k]) % mo;
    }
    printf("%d\n", ans);
    return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<long long> a(N*3);
  for(int i=0; i<N*3; i++){
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  long long ans=0;
  for(int i=0; i<N; i++){
    ans+=a.at(i*2+1);
  }
  cout << ans << endl;
}


Measured memory_bytes: 2560
n=int(input())
a=[int(i) for i in input().split()]
s=[0]
for i in range(n):
    s.append(s[-1]+a[i])
d={}
for i in s:
    if i in d:
        d[i]+=1
    else:
        d[i]=1
ans=chk=0
for i in d:
    ans+=(d[i]*(d[i]-1))//2
print(ans)

Measured memory_bytes: 111688
#include <bits/stdc++.h>
using namespace std;
int main(void){
   long n,k; cin >> n >> k;
   vector<long> v(n);
   for(int i=0;i<n;i++)cin >> v[i];
   for(int i=0;i<n-k;i++){
       if(v[i] < v[i+k])cout << "Yes" << endl;
       else cout << "No" << endl;
   }
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> void amax(T &x, T y) { x = max(x, y); }
template <typename T> void amin(T &x, T y) { x = min(x, y); }
template <typename T> T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

template <typename T, typename U>
vector<U> make_vector(T&& n, U&& val) {
  return vector<U>(forward<T>(n), forward<U>(val));
}
template <typename T, typename... Args>
decltype(auto) make_vector(T&& n, Args&&... args) {
  return vector<decltype(make_vector(forward<Args>(args)...))>(forward<T>(n), make_vector(forward<Args>(args)...));
}

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

void solve() {
  int n, m;
  cin >> n >> m;
  vector<vi32> g(n);
  vi32 deg(n);
  rep(i, m) {
    int u, v;
    cin >> u >> v;
    deg[v] += 1;
    g[u].emplace_back(v);
  }
  vi32 history;
  rep(i, n) if (deg[i] == 0) history.push_back(i);
  int ptr = 0;
  while (ptr < sz(history)) {
    int u = history[ptr++];
    for (int v : g[u]) {
      deg[v] -= 1;
      if (deg[v] == 0) history.push_back(v);
    }
  }
  if (ptr == n) {
    rep(i, n) cout << history[i] << '\n';
  } else {
    cout << "No" << endl;
  }
}



Measured memory_bytes: 3756
#include <iostream>

using namespace std;

int button(int &A, int &B)
{
	if (A < B) {
		return B--;
	}
	else {
		return A--;
	}
}

int main()
{
	int A, B;
	cin >> A >> B;

	int ans = 0;
	ans += button(A, B);
	ans += button(A, B);
	cout << ans << endl;
}


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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n;
  cin >> n;
  vector<int> a(n + 1);
  REP(i, n + 1) cin >> a[i];
  vector<int> b(n);
  REP(i, n) cin >> b[i];
  ll ans = 0;
  REP(i, n) {
    ll t = min(a[i], b[i]);
    ans += t;
    a[i] -= t;
    ll s = min(1ll * a[i + 1], b[i] - t);
    ans += s;
    a[i + 1] -= s;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <stack> 
#include <sstream>
#include <set>
typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
using namespace std;
//start
const int limit = 2e5 + 1;
int k;
vector<int> g[limit];
bool vis[limit];

void dfs(int s,int k){
    if(k >= 2) return;

    for(auto it:g[s]){
        if(!vis[it]){
            vis[it] = true;
            dfs(it, k+1);
        } 
    }
}


int main(){
    int x,a,b,c,d;
    cin >> x;

    d = x%10;
    x/= 10;
    c = x%10;
    x/= 10;
    b = x%10;
    x/=10;
    a = x;
    int k[4];
    k[1] = b;
    k[2] = c;
    k[3] = d;
    int ans = a;
    
    string s[10];
    for(int bit = 0; bit < (1 << 3); ++bit){
        for(int i =0 ; i<3;i++){
            if(bit & (1<<i)){
                ans +=k[i+1];
                s[bit] += '+';
            }else{
                ans -=k[i+1];
                s[bit] += '-';
            }
        }
            if(ans == 7){
            cout << a << s[bit][0] << b << s[bit][1] << c << s[bit][2] << d << "=7" <<endl;
            return 0;
            }

            ans = a;
    }

}


Measured memory_bytes: 4992
import java.util.Scanner;

/**
 * https://abc056.contest.atcoder.jp/tasks/abc056_a
 */
public class Main {
	 
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		sc.close();
		
		String ans;
		ans = a.equals(b) ? "H" : "D";
	
		System.out.println(ans);
 
	}
 
}

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

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

    vector<vector<int>> X(N, vector<int>(D));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < D; j++) {
            cin >> X[i][j];
        }
    }

    int mid = N / 2;
    int ans = 0;
    double k;
    if (N % 2 != 0) mid++;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            k = 0;
            for (int d = 0; d < D; d++) {
                k += (X[i][d] - X[j][d]) * (X[i][d] - X[j][d]);
            }
            k = sqrt(k);
            if (k == (int)k) ans++;
        }
    }
    cout << ans << endl;
}

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

using namespace std;

int main(void){
  int n,m,max,i,x;
  vector<int>time;

  while(cin >> n >> m){
    time.push_back(0);
    if(n==0 && m==0)break;
    for(i=0;i<n+m;i++){
      cin >> x;
      time.push_back(x);
    }
    sort(time.begin(),time.end());
    max=-1;
    for(i=0;i<n+m;i++){
      max= (max<time[i+1]-time[i])?time[i+1]-time[i]:max;
}
    cout << max << endl;
    time.clear();
  }

  return 0;
}

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

using namespace std;

const int INF = 1e9+5;

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

    int n,k;
    cin>>n>>k;
    vector<int>h(n),dp(n,INF);
    for(int i=0; i<n; i++)cin>>h[i];
    dp[0]=0;
    for(int i=0; i<n; i++){
        for(int step=1; step<=k; step++){
            if(i+step<n){
                dp[i+step]=min(dp[i+step],dp[i]+abs(h[i]-h[i+step]));
            }
        }
    }
    cout<<dp[n-1]<<endl;

    return 0;
}

Measured memory_bytes: 4000
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

#define x first
#define y second


int main() {
    int n;
    while(cin>>n){
        if(n==0)break;
        
        vi taro;
        rep(i,n){
            int a;
            cin>>a;
            taro.pb(a);
        }
        
        vi hanako;
        for(int i=1;i<=2*n;i++){
            bool flag=true;
            rep(j,n){
                if(taro[j]==i)flag=false;
            }
            if(flag)hanako.pb(i);
        }
        
        sort(all(taro));
        sort(all(hanako));
        reverse(all(taro));
        reverse(all(hanako));
        
        int fie=-1;
        bool flag;
        bool pass=false;
        while(1){
            flag=true;
            for(int i=n-1;i>=0;i--){
                if( taro[i]>fie ){
                    fie=taro[i];
                    taro[i]=-1;
                    flag=false;
                    pass=false;
                    break;
                }
            }
            if(flag){
                if(pass)break;
                fie=-1;
                pass=true;
            }
            
            flag=true;
            for(int i=n-1;i>=0;i--){
                if( hanako[i]>fie ){
                    fie=hanako[i];
                    hanako[i]=-1;
                    flag=false;
                    pass=false;
                    break;
                }
            }
            if(flag){
                if(pass)break;
                fie=-1;
                pass=true;
            }
        }
        sort(all(taro));
        sort(all(hanako));
        reverse(all(taro));
        reverse(all(hanako));
        for(int i=n-1;i>=0;i--){
            if(taro.back()==-1)taro.pop_back();
            else break;
        }
        for(int i=n-1;i>=0;i--){
            if(hanako.back()==-1)hanako.pop_back();
            else break;
        }
        cout<<hanako.size()<<endl;
        cout<<taro.size()<<endl;
        
    }
    return 0;
}

        
        

Measured memory_bytes: 1216
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int M = input.nextInt();
		int sum=0;
		
		for(int i=0;i<M;i++) {
			sum+=input.nextInt();
		}
		if (sum > N) {
			System.out.println("-1");
		} else {
			System.out.println(N - sum);
		}
	}
}


Measured memory_bytes: 46240
from itertools import permutations
from math import acos, sin, cos, pi
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
    N = int(readline())
    R = [int(readline()) for i in range(N)]
    R.sort(reverse=1)

    ans = 0
    for l in range(3, N+1):
        for rs in permutations(R[:l]):
            C = [rs[i]*rs[i-l+1] for i in range(l)]
            if C.index(min(C)) != 0:
                continue

            left = 0; right = pi+1e-9
            while right - left > 1e-9:
                mid = (left + right) / 2
                s = mid
                cv = cos(mid)
                for i in range(1, l):
                    s += acos(C[0]*cv/C[i])
                if s > 2*pi:
                    right = mid
                else:
                    left = mid
            if left < 1e-9:
                continue
            res = C[0]*sin(left)
            cv = cos(left)
            v2 = (C[0]*cos(left))**2
            for i in range(1, l):
                res += (C[i]**2 - v2)**.5
            ans = max(ans, res)
    ans /= 2
    write("%.16f\n" % ans)
solve()


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

int main()
{
    ll n;
    cin >> n;
    vector<string> s(n);
    rep(i, n) cin >> s[i];
    rep(i, n) sort(s[i].begin(), s[i].end());
    map<string, ll> mp;
    ll ans = 0;
    for (ll i = 0; i < n; i++)
    {
        mp[s[i]] += 1;
    }
    for (auto i : mp)
    {
        ans += (i.second - 1) * i.second / 2;
    }

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


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

int main() {
	int A,B,x,y,n;
	cin >> A >> B;
	for (n = 0; n < 10000; ++n) {
		int x = n * 8 / 100;
		int y = n * 10 / 100;
		if (A == x && B == y) {
			cout << n << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
	int n;
	cin >> n;
	string s[n];
	for(int i=0;i<n;i++) cin >> s[i];
	int a=0,b=0,ab=0;
	for(int i=0;i<n;i++){
		if(s[i][0]=='B' && s[i][s[i].length()-1]=='A') ab++;
		else if(s[i][0]=='B') b++;
		else if(s[i][s[i].length()-1]=='A') a++;
	}
	int ans=0;
	if(a==0 && b==0) ans=ab>0?ab-1:0;
	else ans=min(a+ab,b+ab);
	for(int i=0;i<n;i++){
		for(int j=0;j<s[i].length()-1;j++)
			if(s[i][j]=='A' && s[i][j+1]=='B') ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 768
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int T = sc.nextInt();
        int A = sc.nextInt();
        int[] hArr = new int[N];
        for (int i = 0; i < hArr.length; i++) {
            hArr[i] = sc.nextInt();
        }
        sc.close();

        double ht;               // 対象地の気温
        double dif = 0;          // 対象地の目標気温差
        double min = 100000000;  // 候補地の目標気温差
        int hn  = 0;             // 候補地の番号

        // 目標気温差が最小の候補地を選定
        for (int i = 0; i < hArr.length; i++) {

            ht = T - (hArr[i] * 0.006);
            dif = Math.abs(A - ht);

            if(min > dif) {
                hn = i;
                min = dif;
            };
        }
        System.out.println(hn + 1);
    }
}

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

#define ll long long int
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define INF 0x3f3f3f3f
#define all(x) x.begin(),x.end()
#define show(x) cerr<<#x<<" : "<<x<<'\n';
#define yogeshk972() cerr<<"\nTime Taken : "<<(float)(clock()-time_p)/CLOCKS_PER_SEC<<"\n";
clock_t time_p=clock();

using namespace std;
const int mod=998244353;
string grid[100];
int N,M;

class QItem { 
public: 
    int row; 
    int col; 
    int dist; 
    QItem(int x, int y, int w) 
        : row(x), col(y), dist(w) 
    { 
    } 
}; 
  
int minDistance(int i,int j,int k,int l ) 
{ 
    QItem source(i, j, 0); 
  
    // To keep track of visited QItems. Marking 
    // blocked cells as visited. 
    bool visited[N][M]; 
    for (int i = 0; i < N; i++) { 
        for (int j = 0; j < M; j++) 
        { 
            if (grid[i][j] == '#') 
                visited[i][j] = true; 
            else
                visited[i][j] = false; 
        } 
    } 
  
    // applying BFS on matrix cells starting from source 
    queue<QItem> q; 
    q.push(source); 
    visited[source.row][source.col] = true; 
    while (!q.empty()) { 
        QItem p = q.front(); 
        q.pop(); 
  
        // Destination found; 
        #define mp make_pair
        if ( mp(p.row,p.col) == mp(k,l)  ) 
            return p.dist; 
  
        // moving up 
        if (p.row - 1 >= 0 && 
            visited[p.row - 1][p.col] == false) { 
            q.push(QItem(p.row - 1, p.col, p.dist + 1)); 
            visited[p.row - 1][p.col] = true; 
        } 
  
        // moving down 
        if (p.row + 1 < N && 
            visited[p.row + 1][p.col] == false) { 
            q.push(QItem(p.row + 1, p.col, p.dist + 1)); 
            visited[p.row + 1][p.col] = true; 
        } 
  
        // moving left 
        if (p.col - 1 >= 0 && 
            visited[p.row][p.col - 1] == false) { 
            q.push(QItem(p.row, p.col - 1, p.dist + 1)); 
            visited[p.row][p.col - 1] = true; 
        } 
  
         // moving right 
        if (p.col + 1 < M && 
            visited[p.row][p.col + 1] == false) { 
            q.push(QItem(p.row, p.col + 1, p.dist + 1)); 
            visited[p.row][p.col + 1] = true; 
        } 
    } 
    return -1; 
} 
  

int main(){
	ios_base::sync_with_stdio(0);	cin.tie(0);
	cin>>N>>M;
	
	for(int i=0;i<N;i++){
		cin>>grid[i];
	}
	
	int res=0;
	
	for(int i=0;i<N;i++){
		for(int j=0;j<M;j++){
			for(int k=0;k<N;k++){
				for(int l=0;l<M;l++){
					if( grid[i][j]=='.' && grid[i][j]== '.' )
						res=max(minDistance(i,j,k,l),res);
				}
			}
		}
	}
	
	cout<<res;
	
	
    yogeshk972();
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

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

using namespace std;

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

    ll N;
    cin >> N;
    vector<ll> A(N);
    Rep (i, N) {
        cin >> A[i];
    }

    multiset<ll> color;
    Rep (i, N) {
        auto itr = color.upper_bound(-A[i]);
        // cout << *itr << "\n";
        if (itr != color.end()) {
            color.erase(itr);
        }
        // color.erase(*itr);
        color.insert(-A[i]);
        // for (auto itr = color.begin(); itr != color.end(); itr++) {
        //     cout << -*itr << " ";
        // }
        // cout << "\n";
    }
    
    // for (auto itr = color.begin(); itr != color.end(); itr++) {
    //     cout << -*itr << " ";
    // }
    // cout << "\n";

    cout << color.size() << "\n";
}


Measured memory_bytes: 5760
n = int(input())
works = [tuple(int(v) for v in input().split()) for _ in range(n)]

works = sorted(works, key=lambda w: w[1])

sum_a = 0
workable = True
for a, b in works:
    sum_a += a
    if sum_a > b:
        print('No')
        workable = False
        break

if workable:
    print('Yes')

Measured memory_bytes: 34424
import queue

n, m = map(int, input().split())
table = [[] for i in range(n+1)]
ans = [(1e9, 0) for i in range(n+1)]
seen = [False for _ in range(n+1)]
seen[1] = True

for i in range(m):
    a, b = map(int, input().split())
    # print(table[min(a, b)])
    # table[min(a, b)].append(max(a, b))
    table[a].append(b)
    table[b].append(a)

q = queue.Queue()

q.put((1, table[1]))
while(not q.empty()):
    element = q.get()
    for i in element[1]:
        if seen[i]:
            continue
        ans[i] = element[0]
        seen[i] = True
        q.put((i, table[i]))


if 1e9 in ans[2:]:
    print("No")
else:
    print("Yes")
    for i in ans[2:]:
        print(i)

Measured memory_bytes: 39048
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;

int main(){
  int N;
  cin>>N;
  map<int,int> m;
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    if(m.count(a)==0){
      m[a]=1;
    }else{
      m[a]++;
    }
  }

  int ans=0;
  for(auto x : m){
    if(x.second>x.first){
      ans+=x.second-x.first;
    }else if(x.second<x.first){
      ans+=x.second;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 4736
import sys
input=sys.stdin.readline

w,a,b = map(int, input().split())
if (a <= b and b <= a+w) or (a <= b+w and b+w <= a+w):
    print(0)
elif a+w < b:
    print(b-(a+w))
else:
    print(a-(b+w))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A.at(i);
  }
  int counter = 0;
  bool divide = true;
  
  while(divide){
    for (int i = 0; i < N; i++){
      if(A.at(i)%2==1){
        divide = false;
        break;         
      }
      A.at(i) /= 2;
    }
    if(divide){
      counter+=1;
    }
  }
  
  cout << counter << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

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

//改造
typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void solve() {
        Int N;
        cin >> N;
        vector<Int> A(N);
        map<Int, Int> mp;
        Int sum = 0;
        mp[sum]++;

        for (int i = 0; i < N; ++i) {
            cin >> A[i];
            sum += A[i];
            mp[sum]++;
        }

        Int ans = 0;
        for (auto e : mp) {
            ans += e.second * (e.second - 1) / 2;
        }
        cout << ans << endl;

    }
};


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

    Solve().solve();


    return 0;
}


Measured memory_bytes: 14336
n, l = map(int, input().split())
true_sum = 0
false_sum = 0

for i in range(n):
    true_sum += l+i

for j in range(n):
    tmp = 0
    for k in range(n):
        if k == j:
            continue
        else:
            tmp += l+k
    if abs(tmp - true_sum) < abs(false_sum - true_sum):
        false_sum = tmp

print(false_sum)

Measured memory_bytes: 3188
n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(1, n - 1):
    if p[i - 1] > p[i] > p[i + 1] or p[i - 1] < p[i] < p[i + 1]:
        ans += 1
print(ans)


Measured memory_bytes: 2940