akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports)]
#![allow(dead_code)]
use std::io::prelude::*;
use std::cmp::{max, min};

const MOD: i64 = 1e9 as i64 + 7; 

fn main(){
    let k: i32 = read();
    let x: i32 = read();
    let mut a: Vec<String> = vec![];
    for i in x - k + 1..x + k{
        a.push(format!("{}", i));
    }
    let ans = a.join(" ");
    println!("{}", ans);
}

fn read<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


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



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

    string s;
    cin>>s;
    int n = s.size();
    for(int i=0;i<n;i+=2){
        if(s[i] == 'L'){
            cout << "No" << endl;
            return 0;
        }
    }
    for(int i=1;i<n;i+=2){
        if(s[i] == 'R'){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define watch(x) cout << #x << " is " << x << endl;
#define print(a, l, r) \
    for (int i = l; i < r; i++) cout << a[i] << (i == (r - 1) ? endl : " ");
const long long M = 1000000007;

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

    int h, w, n;
    cin >> h >> w >> n;

    int mx = max(h, w);
    int ans = (n + mx - 1) / mx;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
s=list(map(int,input()))
bw=0 #0101との差異
for i in range(len(s)):
	if (i%2==0 and s[i]==1) or (i%2==1 and s[i]==0):
		bw+=1
wb=0
for i in range(len(s)):
	if (i%2==0 and s[i]==0) or (i%2==1 and s[i]==1):
		wb+=1
print(min(bw,wb))

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

const int N = 1e5 + 100;
int vt[N], up[22][N];

void solve() {
    int n, L, q;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> vt[i];
    }

    cin >> L;

    int rh = 1;
    for (int l = 1; l <= n; l++) {
        while (rh <= n && vt[rh] - vt[l] <= L)
            rh++;
        int r = rh - 1;
        up[0][l] = r;
    }

    for (int lvl = 1; lvl < 22; lvl++) {
        for (int v = 1; v <= n; v++) {
            up[lvl][v] = up[lvl - 1][up[lvl - 1][v]];
        }
    }

    cin >> q;
    for (int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;
        if (l > r)
            swap(l, r);

        int ans = 0;
        for (int lvl = 21; lvl >= 0; lvl--)
            if (up[lvl][l] < r) {
                ans += (1 << lvl);
                l = up[lvl][l];
            }
            
        ans++;
        cout << ans << "\n";
    }
}

int main() {
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(20);
    solve();
    return 0;
}


Measured memory_bytes: 9856
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <sstream>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <vector <int>> vii;
typedef vector <long long> vll;
typedef vector <string> vs;
typedef vector <char> vc;
typedef set <int> si;
typedef set <string> ss;
typedef queue <int> qi;
typedef queue <long long> qll;
typedef queue <string> qs;
typedef queue <char> qc;
typedef struct board board;
typedef pair <int, int> pi;
typedef pair <long long, long long> pll;
typedef pair <int, pair<int, int>> pii;

#define eb emplace_back
#define ppb pop_back
#define clr(a) a.clear()
#define F first
#define S second
#define mkp make_pair

#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

#define left(x) x * 2
#define right(x) x * 2 + 1

#define meme(a, b, c) fill(a + 1, a + 1 + b, c)

#define max(a, b) (a > b ? a : b)
#define min(a, b) (a > b ? b : a)
#define abs(a) (a > 0? a : -(a))

#define move(s) s += "#"

#define fr(i, a, b) for (ll i = a; i <= b; ++ i)
#define rf(i, a, b) for (ll i = a; i >= b; -- i)

#define eprintf(...) fprintf(stderr, __VA_ARGS__);

void to_pray() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cerr << "Ready\n";
}

const int N = 4e6 + 10;
const int NN = 1e3 + 10;
const int NNN = 2e3 + 9;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll LLINF = 1e12 + 7;
const ll P = 53;
const int EPS = 1e-9 - 8;
const int vN = 2e4 + 10;
const int sz = (1 << 22) - 1;
const double PI = acos(-1);

int u[N];

int main () {
    to_pray();

    string s;
    cin >> s;
    
    int cnt = 0;
    
    for (auto to : s) {
    	++u[to];
    	if (u[to] == 2)
    		++cnt;
    }
    
    cout << (cnt == 2 ? "Yes" : "No");
    
    cout << '\n';
    return 0;
}

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

using namespace std;

int main()
{
    int N, K, O;
    cin >> N >> K;
    vector<long long> X(N);

    bool flag = true;
    O = N-1;
    for (int i = 0; i < N; i++)
    {
        cin >> X.at(i);
        if (flag && X.at(i) >= 0)
        {
            O = i;
            flag = false;
        }
    }

    long long min_dist = 10000000000, dist;
    for (int i = 0; i < K + 1; i++)
    {
        // 0以上をi個
        if (O - (K - i) < 0 || O + i - 1 > N - 1)
            continue;
        if (X.at(O + i - 1) < 0)
            dist = -X.at(O - K + i);
        else if (X.at(O - K + i) >= 0)
            dist = X.at(O + i - 1);
        else
        {
            dist = min(-2 * X.at(O - K + i) + X.at(O + i - 1), -X.at(O - K + i) + 2 * X.at(O + i - 1));
        }
        if (min_dist > dist)
            min_dist = dist;
    }
    cout << min_dist << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    int a[5];
    rep(i, 5) {
        cin >> a[i];
    }
    rep(i, 5) {
        if(a[i] == 0) cout << i + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3620
#include <stdio.h>

int main(){
	int a[4], b[4];
	while(scanf("%d %d %d %d\n%d %d %d %d\n", &a[0], &a[1], &a[2], &a[3], &b[0], &b[1], &b[2], &b[3])!=EOF){
		int hit = 0, blow = 0;
		for(int i = 0; i < 4; i++)
		for(int j = 0; j < 4; j++)
			if(a[i] == b[j])
				if(i == j) hit++; else blow++;
		printf("%d %d\n", hit, blow);
	}
	return 0;
}

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

#define ll long long
#define pll pair<ll,ll>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define vi vector<ll>
#define vvi vector<vi>
#define P_Q priority_queue<ll>
#define p_q priority_queue<ll,vi,greater<ll>>
#define loop(i,x,y,z) for(int i=x; i<=y; i+=z)
#define loopR(i,x,y,z) for(int i=x; i>=y; i-=z)
#define all(x) begin(x), end(x)
#define allR(x) rbegin(x), rend(x)
#define watch(x) cout<<(#x)<<" is "<<x<<'\n'
#define display(v,c) for(auto x:v) cout<<x<<c;
#define endl "\n"

vi v1,v2,v3;
ll dp[100005][5];

ll solve(ll n, ll ind){
	if(n<0) return 0;
	if(dp[n][ind]) return dp[n][ind];
	ll a,b,c;
	a = b = c = INT_MIN;
	if (ind==1) a = max(v1[n] + solve(n-1,2),v1[n] + solve(n-1,3));
	if (ind==2) b = max(v2[n] + solve(n-1,1),v2[n] + solve(n-1,3));
	if (ind==3) c = max(v3[n] + solve(n-1,1),v3[n] + solve(n-1,2));
	return dp[n][ind] = max(a,max(b,c));
}

int main(){
	IOS
	// do magic here
	ll n,a,b,c;
	cin>>n;
	loop(i,1,n,1){
		cin>>a>>b>>c;
		v1.push_back(a);
		v2.push_back(b);
		v3.push_back(c);
	}
	cout<<max(solve(n-1,1),max(solve(n-1,2),solve(n-1,3)));
	return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// DON'T USE THESE MACROS DURING ICPC PRACTICE
#define For(i,n) for (int i=0; i<n; i++)
#define FOR(i,a,b) for (int i=a; i<=b; i++)
#define Down(i,n) for (int i=n-1; i>=0; i--)
#define DOWN(i,a,b) for (int i=b; i>=a; i--)

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef complex<ld> pt;
typedef vector<pt> pol;
typedef vector<int> vi;

const char nl = '\n';
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll MOD = 1e9+7;
const ld EPS = 1e-10;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());



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

	int n;
	cin >> n;

	int adj[n][n];
	For(i,n) {
		For(j,n) {
			cin >> adj[i][j];
		}
	}

	ll dp[1<<n];
	memset(dp, 0, sizeof dp);
	dp[0] = 1;
	for (int s=1; s<=n; s++) {
		for (int bm=1; bm<1<<n; bm++) {
			if (__builtin_popcount(bm) == s) {
				for (int j=0; j<n; j++) {
					if ((bm&1<<j) && adj[s-1][j]) {
						dp[bm] += dp[bm^1<<j];
					}
				}
				dp[bm] %= MOD;
			}
		}
	}
	cout << dp[(1<<n)-1] << nl;

	return 0;
}


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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937_64 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());

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

    int N;
    cin >> N;

    vi len(2 * N);
    for (int i = 0; i < 2 * N; i++) {
        cin >> len[i];
    }

    sort(all(len));

    int ans = 0;
    for (int i = 0; i < len.size(); i += 2)
        ans += len[i];
    cout << ans << endl;

    return 0;
}



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

int main() {
  int num;
  int allSum = 0;
  int kekka = 0;
  int tmp = 0;
  
  cin >> num;
  
  vector<int> vec(num);
  for(int i = 0; i < num; i++){
    cin >> vec.at(i);
    allSum += vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  
  if(allSum % 10 == 0){
    kekka = 0;
    for(int i = 0; i < num; i++){
      if(vec.at(i) % 10 == 0){
      }else{
        kekka = allSum - vec.at(i);
        break;
      }
    }
  }else{
    kekka = allSum;
  }
  
  cout << kekka;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

#[derive(Clone, Default, Copy)]
struct Point {
    x: f64,
    y: f64,
}

impl Point {
    fn angle(&self) -> f64 {
        self.y.atan2(self.x) + std::f64::consts::PI
    }

    fn abs(&self) -> f64 {
        self.x.hypot(self.y)
    }
}

impl std::ops::Add for Point {
    type Output = Point;
    fn add(self, other: Point) -> Point {
        Point {
            x: self.x + other.x,
            y: self.y + other.y,
        }
    }
}

impl std::ops::Sub for Point {
    type Output = Point;
    fn sub(self, other: Point) -> Point {
        Point {
            x: self.x - other.x,
            y: self.y - other.y,
        }
    }
}

fn main() {
    let n = read::<usize>();
    let mut points = vec![];
    for _ in 0..n {
        let v = read_vec::<f64>();
        if v[0] == 0.0 && v[1] == 0.0 {
            continue;
        }
        points.push(Point { x: v[0], y: v[1] });
    }
    let n = points.len();
    let mut clone = points.clone();
    points.append(&mut clone);

    let mut points_angles = vec![];
    for (i, point) in points.into_iter().enumerate() {
        let mut angle = point.angle();
        if i >= n {
            angle += 2.0 * std::f64::consts::PI;
        }
        points_angles.push((angle, point));
    }
    points_angles.sort_by_key(|x| Total(x.0));

    let mut ans = 0.0;
    for i in 0..n {
        let mut sum = Point { x: 0.0, y: 0.0 };
        for j in i..i + n {
            sum = sum + points_angles[j].1;
            ans = max(Total(ans), Total(sum.abs())).0;
        }
    }
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
// #define STOPIT
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

void debug_impl() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
    #define debug(...)\
    do {\
        cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        cerr << std::noboolalpha;\
    } while (false)
#else
    #define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr>
istream& operator>> (istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr >
ostream& operator<< (ostream& os, Container const& v) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

const double PI  =3.141592653589793238463;

int main()
{
    double R;
    cin >> R;

    double res = R*2*PI;
    printf("%.10f\n", res);
    return 0;
}


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

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	long long X, Y; cin >> X >> Y;
	if (abs(X-Y) <= 1) {
		cout << "Brown" << '\n';
	} else {
		cout << "Alice" << '\n';
	}

	return 0;
}


Measured memory_bytes: 256
#include <cassert>
#include <iostream>
#include <functional>
#include <iomanip>
#include <set>
#include <unordered_map>
#include <queue>
#include <vector>
#include <deque>
#include <algorithm>
#include  <cstring>
#include <string>
#include <cmath> 
using namespace std;
typedef long long LL;
const int MAX = 3010;
const LL base = 1e9 + 7;


struct Node {
	int x, y, w;
};

LL dp[MAX][MAX];

void solve() {

	LL result = 0;
	int n;

	cin >> n;
	vector<int> za(n);
	for (int i = 0; i < n; ++i) {
		cin >> za[i];
		dp[i][i] = za[i];
	}
	for (int gg = 1; gg < n; ++gg) {
		for (int i = 0; i < n - gg; ++i) {
			int j = i + gg;
			LL r0 = za[i] - dp[i + 1][j];
			LL r1 = za[j] - dp[i][j - 1];
			dp[i][j] = max(r0, r1);
		}
	}

	result = dp[0][n - 1];

	cout << result << endl;

}

int main() {
	const int inId = 0;
	const int outId = 0;
	if (inId>0) {
		cerr << "redirect stdin to input " << inId << endl;
		string s = "input";
		s += to_string(inId);
		s += ".txt";
		auto r = freopen(s.c_str(), "r", stdin);	
		if (r == nullptr) {
			cerr<< "invalid input file "<< s;
		}
	}
	if (outId>0) {
		cerr << "redirect stdout to stdout " << outId << endl;
		string s = "stdout";
		s += to_string(outId);
		s += ".txt";
		auto r = freopen(s.c_str(), "w", stdout);
		if (r == nullptr) {
			cerr<< "invalid output file "<< s;
		}		
	}
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // close sync between cout and printf
	cout.precision(10);
	solve();
}
 

Measured memory_bytes: 70016
#include<iostream>
#include<string>

int main(){
  std::string S;
  std::cin >> S;

  if(S[2]==S[3] && S[4]==S[5]){
    std::cout << "Yes" << "\n";
  } else {
    std::cout << "No" << "\n";
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N;
  vector<string> s(N);
  for(int i=0;i<N;i++) cin >> s[i];
  cin >> M;
  vector<string> t(M);
  for(int j=0;j<M;j++) cin >> t[j];
  int sum=0;
  
  for(string& word : s) {
    int v=0;
    for(string& w : s) {
      if (word==w) v += 1;
    }
    for(string& w : t) {
      if (word==w) v -= 1;
    }
    if (v>sum) sum = v;
  }
  for(string& word : t) {
    int v=0;
    for(string& w : s) {
      if (word==w) v += 1;
    }
    for(string& w : t) {
      if (word==w) v -= 1;
    }
    if (v>sum) sum = v;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 60;
const int M = N*N;
int n, m;
int h[N], e[M], ne[M], idx;
int low[N], dfn[N], timestamp;
int cnt;

void add(int a, int b){
    e[idx] = b;
    ne[idx] = h[a];
    h[a] = idx ++;
}

void tarjan(int curr, int prev){
    low[curr] = dfn[curr] = ++ timestamp;
    for(int i = h[curr]; i != -1; i = ne[i]){
        int next = e[i];
        if(!dfn[next]){
            tarjan(next, curr);
            low[curr] = min(low[curr], low[next]);
            if(low[next] > dfn[curr]) cnt ++;
        } else if(next != prev){
            low[curr] = min(low[curr], low[next]);
        }
    }
}

int main(){
    memset(h, -1, sizeof h);
    cin >> n >> m;
    while(m --){
        int a, b;
        cin >> a >> b;
        add(a, b);
        add(b, a);
    }
    for(int i = 1; i <= n; i ++){
        if(!dfn[i]){
            tarjan(i, -1);
        }
    }
    cout << cnt << endl;
    return 0;
}

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

struct combination {
    ll mod;
    vector<ll> fac, finv, inv;

    combination(int n, ll m) : fac(n), finv(n), inv(n) {
        mod = m;
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < n; i++) {
            fac[i] = fac[i - 1] * i % mod;
            inv[i] = mod - inv[mod % i] * (mod / i) % mod;
            finv[i] = finv[i - 1] * inv[i] % mod;
        }
    }

    ll C(int n, int k) {
        if (n < k)
            return 0;
        if (n < 0 || k < 0)
            return 0;
        return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
    }
};

ll modpow(ll x, ll n, ll mod) {
    ll r = 1;
    while (n > 0) {
        if (n & 1)
            r = r * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return r;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // cout << fixed << setprecision(10);
    ll n, a, b, c;
    cin >> n >> a >> b >> c;
    ll mod = 1e9 + 7;
    combination com(300000, mod);
    ll ans = 0;
    ll p = a * com.inv[int(a + b)] % mod;
    ll q = b * com.inv[int(a + b)] % mod;
    rep(i, n, 2 * n) {
        ll sum = (modpow(p, n, mod) * modpow(q, i - n, mod) +
                  modpow(p, i - n, mod) * modpow(q, n, mod)) %
                 mod;
        sum *= com.C(i - 1, n - 1);
        sum %= mod;
        sum *= (ll)100 * (ll)i;
        sum %= mod;
        sum = (sum * com.inv[100 - c]) % mod;
        ans += sum;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7296
import sys,os,io
# input = sys.stdin.readline
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
N = int(input())
edge = [[] for _ in range(N)]
for i in range(N-1):
  a,b = map(int, input().split())
  edge[a-1].append(b-1)
  edge[b-1].append(a-1)

def dfs(start):
  stack = [start]
  parent = [N]*N
  parent[start] = -1
  while stack:
    v = stack[-1]
    marker = 0
    for u in edge[v]:
      if u==parent[v]:
        continue
      if parent[u]==N: #子へ降ろす
        marker = 1
        parent[u]=v
        stack.append(u)
      else: #子から吸い上げる
        pass
        #吸い上げる際の個々の処理
        ans[v] += ans[u]+1
    if marker==0:
      stack.pop()
      if v==start:
        #根へ吸い上げる時のまとめ処理
        ans[v] /= len(edge[v])
      elif ans[v]>0:
        ans[v] /= len(edge[v])-1
  return

def dfs2(start):
  stack = [start]
  parent = [N]*N
  parent[start] = -1
  p_value = [0]*N
  while stack:
    v = stack.pop()
    for i,u in enumerate(edge[v]):
      if u==parent[v]:
        continue
      parent[u] = v
      if len(edge[v])==1:
        p_value[u] = 0
      else:
        p_value[u] = (ans[v]*len(edge[v])-(ans[u]+1))/(len(edge[v])-1)
      ans[u] *= len(edge[u])-1
      ans[u] += p_value[u]+1
      ans[u] /= len(edge[u]) 
      stack.append(u)
  return

ans = [0]*N
dfs(0)
dfs2(0)
print(*ans, sep='\n')

Measured memory_bytes: 115168
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<unordered_map>
#include<unordered_set>

using namespace std;
typedef long long int ll;typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define ALL(a) (a).begin(),(a).end()

int main(void) {
	string str;
	cin >> str;
	bool c=0, f=0;
	rep(i, str.length()) {
		if (str.at(i) == 'C')c = 1;
		if (c&&str.at(i) == 'F')f = 1;
	}
	cout << (c&& f ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};

int main(){
  int H, W;
  cin >> H >> W;
  char S[H+2][W+2];
  for(int i=0; i<H+2; i++){
    for(int j=0; j<W+2; j++) S[i][j]='#';
  }
  for(int i=1; i<H+1; i++){
    for(int j=1; j<W+1; j++) cin >> S[i][j];
  }
  
  int ans=0;
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      if(S[i+1][j+1]=='#') continue;
      queue<pair<int, int>> que;
      vector<vector<int>> dist(H, vector<int>(W, -1));
      que.push({i, j});
      dist[i][j]=0;
      while(!que.empty()){
        int x, y;
        tie(y, x) = que.front();
        que.pop();
        for(int k=0; k<4; k++){
          int nx = x + dx[k], ny = y+dy[k];
          if(nx < 0 || W <= nx || ny < 0 || H <= ny || S[ny+1][nx+1] == '#'|| dist[ny][nx] != -1) continue;
          dist[ny][nx] = dist[y][x] + 1;
          que.push({ny, nx});
        }
      }
      int diss=0;
      for(int k=0; k<H; k++){
        for(int l=0; l<W; l++) diss=max(diss, dist[k][l]);
      }
      ans=max(ans, diss);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    int flag=0;
    for(int i=1;i<1100;i++){
        if((i*8)/100==a && i/10==b)
        {cout<<i;
        flag=1;
        break;}
    }
    if(flag==0)
    cout<<-1;
    
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <cmath>
#include <unordered_map>

#define MaxN 2010

using namespace std;

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

int n;
int a[MaxN];
pii a_p[MaxN];
ll dp[MaxN][MaxN];


int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);
        a_p[i] = make_pair(a[i], i);
    }
    sort(a_p + 1, a_p + n + 1, greater<pii>());
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= i; ++j) {
            dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + (ll)a_p[i].first * (ll)abs(a_p[i].second - j));
        }
        for (int j = 0; j < i; ++j) {
            dp[i][j] = max(dp[i][j], dp[i - 1][j] + (ll)a_p[i].first * (ll)abs(n - (i - j) + 1 - a_p[i].second));
        }
    }
    ll ans = 0;
    for (int i = 0; i <= n; ++i) {
        ans = max(ans, dp[n][i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 26348
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public final class Main {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final int l = in.nextInt();
        final int r = in.nextInt();
        final int d = in.nextInt();
        in.nextLine();
        int res = 0;
        for (int i = l; i <= r; i++) {
            if (i % d == 0) {
                res++;
            }
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 35684
#include<stdio.h>
#include<string.h>
void main()
{
int n,i;
char s[100],a[50]={0},b[50]={0};
scanf("%d",&n);
scanf("%s",s);
for(i=0;i<=(n/2)-1;i++)
 a[i]=s[i];
for(i=n/2;i<=n;i++)
 b[i-(n/2)]=s[i];
if(strcmp(a,b)==0)
 printf("Yes");
else
printf("No");
}

 





Measured memory_bytes: 128
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	
	char s[4];
	for (int i = 0; i < 4; i++)
		cin >> s[i];
	int sum = 0;
	for (int i = 0; i < 4; i++)
	{
		for(int j=0;j<i;j++)
			if (s[j] == s[i])
			{
				sum++;
				break;
			}
	}
	if (sum == 2) cout << "Yes" << endl;
	else cout << "No" << endl;
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  ll i,n,x;
  cin >> n >> x;
  ll a[100010];
  for(i=0;i<n;i++){
    cin >> a[i];
  }
  ll sum=0;
  for(i=1;i<n;i++){
    if(a[i-1]+a[i]>=x){
      if(a[i-1]+a[i]-x<=a[i]){
        sum+=(a[i-1]+a[i]-x);
        a[i]=x-a[i-1];
      }
      else{
        sum+=(a[i-1]+a[i]-x);
        a[i]=0;
      }
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 4408
W,H,N = map(int,input().split())
bo = [[0]*W]*H
for i in range(N):
    x,y,z = map(int,input().split())
    if z == 1:
        for j in range(H):
            for k in range(x):
                bo[j][k] = 1
    elif z == 2:
        for j in range(H):
            for k in range(x,W,1):
                bo[j][k] = 1
    elif z == 3:
        for j in range(y):
            bo[j] = [1]*W
    else:
        for j in range(H-1,y-1,-1):
            bo[j] = [1]*W

sum = 0

for i in range(H-1,-1,-1):
    sum += bo[i][:].count(1)
print((W*H)-sum)

Measured memory_bytes: 3064
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
int main(){
   
    char c[3][3];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin>>c[i][j];
        }
    }
   
    cout<<c[0][0]<<c[1][1]<<c[2][2]<<endl;

    return 0;
   
}






Measured memory_bytes: 256
#include<stdio.h>

int isprime(int x){
  int i;
  if(x==2) return 1;
  if(x<2 || x%2==0) return 0;
  for(i=3;i*i<=x;i+=2){
    if(x%i==0) return 0;
  }
  return 1;
}

int main(){
  int n,c=0,i,a;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a);
    if(isprime(a)) c++;
  }
  printf("%d\n",c);
  return 0;
}
    



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

using namespace std;
const int N=1100000;

int n,a[N],flag;
char s[N];

void dfs(int t)
{
    if(t==n-1)
    {
        int flag1=0;
        if(a[t]==1)//wf
        {
            if((s[t]=='o'&&a[n-2]!=a[0])||(s[t]=='x'&&a[n-2]==a[0]))
            {
                if(a[0]==1)
                {
                    if((s[0]=='o'&&a[1]!=a[t])||(s[0]=='x'&&a[1]==a[t]))
                        flag1=1;
                }
                else
                {
                    if((s[0]=='o'&&a[1]==a[t])||(s[0]=='x'&&a[1]!=a[t]))
                        flag1=1;
                }
            }
        }
        else
        {
            if((s[t]=='o'&&a[n-2]==a[0])||(s[t]=='x'&&a[n-2]!=a[0]))
            {
                if(a[0]==1)
                {
                    if((s[0]=='o'&&a[1]!=a[t])||(s[0]=='x'&&a[1]==a[t]))
                        flag1=1;
                }
                else
                {
                    if((s[0]=='o'&&a[1]==a[t])||(s[0]=='x'&&a[1]!=a[t]))
                        flag1=1;
                }
            }
        }
        if(flag1)
        {
            for(int i=0;i<n;i++)
            {
                if(a[i]==0) printf("S");
                else    printf("W");
            }
            printf("\n");
            flag=0;
        }
        return;
    }
    if(a[t]==0)
    {
        if(s[t]=='o')
            a[t+1]=a[t-1];
        else
            a[t+1]=1-a[t-1];
    }
    else
    {
        if(s[t]=='o')
            a[t+1]=1-a[t-1];
        else
            a[t+1]=a[t-1];
    }
    dfs(t+1);
}

int main()
{
    while(~scanf("%d",&n))
    {
        scanf("%s",s);
        flag=1;
        for(int i=0;i<2&&flag;i++)
            for(int j=0;j<2&&flag;j++)
            {
                a[0]=i;
                a[1]=j;
                dfs(1);
            }
        if(flag)
        {
            printf("-1\n");
        }
    }
}


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

int main() {
	int a,b;
  	string d;
  	cin >> a >> b;
  	cin >> d;
  	if(d[b-1]=='A')
      d[b-1] = 'a';
  	else if(d[b-1]=='B')
      d[b-1] = 'b';
  	else
      d[b-1] = 'c';
  	cout << d << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
    int n;
    cin>>n;
    vector<vector<pair<int,ll>>>g(n);
    for(int i=0;i<n-1;++i){
        int u,v;
        ll w;
        cin>>u>>v>>w;
        u--,v--;
        g[u].push_back({v,w});
        g[v].push_back({u,w});
    }
    vector<bool>ans(n,false), visited(n,false);
    stack<int>st;
    st.push(0);
    while(!st.empty()){
        auto now=st.top();
        st.pop();
        visited[now]=true;
        for(auto dst:g[now]){
            if(!visited[dst.first]){
                st.push(dst.first);
                ans[dst.first]=ans[now];
                if(dst.second & 1)ans[dst.first]=(!ans[dst.first]);
            }
        }
    }
    for(auto b:ans){
        cout<<b<<endl;
    }
}

Measured memory_bytes: 7936
#include<bits/stdc++.h>
using namespace std;
#define M_PI 3.1415926535
#define ll long long
#define ld long double
#define all(a) (a.begin(),a.end())
#define Summon_Tourist ios::sync_with_stdio(false);cin.tie(0);
ll gcd(ll a , ll b) { return b==0?a: gcd( b, a%b); }
ll lcm(ll a , ll b) { return a/gcd(a,b) * b ; }
ll inf = 998244353;
ll modexp( ll base ,ll power)
 {
     if( power == 0  ) return 1;
     if( power & 1) return base*modexp( base , power-1 )%inf;
     return modexp(base*base%inf,power/2);
 }
 int main()
{
  Summon_Tourist
  //freopen("input.txt" , "r" , stdin ) ;
  ll t = 1 ;
  //cin>>t ;
  while(t--)
  {
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    vector<vector<ll> > ar( c+1 , vector<ll> (d+1,0)) ;
    ar[a][b] = 1 ;
    for( ll i = a+1 ; i<=c ; i++ )
    {
        ar[i][b] = (b%inf*ar[i-1][b]%inf)%inf ;
    }
    for( ll i = b+1 ; i<=d ; i++ )
    {
        ar[a][i] = (a%inf*ar[a][i-1]%inf)%inf;
    }
    for( ll i = a+1 ; i<=c ; i++ )
    {
        for( ll j = b+1 ; j<=d ; j++ )
        {
            ar[i][j] = (((j%inf*ar[i-1][j]%inf) + (i%inf*ar[i][j-1]%inf)%inf - ((i-1)%inf*(j-1)%inf*ar[i-1][j-1]%inf)%inf)%inf + inf)%inf ;
        }
    }
    cout<<ar[c][d]%inf;
  }
  return 0;

}


Measured memory_bytes: 73608
#include <stdio.h>
#include <string.h>

int main() {
	char a[100];
	int k, length;
	scanf("%d\n%s", &k, &a);
	
	length = strlen(a);
	
	if(length <= k) {
		printf ("%s\n", a);
	}
	else if(length > k ) {
		for ( int i = 0; i < k; i++) {
		printf ("%c", a[i]);
	}
	puts("...");
  }
	
	return 0;
}

Measured memory_bytes: 1660
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
#include <string.h>
#include <map>
#include <cmath>
#include <deque>
using ll = long long;
using Graph = vector<vector<int>>;
#include <queue>
#include <stack>

//最大公約数
ll gcd(ll a,ll b){
    if(b == 0LL) return a;
    return gcd(b , a % b);
}

//最小公倍数
ll lcm(ll a,ll b){
    return a / gcd(a,b) * b;

}

//前後を比較
bool compare(int pos,vector<int>& a){
    if(a[pos] == a[pos + 1]) return true;
    else return false;
}

int main(){

    string s;
    cin >> s;
    //辞書順ソート
    sort(s.begin(),s.end());
    
    vector<char> ans;
    for(char i = 'a';i <= 'z';i++){
        bool exist = false;//存在しないとして探索  
        // for(int  j = 0;j < s.length();j++){
        //     if(i == s[j]){
        //         exist = true;
        //         break;//次の文字へ
        //     }

        // }
        //やっぱり二分探索
        exist = binary_search(s.begin(),s.end(),i);
        //入力文字列に含まれない辞書順最小の文字を格納
        if(!exist) {
            ans.push_back(i);
            break;
        }

    }

    if(ans.size() > 0) cout << ans[0];
    else cout << "None" << endl;

    



}

Measured memory_bytes: 512
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

ll A, B, K;

int main() {
	scanf("%lld %lld %lld", &A, &B, &K);
	if(A <= K) {
		K -= A;
		A = 0;
		B -= K;
		B = max(0ll, B);
		cout << A << " " << B<<"\n";
	}
	else {
		cout << A - K << " " << B;
	}


	return 0;
}
/*
	Powered by Buggy Plugin
*/


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

int main(){
  int H, W;
  cin >> H >> W;
  char tmp;
  for(int i = 0; i < W + 2; i++){
    cout << '#';
    if(i == W + 1) cout << endl;
  }
  for(int i = 0; i < H; i++){
    cout << '#';
    for(int j = 0; j < W; j++){
      cin >> tmp;
      cout << tmp;
      if(j == W - 1) cout << '#' << endl;
    }
  }   
  for(int i = 0; i < W + 2; i++){
    cout << '#';
    if(i == W + 1) cout << endl;
  }
  return 0;
}

Measured memory_bytes: 3644
package main

import "fmt"

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	s := make(map[int]bool, n)

	for i:=0; i<k; i++ {
		var d int
		fmt.Scan(&d)
		for j:=0; j<d; j++ {
			var a int
			fmt.Scan(&a)
			s[a] = true
		}
	}

	var target int
	for i, _ := range s {
		if s[i] == true {
			target += 1
		}
	}

	fmt.Println(n-target)
}


Measured memory_bytes: 2468
n,k=map(int,input().split())

#n以下の整数で、a+b=kx b+c=ky c+a=kz
# a-b=k(x-y)


dic=[0]*k

for i in range(1,n+1):
    dic[i%k]+=1

if k%2==0:
    print(dic[k//2]**3+dic[0]**3)
else:
    print(dic[0]**3)

Measured memory_bytes: 40048
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
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 INF=1e10;
int MOD=1e9+7;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int kurai(int a,int b){
  int m=pow(10,b),n=pow(10,b-1);
  return (a%m)/n;
}
int ketawa(int a){
  int k=0;
  rep(i,keta(a)){
  k+=kurai(a,i+1);
  }
  return k;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
int mid(int a,int b,int c){
  vector<int> k(3);
  k[0]=a;k[1]=b;k[2]=c;
  sort(all(k));
  return k[1];
}
bool sosuu(int a){
  bool b=1;
  if(a<=1)
    return 0;
  else{
  rep1(i,sqrt(a)-1){
  if(a%(i+1)==0)
  b=0;
  }
  return b;
  }
}
int modpow(int a,int b,int m=MOD){
 if(!b)return 1; if(b&1)return modpow(a,b-1,m)*a%m;
 int memo = modpow(a,b>>1,m);
 return memo*memo%m;
}
int fact_mod(int n) {
    int f=1; 
for(int i=2;i<n+1;i++) f=f*(i%MOD)% MOD;
    return f;
}
int mod_pow(int x,int n) {
    int res=1;
    while(n>0){
        if(n&1) res=(res*x)%MOD; 
        x=(x*x)%MOD;        
n>>=1; 
    }
    return res;
}
int c_mod(int n, int r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    int a=1;
    rep(i,r) 
a=a*((n-i)%MOD)%MOD;
    int b=mod_pow(fact_mod(r), MOD-2);
    return (a%MOD)*(b%MOD)%MOD;
}
signed main(){
  string a;
  cin>>a;
  int b=0,c=0;
  rep(i,a.size()){
    if(i%2==0){
    if(a[i]=='0')
      b++;
    }
    else{
      if(a[i]=='1')
        b++;
    }
  }
  rep(i,a.size()){
    if(i%2==0){
    if(a[i]=='1')
      c++;
    }
    else{
      if(a[i]=='0')
        c++;
    }
  }
  out(min(b,c));
}

Measured memory_bytes: 3944
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;
void solve() {
     
     long int n;
     cin>>n;

     vector<long long int>a(n);
     long long int sum=0;
     for(long int i=0;i<n;i++) {
           cin>>a[i];
           sum= (sum+a[i]) % mod;
     }
     sum=sum-a[0];
     if(sum < 0) sum+=mod;

     long long int s=0;
     for(int i=0;i<n-1;i++) {
           s=(s + (a[i]*sum)%mod) % mod;
           sum-=a[i+1];
           if(sum < 0 ) sum+=mod;
     }

   cout<<s;
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     #ifndef ONLINE_JUDGE
     freopen("in.txt","r",stdin);
      
     #endif

     int t;
     t=1;
     while(t--) solve();


   return 0;
}


Measured memory_bytes: 4788
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase

/*
cout<<fixed<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
vector<vector<int>>go;
vector<llint>A;
int n;
pair<vector<llint>,llint>solve(int ter,int per){
	//bigは不可
	vector<llint>ans(1,A[ter]);
	int sar=0;
	for(auto it:go[ter]){
		if(it==per){continue;}
		auto ret=solve(it,ter);
		
		sar+=ret.sec;
		vector<llint>iti(ans.size()+ret.fir.size()-1,big);
		for(int i=0;i<ans.size();i++){
			for(int j=0;j<ret.fir.size();j++){
				mineq(iti[i+j],ans[i]+ret.fir[j]);
			}
		}
		ans=iti;
	}
	ans.pub(0);
	if(A[ter]<0){sar=mod;}
	for(int i=0;i<ans.size();i++){
		if(ans[i]<0){mineq(sar,i+1);break;}
	}
	for(int i=sar+1;i<ans.size();i++){mineq(ans[i],0);}
	
	//for(int i=0;i<ans.size();i++){cerr<<ans[i]<<" ";}cerr<<"i="<<ter<<endl;
	return mp(ans,sar);
}
int main(void) {
	int i;cin>>n;
	go.res(n);A.res(n);
	for(i=0;i<n;i++){cin>>A[i];}
	for(i=1;i<n;i++){
		int x,y;cin>>x>>y;x--;y--;
		go[x].pub(y);
		go[y].pub(x);
	}
	auto ret=solve(0,-1);
	for(i=0;i<ret.fir.size();i++){
		if(ret.fir[i]<0){mineq(ret.sec,i);break;}
	}
	cout<<ret.sec<<endl;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
int n,m;
int dp[100100];
vvi g;
int ds(int id) {
	int lp=0;
	if(dp[id] != -1) {return dp[id];}
	for(int i=0;i<g[id].size();i++) {
		lp = max(lp,1+ds(g[id][i]));
	}
	return dp[id] = lp;
}
int main() {
	scanf("%d %d ",&n,&m);
	memset(dp,-1,sizeof(dp));
	g.assign(n,vi());
	while(m--) {
		int a,b;
		scanf("%d %d ",&a,&b);
		a--;b--;
		g[a].push_back(b);
	}
	int mp = 0;
	for(int i=0;i<n;i++) {
		mp = max(mp,ds(i));
	}
	printf("%d\n",mp);
}

Measured memory_bytes: 8192
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<math.h>
using namespace std;

const int M=3;
const int N=1e5+5;
const int mod=1e9+7;
struct mat
{
	int a[M][M];
};
mat hv,uhv,sig;
int len,n,s[N],t[N];

namespace MATHEMATICS
{
	int add(int x,int y)
	{
		int ret=x+y;
		if(ret>=mod) ret-=mod;
		return ret;
	}
	int mi(int x,int y)
	{
		int ret=x-y;
		if(ret<0) ret+=mod;
		return ret;
	}
	
	void inc(int &x,int y)
	{
		x+=y;
		if(x>=mod) x-=mod;
	}
	void dec(int &x,int y)
	{
		x-=y;
		if(x<0) x+=mod;
	}
	
	int mul(int x,int y)
	{
		return 1LL*x*y%mod;
	}
	int F_p(int x,int y)
	{
		int ret=1,bas=x;
		while(y)
		{
			if(y&1) ret=mul(ret,bas);
			bas=mul(bas,bas);
			y>>=1;
		}
		return ret;
	}
}
using namespace MATHEMATICS;

namespace MAT
{
	void clear(mat &A)
	{
		int i,j;
		for(i=0;i<3;++i)
			for(j=0;j<3;++j)
				A.a[i][j]=0;
	}
	void reset(mat &A)
	{
		int i,j;
		clear(A);
		for(i=0;i<3;++i) A.a[i][i]=1;
	}
	
	mat operator * (mat x,mat y)
	{
		mat ret;clear(ret);
		int i,j,k;
		for(i=0;i<3;++i)
			for(j=0;j<3;++j)
				for(k=0;k<3;++k)
					inc(ret.a[i][j],mul(x.a[i][k],y.a[k][j]));
		return ret;
	}
	
	mat F_p(mat x,int y)
	{
		mat ret,bas;
		reset(ret),bas=x;
		while(y)
		{
			if(y&1) ret=ret*bas;
			bas=bas*bas;
			y>>=1;
		}
		return ret;
	}
}
using namespace MAT;

void init()
{
	int i;
	scanf("%d%d",&len,&n);
	for(i=1;i<=n;++i) scanf("%d",&t[i]);
	for(i=1;i<=n;++i) s[i]=t[i]-t[i-1]-1;
	s[++n]=len-t[n-1];
}

void prework()
{
	uhv.a[0][0]=1,uhv.a[0][1]=0,uhv.a[0][2]=0;
	uhv.a[1][0]=1,uhv.a[1][1]=1,uhv.a[1][2]=0;
	uhv.a[2][0]=1,uhv.a[2][1]=2,uhv.a[2][2]=1;
	
	int i,j;
	for(i=0;i<3;++i)
		hv.a[i][0]=hv.a[i][1]=0,hv.a[i][2]=1;
	
	for(i=0;i<3;++i)
		for(j=0;j<3;++j)
			hv.a[i][j]+=uhv.a[i][j];
}

void work()
{
	int i,j,k;
	mat pr;reset(pr);
	for(i=1;i<=n;++i)
	{
		pr=pr*F_p(hv,s[i]);
		if(i<n) pr=pr*uhv;
	}
	printf("%d\n",pr.a[2][0]);
}

int main()
{
	init();prework();work();
	return 0;
}

Measured memory_bytes: 1024
N = int(input())
import sys
sys.setrecursionlimit(N+10)

es = [[] for _ in range(N)]
for i in range(N-1):
    a,b = map(int, input().split())
    a,b = a-1, b-1
    es[a].append(b)
    es[b].append(a)

"""
相手の取れるマス目を減らすようにとるとよい
相手よりそのマスに近ければそのマスを取得できる
フェネックくん、すぬけ君について初期地点からそれぞれへの距離が必要
"""
def solve(now, depth, depth_list, es, visited):
    visited[now] = True
    depth_list[now] = depth
    for next in es[now]:
        if visited[next] == False:            
            solve(next, depth+1, depth_list, es, visited)

depth_list_F = [0] * N
visited_F = [False] * N
solve(0, 0, depth_list_F, es, visited_F)

depth_list_S = [0] * N
visited_S = [False] * N
solve(N-1, 0, depth_list_S, es, visited_S)

cnt_F = cnt_S = 0
for f,s in zip(depth_list_F, depth_list_S):
    if f <= s:
        cnt_F += 1 # フェネック君から始めるので同じ距離ならフェネック君がとる
    else:
        cnt_S += 1

if cnt_F > cnt_S:
    print("Fennec")
else:
    print("Snuke")

Measured memory_bytes: 126092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
double pi = 3.14159265359;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = a - 1; i >= b; i--)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

int main() {
    map<pint, int> mp;
    int n;
    cin >> n;
    rep (i, 1, n + 1) {
        if (i < 10) mp[{i, i}]++;
        else {
            int a = i % 10, b = i;
            while (b > 9) {
                b /= 10;
            }
            mp[{b, a}]++;
        }
    }
    ll ans = 0;
    for (auto p : mp) {
        if (p.first.first == p.first.second) ans += p.second * p.second;
        else {
            ans += mp[{p.first.second, p.first.first}] * p.second;
        }
    } /*
     for (auto p : mp) {
         cout << p.first.first << p.first.second << " " << p.second << "\n";
     }*/

    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_map>
#include <deque>
#include <list>
#include <set>
#include <random>
#include <deque>

using namespace std;
using ll = long long;
const int BIG = 100000007;


int main() {
    ll k;
    cin >> k;
    ll c = 1;
    ll d = 0;
    vector<ll> history(k,0);
    while (true){
        d = (d * 10 + 7) % k;
       // cout << d << endl;

        if(d == 0)break;
        if(c > 1 && history[d] == 1){
            cout << -1 << endl;
            return 0;
        }
        history[d] = 1;
        ++c;
    }
    cout << c << endl;
}




Measured memory_bytes: 10692
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>

using namespace std;
const int MAX=10010;

string s, t;

inline void readx(int &x){
	register int k=1; x=0; register char ch=0;
	while(ch<'0' | ch>'9') { ch=getchar(); if(ch=='-') k=-1; }
	while(ch>='0' && ch<='9') { x=x*10+ch-48; ch=getchar(); }
	x*=k;
}

int main(){
	cin>>s>>t;
	for(register int k=0; k<s.size(); k++){
		register int i=0;
		for(i=0; i<s.size(); i++){
			if(s[i]!=t[i]) break;
		}
		if(i==s.size()){
			printf("Yes\n");
			return 0;
		}
		for(register int i=s.size(); i>0; i--){
			t[i]=t[i-1];
		}
		t[0]=t[s.size()];
		/*for(register int ss=0; ss<s.size(); ss++){
			printf("%c", t[ss]);
		}
		printf("\n");*/
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 256
N,A,B=(int(x) for x in input().split())

tot=0
for i in range(N+1):
    ketat=0
    ketat+=i//1e4 #5ケタ
    ketat+=(i%1e4)//1e3 #4ケタ
    ketat+=(i%1e3)//1e2 #3ケタ
    ketat+=(i%1e2)//1e1 #2ケタ
    ketat+=i%10 #1ケタ
    # print("i,ketat=",i,ketat)
    if ketat>=A and ketat<=B:
        tot+=i
print(tot)


Measured memory_bytes: 3188