akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()
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; }
using namespace std;

template<const long long mod = 1000000007>
struct mint{ //modint
    long long x;
    mint(long long x = 0): x((x %= mod) < 0 ? x + mod : x) {}
    friend istream& operator >> (istream &s, mint& m){ return s >> m.x; }
    friend ostream& operator << (ostream &s, mint m){ return s << m.x; }
    inline mint& operator += (mint a){ if((x += a.x) >= mod)x -= mod; return *this; }
    inline mint& operator -= (mint a){ if((x += mod - a.x) >= mod)x -= mod; return *this; }
    inline mint& operator *= (mint a){ (x *= a.x) %= mod; return *this; }
    inline mint& operator /= (mint a){ return (*this) *= a.inv(); }
    inline mint operator + (mint a){ mint res(*this); return res += a; }
    inline mint operator - (mint a){ mint res(*this); return res -= a; }
    inline mint operator * (mint a){ mint res(*this); return res *= a; }
    inline mint operator / (mint a){ mint res(*this); return res /= a; }
    inline void takemod(){ x = ((x % mod) + mod) % mod; }
    inline mint inv(){
        long long a = x, b = mod, u = 1, v = 0, t;
        while(b){
            t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        return mint(u);
    }
    inline mint pow(long long p){
        mint res(1), tmp(x);
        for(; p; p >>= 1){ if(p & 1)res *= tmp; tmp *= tmp; }
        return res;
    }
};

template<const long long mod = 1000000007>
struct mfact{ //modfact
private:
    vector<mint<mod>> fact, ifact;
public:
    mfact(int size = 200010) : fact(size + 1), ifact(size + 1) {
        fact[0] = mint<mod>(1);
        for(int i = 1; i <= size; i++)fact[i] = fact[i - 1] * mint<mod>(i);
        ifact[size] = fact[size].inv();
        for(int i = size; i > 0; i--)ifact[i - 1] = ifact[i] * mint<mod>(i);
    }
    inline mint<mod> operator [] (int i){ return fact[i]; }
    inline mint<mod> nPr(int n, int r){ return fact[n] * ifact[r]; }
    inline mint<mod> nCr(int n, int r){ return fact[n] * ifact[n - r] * ifact[r]; }
};

int main(){

    int N, A, B, C;
    cin >> N >> A >> B >> C;

    mint<> a = mint<>(A) / mint<>(A + B);
    mint<> b = mint<>(B) / mint<>(A + B);
    mint<> c = mint<>(100) / mint<>(100 - C);
    mfact<> fac;

    mint<> ans;
    for(int i = N; i < 2 * N; i++){
        mint<> tmp;
        tmp += a.pow(N) * b.pow(i - N) * fac.nCr(i - 1, N - 1);
        tmp += a.pow(i - N) * b.pow(N) * fac.nCr(i - 1, N - 1);
        ans += tmp * i * c;
    }

    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P std::pair<int,int>
#define PiP std::pair<int,std::pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp std::make_pair
#define prique(T) std::priority_queue<T,vector<T>,greater<T>>
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = std::max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = std::min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	std::random_device rnd;
	std::mt19937_64 mt64(rnd());
	std::uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt64);
}
/*--------Library Zone!--------*/

int n;
string s;
signed main() {
	cin >> n >> s;
	stack<char>st;
	rep(i, n) {
		if (st.empty() || st.top() == ')')st.push(s[i]);
		else if (st.top() == '(') {
			if (s[i] == ')')st.pop();
			else st.push(s[i]);
		}
	}
	int le = 0, ri = 0;
	while (st.size()) {
		if (st.top() == '(')ri++;
		else le++;
		st.pop();
	}
	rep(i, le)cout << '('; cout << s; rep(i, ri)cout << ')';
}


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

typedef std::pair<int, int> swap_command;

int w, n;
std::vector<int> vertical;
std::vector<swap_command> commands;

swap_command get_command_input()
{
	swap_command cmd;
	char dummy;
	std::cin >> cmd.first >> dummy >> cmd.second;
	return cmd;
}

void init()
{
	std::cin >> w;
	std::cin >> n;

//	std::cout << w << " " << n << std::endl;

	int i;
	for (i = 0; i < w; i++) {
		vertical.push_back(i+1);
	}

	for (i = 0; i < n; i++) {
		commands.push_back(get_command_input());
	}
}

void dump_vertical()
{
	std::cout << "vertical: ";
	for (int i = 0; i < w; i++) {
		std::cout << vertical[i] << ' ';
	}
	std::cout << std::endl;
}

void swap(swap_command cmd)
{
//	std::cout << "fist: " << cmd.first << " second: " << cmd.second << std::endl;
	int i = cmd.first-1;
	int j = cmd.second-1;
	int tmp = vertical[i];
	vertical[i] = vertical[j];
	vertical[j] = tmp;
//	dump_vertical();
}

void solve()
{
	for (std::vector<swap_command>::iterator i = commands.begin(); i != commands.end(); i++) {
		swap(*i);
	}
}

void output()
{
	for (std::vector<int>::iterator i = vertical.begin(); i != vertical.end(); i++) {
		std::cout << *i << std::endl;
	}
}

int main()
{
	init();
	solve();
	output();
	return 0;
}

Measured memory_bytes: 0
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

pub struct Graph {
    graph: Vec<Vec<usize>>,
}

type Edge = (usize, usize);
impl Graph {
    pub fn new_directed(edges: &[Edge], v: usize) -> Self {
        let mut graph = vec![Vec::new(); v];
        for &(u, v) in edges {
            graph[u].push(v);
        }
        Graph { graph }
    }

    pub fn solve(&self, que: VecDeque<usize>, indegreev: &mut Vec<usize>) -> isize {
        let mut res = 1;
        let mut que = self.next_que(que, indegreev);
        loop {
            if que.len() == 0 {
                break;
            }
            res += 1;
            que = self.next_que(que, indegreev);
        }
        let is_ok = indegreev.into_iter().all(|x| *x == 0);
        if is_ok {
            res as isize
        } else {
            -1
        }
    }

    fn next_que(&self, mut que: VecDeque<usize>, indegreev: &mut Vec<usize>) -> VecDeque<usize> {
        let mut res = VecDeque::new();
        while let Some(u) = que.pop_front() {
            for &v in &self.graph[u] {
                indegreev[v] -= 1;
                if indegreev[v] == 0 {
                    res.push_back(v);
                }
            }
        }
        res
    }
}

fn solve() {
    input! {
        n: usize,
        matchv: [[Usize1; n - 1]; n]
    };

    let vn = n * (n - 1) / 2;
    let mut indegreev = vec![0; vn];
    let mut edges = Vec::new();
    let mut id_table: HashMap<(usize, usize), usize> = HashMap::new();
    let mut cur_id = 0;
    for i in 0..n {
        let a = i;
        for mv in matchv[i].windows(2) {
            let b = mv[0];
            let key = (a.min(b), a.max(b));
            let u = match id_table.get(&key) {
                Some(id) => *id,
                None => {
                    let id = cur_id;
                    id_table.insert(key, id);
                    cur_id += 1;
                    id
                }
            };
            let c = mv[1];
            let key = (a.min(c), a.max(c));
            let v = match id_table.get(&key) {
                Some(id) => *id,
                None => {
                    let id = cur_id;
                    id_table.insert(key, id);
                    cur_id += 1;
                    id
                }
            };
            indegreev[v] += 1;
            edges.push((u, v));
        }
    }

    let graph = Graph::new_directed(&edges, vn);
    let mut que = VecDeque::new();
    for u in 0..vn {
        if indegreev[u] == 0 {
            que.push_back(u);
        }
    }
    let res = graph.solve(que, &mut indegreev);
    println!("{}", res);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 84908
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
int N;
ll a[200000], b[200000];
ll T;

bool comp(P p1, P p2){
    if(p1.first == 0 && p2.first == 0) return p1.first < p2.first; 
    return (p1.second*p2.first < p1.first*p2.second);
}

ll dp[200005][60];
P p[200005];
const ll INF = 1e+15;
vector<ll> z;
vector<ll> sum;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N >> T;
    T++;
    for(int i = 0; i < N; i++){
        cin >> a[i] >> b[i];
        b[i]++;
        p[i] = P(a[i], b[i]);
        if(a[i] == 0) z.push_back(b[i]);
    }
    sort(z.begin(), z.end());
    sum.push_back(0);
    ll cur = 0;
    for(int i = 0; i < z.size(); i++){
        cur += z[i];
        sum.push_back(cur);
    }
    sort(p, p+N, comp);
    // for(int i = 0; i < N; i++){
    //     cout << p[i].first << ' ' << p[i].second << ' ' << (double)p[i].first/(double)p[i].second << endl;
    // }
    dp[0][0] = 1;
    for(int i = 1; i < 60; i++){
        dp[0][i] = INF;
    }
    for(int i = 1; i <= N; i++){
        for(int j = 0; j < 60; j++){
            dp[i][j] = INF;
        }
    }
    int idx;
    for(int i = 0; i < N; i++){
        idx = i;
        if(p[i].first == 0) break;
        for(int j = 0; j < 60; j++){
            if(dp[i][j] > T) continue;
            ll t = dp[i][j];
            ll a_ = p[i].first;
            ll b_ = p[i].second;
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
            dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j]+(t*a_)+b_);
        }
        idx++;
    }
    int ans = 0;
    // cout << idx << endl;
    for(int i = 0; i < 60; i++){
        ll t = dp[idx][i];
        if(t > T) continue;
        // cout << i << ' ' << t << endl;
        auto ptr = upper_bound(sum.begin(), sum.end(), T-t);
        ptr--;
        ans = max(ans, i+(int)(ptr-sum.begin()));
    }
    cout << ans << endl;
}

Measured memory_bytes: 103536
#include <stdio.h>
#define MAX 100

int main(){
  int n,a[MAX+1][MAX+1],i,j,u,k,v;

  scanf("%d",&n);

  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      a[i][j]=0;
    }
  }

  for(i=1;i<=n;i++){
    scanf("%d%d",&u,&k);
    for(j=1;j<=k;j++){
      scanf("%d",&v);
      a[u][v]=1;
    }
  }

  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      if(j==n) printf("%d\n",a[i][j]);
      else printf("%d ",a[i][j]);
    }
  }
  return 0;
}


Measured memory_bytes: 2112
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")
#include <bits/stdc++.h>

using namespace std;

#define PB push_back
#define MP make_pair
#define EB emplace_back
#define f first
#define s second
#define FOR(i,a,b) for (int i = a; i < (b); ++i)
#define RFOR(i, b, a) for (int i = b-1; i>=a; --i)
#define FILL(a, b) memset(a, b, sizeof a)
#define ALL(a) a.begin(), a.end()
#define SZ(a) ((int)a.size())
#define bitc(n) __builtin_popcount(n)
#define MAGIC0 mt19937 rnd(time(0)); //rnd()

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = 1LL * INF*INF;
const int MAX = 1e6 + 7;
const double PI = acos(-1.);
const double EPS = 1e-7;
const int MAXN = 100005;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int cnt[100005], d[100005];
bool was[100005];
VI x[100005];
vector<PII> ans;

void dfs(int v, int p = -1)
{
	was[v] = 1;
	for(auto to : x[v])
	{
		if (was[to] && to != p && d[to] < d[v])
		{
			ans.EB(v, to);
			cnt[v] ^= 1;
		}
		if (!was[to])
		{
			d[to] = d[v] + 1;
			dfs(to, v);
			if (cnt[to])
			{
				ans.EB(to, v);
			}
			else
			{
				ans.EB(v, to);
				cnt[v] ^= 1;
			}
		}
	}
}

int main()
{
	ios_base::sync_with_stdio(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, m;
	cin >> n >> m;
	FOR(i, 0, m)
	{
		int a, b;
		cin >> a >> b;
		--a, --b;
		x[a].PB(b);
		x[b].PB(a);
	}
	
	if (m % 2)
	{
		cout << -1 << "\n";
		return 0;
	}
	
	dfs(0);
	for(auto el : ans)
	{
		cout << el.f + 1 << " " << el.s + 1 << "\n";
	}
	
	return 0;
}









Measured memory_bytes: 14964
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin >> n;
    vector<int> a(n),b(n),c(100005);
    for(int i=0;i<n;i++){
        cin >> a[i] >> b[i];
        c[a[i]-1]++,c[b[i]]--;
    }
    int sum=0,ans=0;
    for(int i=1;i<=n;i++){
        sum+=c[i];
        if(sum>=i){
            chmax(ans,i);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 4028
k=int(input())

def dfs(keta, val):
  lunlun.append(val)

  if keta==10:
    return

  for i in range(-1,2):
    add=(val%10)+i
    if 0<=add<=9:
      dfs(keta+1, val*10+add)

lunlun=[]
for i in range(1,10):
  dfs(1, i)

lunlun.sort()
print(lunlun[k-1])

Measured memory_bytes: 19248
#C
def zeros(n): return [0 for i in range(n)]

N, M = [int(x) for x in input().split()]
city = []
for i in range(M):  
    pref, year = [int(x) for x in input().split()]
    city.append([pref, year, i, ''])

#print(N, M) #
#print(city) #
city.sort()
#print(city) #

nth = zeros(N+1)
for i in range(M):
    pref, year, seq, id = [x for x in city[i]]
    nth[pref] += 1
    city[i][3] = '%06d%06d' % (pref, nth[pref])
    city[i][0] = city[i][2] # seqを最初に
    #for j in range(4): print(city[i][j],end=',') #
    
city.sort()
for i in range(M): print(city[i][3])



Measured memory_bytes: 33248
var N,M,nodes;
function main(input) {
    N = input[0].split(" ")[0]-0;
    M = input[0].split(" ")[1]-0;
    nodes = {};
    for(var i=1;i<=M;i++){
        var a = input[i].split(" ")[0]-0;
        var b = input[i].split(" ")[1]-0;
        nodes[a] = nodes[a]||[];
        nodes[b] = nodes[b]||[];
        nodes[a].push(b);
        nodes[b].push(a);
    }
    console.log(calc(nodes,1,[1]));
    
}

function calc(nodes,now,route){
    if(route.length == N){
        return 1;
    }
    var ans = 0;
    var next = nodes[now];
    for(var i=0;i<next.length;i++){
        if(route.indexOf(next[i]) == -1){
            ans += calc(nodes, next[i], route.concat(next[i]))
        }
    }
    return ans;
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))


Measured memory_bytes: 9144
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
bool comp(int a,int b){
return a>b;
}
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
int main()
{
	fast;
	ll res=INT_MAX,n,a,m,mi=INT_MAX;
	unordered_map<int,int>mp;
	cin>>n>>m;
	rep(i,0,m){
		cin>>a;
   mp[a]++;
		    	
		}
		
		rep(i,0,n+1)
		{
			if(mp[n-i]==0)
			{
				cout<<n-i<<endl;
				return 0;
			}
			if(mp[n+i]==0)
			{
				cout<<n+i<<endl;
				return 0;
			}
							
			
		}
		
		
//	cout<<res;
}



Measured memory_bytes: 3684
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

//aのp乗を求めるアルゴリズム。計算量はO(logp)
ll modpow(ll a, ll p) {
    if(p == 0) {
        return 1;
    }
    if(p%2 == 0) {
        //pが偶数の時
        ll halfP = p/2;
        ll half = modpow(a, halfP);
        //a^(p/2)をhalfとして、half*halfを計算
        return half * half % mod;
    }
    else {
        //pが奇数の時は、pを偶数にするために1減らす
        return a * modpow(a, p-1) % mod;
    }
}
 
ll Comb(ll a, ll b) {
    if(b > a-b) {
        return Comb(a, a-b);
    }
    ll ansMul = 1;
    ll ansDiv = 1;
    rep(i, b) {
        ansMul *= (a-i);
        ansDiv *= (i+1);
        ansMul %= mod;
        ansDiv %= mod;
    }
    // ansMul/ansDivをやりたい
    // ansDivの逆元を使って求めよう
    ll ans = ansMul * modpow(ansDiv, mod-2) % mod;
    return ans; 
}

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    
    ll x = modpow(2LL, n);
    ll y = (Comb(n, a) + Comb(n, b) + 1)%mod;
    ll ans = (x + mod - y)%mod; 
    
    out(ans);
    re0;
}

Measured memory_bytes: 256
import math
N, M = map(int, input().split())
p = 10**9 + 7

if abs(N-M) == 1:
  print((math.factorial(N)*math.factorial(M)) % p)
elif N-M == 0:
  print((math.factorial(N)*math.factorial(M)*2) % p)
else:
  print(0)
  

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

int main()
{
  int64_t N, Q, t, x, l, r;
  char c;
  string S;
  cin >> N >> S >> Q;
  vector<int> vc(N + 1);
  vector<set<int>> vs(30);
  queue<int> ans;
  for (int i = 1; i <= N; i++)
  {
    int ic = S.at(i - 1) - 'a';
    vc.at(i) = ic;
    vs.at(ic).insert(i);
  }
  for (int i = 0; i < Q; i++)
  {
    cin >> t;
    if (t == 1)
    {
      cin >> x >> c;
      vs.at(vc.at(x)).erase(x);
      vc.at(x) = c - 'a';
      vs.at(vc.at(x)).insert(x);
    }
    else
    {
      cin >> l >> r;
      int cnt = 0;
      for (int i = 0; i < 26; i++)
      {
        auto it = vs.at(i).lower_bound(l);
        if (it == vs.at(i).end())
          continue;
        if (*it <= r)
          cnt++;
      }
      ans.push(cnt);
    }
  }
  while (!ans.empty())
  {
    cout << ans.front() << endl;
    ans.pop();
  }
}

Measured memory_bytes: 29304
#include <iostream>

using namespace std;

int main()
{
	int paper[10][10] = {0};
	int x,y,s;
	char dummy;
	
	while ( cin >> x >> dummy >> y >> dummy >> s ) {
		switch (s) {
		case 1:
			paper[x][y]++;
			if (x>0) paper[x-1][y]++;
			if (x<9) paper[x+1][y]++;
			if (y>0) paper[x][y-1]++;
			if (y<9) paper[x][y+1]++;
			break;
		case 2:
			paper[x][y]++;
			if (x>0) {
				paper[x-1][y]++;
				if (y>0) paper[x-1][y-1]++;
				if (y<9) paper[x-1][y+1]++;
			}
			if (x<9) {
				paper[x+1][y]++;
				if (y>0) paper[x+1][y-1]++;
				if (y<9) paper[x+1][y+1]++;
			}
			if (y>0) paper[x][y-1]++;
			if (y<9) paper[x][y+1]++;
			break;
		case 3:
			if (x>1) paper[x-2][y]++;
			if (x<8) paper[x+2][y]++;
			if (y>1) paper[x][y-2]++;
			if (y<8) paper[x][y+2]++;
			paper[x][y]++;
			if (x>0) {
				paper[x-1][y]++;
				if (y>0) paper[x-1][y-1]++;
				if (y<9) paper[x-1][y+1]++;
			}
			if (x<9) {
				paper[x+1][y]++;
				if (y>0) paper[x+1][y-1]++;
				if (y<9) paper[x+1][y+1]++;
			}
			if (y>0) paper[x][y-1]++;
			if (y<9) paper[x][y+1]++;
			break;
		}
	}
	
	int zerocnt = 0;
	int maxdens = 0;
	for (int i=0; i<10; i++) {
		for (int j=0; j<10; j++) {
			if (paper[i][j]==0) zerocnt++;
			if (maxdens < paper[i][j]) maxdens = paper[i][j];
		}
	}
	
	cout << zerocnt << endl << maxdens << endl;
	
	return 0;
}

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

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

int main() {
  double pi=3.141592653589793;
  double a,b,h,m;
  double c;
  cin>>a>>b>>h>>m;
  c=sqrt(a*a+b*b-2*a*b*cos((-h*30-m/2+6*m)*2*pi/360));
  cout << fixed << setprecision(20) <<c<<endl;
}

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

using FLOW = int;
using COST = int;
const int MAX_V = 100;
const COST INF = 1000000000;

struct Edge {
    int rev, from, to;
    FLOW cap, icap;
    COST cost;
    Edge(int r, int f, int t, FLOW cp, COST cs)
        : rev(r), from(f), to(t), cap(cp), icap(cp), cost(cs) {}
};

struct Graph {
    int V;
    vector<Edge> list[MAX_V];
    Graph(int n = 0) { init(n); }
    void init(int n = 0) {
        V = n;
        for(auto &&v : list)
            v.clear();
    }
    void resize(int n = 0) { V = n; }
    void reset() {
        for(auto &&v : list)
            for(auto &&e : v)
                e.cap = e.icap;
    }
    inline vector<Edge> &operator[](int i) { return list[i]; }
    Edge &redge(Edge &e) { return list[e.to][e.rev + (e.from == e.to)]; }
    void addedge(int from, int to, FLOW cap, COST cost) {
        list[from].emplace_back(list[to].size(), from, to, cap, cost);
        list[to].emplace_back(list[from].size() - 1, to, from, 0, -cost);
    }
};

COST MinCostFlow(Graph &G, int s, int t, FLOW f) {
    COST dist[MAX_V];
    int prevv[MAX_V];
    int preve[MAX_V];
    COST res = 0;
    COST h[MAX_V];
    memset(h, 0, sizeof(h));
    using P = pair<COST, int>;
    priority_queue<P, vector<P>, greater<P>> que;
    while(f > 0) {
        fill(dist, dist + G.V, INF);
        dist[s] = 0;
        que.emplace(0, s);
        while(!que.empty()) {
            P p = que.top();
            que.pop();
            int v = p.second;
            if(dist[v] < p.first) continue;
            for(int i = 0; i < (int)G[v].size(); i++) {
                Edge &e = G[v][i];
                if(e.cap > 0 &&
                   dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]) {
                    dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
                    prevv[e.to] = v;
                    preve[e.to] = i;
                    que.emplace(dist[e.to], e.to);
                }
            }
        }
        if(dist[t] == INF) return -1;
        for(int v = 0; v < G.V; v++)
            h[v] += dist[v];
        FLOW d = f;
        for(int v = t; v != s; v = prevv[v])
            d = min(d, G[prevv[v]][preve[v]].cap);
        f -= d;
        res += h[t] * d;
        for(int v = t; v != s; v = prevv[v]) {
            Edge &e = G[prevv[v]][preve[v]];
            Edge &re = G.redge(e);
            e.cap -= d;
            re.cap += d;
        }
    }
    return res;
}

int main() {
    int n, m;
    FLOW f;
    cin >> n >> m >> f;
    Graph G(n);
    for(int i = 0; i < m; i++) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        G.addedge(a, b, c, d);
    }
    cout << MinCostFlow(G, 0, n - 1, f) << "\n";

    return 0;
}


Measured memory_bytes: 3172
#include <stdio.h>

int main(){
    int a, b, c, temp;

    scanf("%d %d %d", &a, &b, &c);

    temp = a;
    a = b;
    b = temp;

    temp = a;
    a = c;
    c = temp;

    printf("%d %d %d", a, b, c);

    return 0;
}

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

int main() {
	int a,b,c,k,numa=0,numb=0,ans=0;
	cin>>a>>b>>c>>k;
	int flag=0;
	
	if(a<k){
		ans=ans+a;
		k=k-a;
	}else{
		ans=ans+k;
		flag=1;
	}
	if(flag==0){
		if(b<k){
			k=k-b;
		}else{
			flag=1;
		}
	}
	
	if(flag==0){
		if(c<k){
			ans=ans-c;
		}else{
			ans=ans-k;
		}
	}
	
	cout<<ans<<endl;
	
	// your code goes here
	return 0;
}

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

int main() {
  int N, K, t, p[1000], count = 0;
  cin >> N>> K;
  for (int i = 0; i < N; i++){
    cin >> t;
    p[i] = t;
  }
  sort(p, p+N);
  for(int j = 0; j<K; j++){
  	count += p[j];
  }
  
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 3628
def main():
    n = int(input())
    h_list = list(map(int, input().split()))

    ans = 0
    temp_max = 0
    for i in range(n-1):
        if h_list[i] >= h_list[i+1]:
            temp_max += 1
        else:
            temp_max = 0
        ans = max(ans, temp_max)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 63984
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x


a, b = [int(x) for x in input().split(' ')]

g = gcd(a, b)
ret = 1
i = 2
while i * i <= g:
    if g % i == 0:
        while g % i == 0:
            g /= i
        ret += 1
    i += 1

if g > 1:
    ret += 1

print(ret)

Measured memory_bytes: 3064
n=int(input())
A=list(map(int,input().split()))
def gcd(a,b):
  if a<=b:
    a,b=b,a
  if a%b==0:
    return b
  else:
    return gcd(b,a%b)
L,R=[],[]
ld,rd=A[0],A[n-1]
for i in range(n):
  ld=gcd(ld,A[i])
  rd=gcd(rd,A[n-1-i])
  L.append(ld)
  R.append(rd)
ans=max(L[-2],R[-2])
for i in range(1,n-1):
  ans=max(ans,gcd(L[i-1],R[n-i-2]))
print(ans if n!=2 else max(A))

Measured memory_bytes: 14076
input1 = input().split()
A = input1[0]
s = input1[1]
C = input1[2]
listA = [str(x) for x in A]
listS = [str(y) for y in s]
listC = [str(z) for z in C]
print(listA[0] + listS[0] + listC[0])

Measured memory_bytes: 3060
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-04-12 12:47:37
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rev(x) greater<x>()
#define MOD 1000000007
#define INF 1000000000

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

LL modpower(LL n, LL m, LL mod)
{
    if (m == 0) {
        return 1;
    } else if (m % 2 == 0) {
        LL p = modpower(n, m/2, mod);
        return p*p % mod;
    } else {
        return n*modpower(n, m-1, mod) % mod;
    }
}

LL modinv(LL n, LL mod)
{
    return modpower(n, mod-2, mod);
}

LL modcombination(LL n, LL r, LL mod)
{
    LL ret = 1;

    for (int i = 0; i < r; i++) {
        ret *= (n-i);
        ret %= mod;
        ret *= modinv(i+1, mod);
        ret % mod;
    }

    return ret % mod;
}

int gcd(int k, int l)
{
    if (l > 0) return gcd(l, k%l);
    else return k;
}

struct UnionFind
{
    vector<int> par;

    UnionFind(int n) : par(n) {
        for (int i = 0; i < n; i++) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

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

    LL ans = 0;
    for (int i = 1; i <= sqrt(n); i++) {
        ans = i*i;
    }

    cout << ans << endl;

    return 0;
}


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

#define MAX_N 100
int n,m;
bool G[MAX_N][MAX_N];
bool used[MAX_N];
void dfs(int v){
	used[v]=true;
	for(int i=0;i<n;i++){
		if(!used[i] && G[v][i])dfs(i);
	}
	return;
}

int from[MAX_N];
int to[MAX_N];

	
void solve(){
	int a,b,ans=0;
	scanf("%d %d",&n,&m);
	for(int i=0;i<m;i++){
		scanf("%d %d",&a,&b);
		from[i]=a-1;
		to[i]=b-1;
		G[from[i]][to[i]]=true;
		G[to[i]][from[i]]=true;
	}
	for(int i=0;i<m;i++){
		G[from[i]][to[i]]=false;
		G[to[i]][from[i]]=false;
		dfs(0);
		for(int j=0;j<n;j++){
			if(!used[j]) {
				ans++;
				break;
			}
		}
		memset(used,0,sizeof(used));
		G[from[i]][to[i]]=true;
		G[to[i]][from[i]]=true;
	}
	printf("%d\n",ans);
}

int main(){
	solve();
	return 0;
}


Measured memory_bytes: 256
import fractions as f

n = int(input())
A = [int(_) for _ in input().split()]

left = []
right = []

left.append(A[0])
for i in range(1,n):
    left.append(f.gcd(left[i-1],A[i]))

right.append(A[n-1])
for i in range(1,n):
    right.append(f.gcd(right[i-1],A[n-1-i]))

ans = 0
for i in range(n):
    if i == 0:
        ans = right[n-2]
    if i >= 1 and i <= n-2:
        ans = max(ans,f.gcd(left[i-1],right[n-2-i]))
    if i == n-1:
        ans = max(ans,left[n-2])
print(ans)

Measured memory_bytes: 16124
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 first = br.readLine();
		int[] a = new int[Integer.parseInt(first)];
		String str = br.readLine();
		String[] stra = str.split(" ");
		for (int i = 0 ; i < a.length ; i++){
			a[i] = Integer.parseInt(stra[i]);
		}
		for (int i = a.length-1 ; i >= 0 ; i--){
			System.out.print(a[i]);
			if ( i == 0) break;
			System.out.print(" ");
		}
		System.out.println();
	}

}

Measured memory_bytes: 16912
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
#include <numeric>
#include <iomanip>
using namespace std;
#define mod (long)(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr start, itr goal){ for(auto i = start; i != goal; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<long> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } long C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

int main(){
    int N, M;
    cin >> N >> M;
    long X[M];
    cins(X, X + M);
    sort(X, X + M);
    long diff[M - 1];
    for(int i = 1; i < M; i++){
        diff[i - 1] = X[i] - X[i - 1];
    }
    sort(diff, diff + M - 1);
    cout << accumulate(diff, diff + max(0, M - N), 0l) << endl;
}


Measured memory_bytes: 1792
X;//[bgÌÚÌ(1~4)
Y;//}XÌ-1(=S[Ì}XÔ)(1~50)
Z;//Cxg}XÌ(0~Y-1)
V[4];//[bgÌÚ
E[51];//Cxg}XÌíÞ
A[51];//Cxg}XÌl
double P0[51][4901];//óÔÌ­¶m¦[}XÔ][à]
double P1[51][4901];
main(){
	int i,p,m,u,p0,p1,m1;
	double dp,sum;
	for(;scanf("%d%d%d",&X,&Y,&Z),X;){
		memset(E,0,sizeof(E));
		memset(P0,0,sizeof(P0));
		memset(P1,0,sizeof(P1));
		for(i=0;i<X;i++)
			scanf("%d",V+i);
		for(i=0;i<Z;i++){
			int n,e,a;
			scanf("%d%d%d",&n,&e,&a);
			E[n]=e;
			A[n]=a;
		}
		P0[0][0]=1;
		for(u=1,p0=0;u;p0++){
			u=0;
			for(p=p0;p<Y;p++){
				for(m=0;m<=p*100;m++){
					if(P0[p][m]){
						dp=P0[p][m]/X;
						u=1;
						for(i=0;i<X;i++){
							p1=p+V[i];
							m1=m;
							if(p1>=Y){
								p1=Y;
							}else{
								if(E[p1]){
									switch(E[p1]){
									case 1://æÖiÞ
										p1+=A[p1];
										if(p1>=Y)
											p1=Y;
										break;
									case 2://àzð¾é
										m1+=A[p1];
										break;
									case 3://àzðx¥¤
										m1-=A[p1];
										if(m1<0)
											m1=0;
										break;
									}
								}
							}
							P1[p1][m1]+=dp;
						}
					}
				}
			}
			memcpy(P0,P1,sizeof(*P0)*Y);
			memset(P1,0,sizeof(*P1)*Y);
		}
		sum=0;
		for(m=0;m<=4900;m++){
			sum+=P1[Y][m]*m;
		}
		printf("%d\n",(int)sum);
	}
	exit(0);
}

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

#define online_judge			freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fastio					ios::sync_with_stdio(false);cin.tie(0);
#define ll                      long long
#define pii                     pair<int, int>
#define pli                     pair<ll, int>
#define pil                     pair<int, ll>
#define pll                     pair<ll, ll>
#define vi                      vector<int>
#define vll                     vector<ll>
#define vb                      vector<bool>
#define vd                      vector<double>
#define vs                      vector<string>
#define ff                      first
#define ss                      second
#define pb                      push_back
#define eb                      emplace_back
#define ppb                     pop_back
#define pf                      push_front
#define ppf                     pop_front
#define vpii                    vector<pii>
#define vpll                    vector<pll>
#define umap                    unordered_map
#define all(x)                  x.begin(),x.end()
#define clr(a,b)                memset(a,b,sizeof a)
#define fr(i, n)                for(ll i=0; i<n;++i)
#define fr1(i, n)               for(ll i=1; i<=n; ++i)
#define rfr(i, n)                for(ll i=n-1; i>=0; --i)
#define precise(x)              cout<<fixed<<setprecision(x)
#define wh                        while
#define mp                        make_pair
#define le                        length()


ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

ll lcm(ll a,ll b) 
{ return (a*b)/__gcd(a,b); }

ll power(ll x,ll y,ll p) 
{ ll res=1; x=x%p;
    while(y>0) 
    { if (y&1) res=(res*x)%p; 
      y=y>>1; x=(x*x)%p; } 
    return res; } 
    
bool inside(ll x,ll y,ll n,ll m)
{
    return(x>=0&&x<n&&y>=0&&y<=m);
}   

void solve()
{    
	ll n;
	cin>>n;
	
	vll a;
	ll ma=0,in=0,p=-1,y=1000,s=0;
	fr(i,n)
	{
		ll e;
		cin>>e;
		if(p!=e)
		{
			a.pb(e);
			p=e;
		}
		
	}
	n=a.size();
	if(n==1)
	{
		cout<<"1000"<<endl;
		return;
	}
	
	fr(i,n)
	{
		if(i==0)
		{
			if(a[i]>a[i+1])
			{
				in=i;
			}
		}
		
		else if(i==n-1)
		{
			if(a[i]>a[i-1])
			{
				in=i;
			}
		}
		else
		{
			if(a[i]>a[i-1]&&a[i]>a[i+1])
			{
				in=i;
			}
		}
	}
	
	if(in==0)
	{
		cout<<"1000"<<endl;
		return;
	}
	
	fr(i,in+1)
	{
		if(i==0)
		{
			if(a[i+1]>a[i])
			{
				s=y/a[i];
				y-=a[i]*(y/a[i]);
			}
		}
		
		else if(i==in)
		{
			y+=s*a[i];
			s=0;	
		}
		
		else
		{
			if(a[i]>a[i-1]&&a[i]>a[i+1])
			{
				y+=s*a[i];
				s=0;
			}
			else if(a[i]<a[i-1]&&a[i]<a[i+1])
			{
				s=y/a[i];
				y-=a[i]*(y/a[i]);
			}
		}	
	}
	cout<<y<<endl;

}
	

int main()
{
    fastio
//	int t;
//  	cin>>t;
//	fr1(i,t)
    {
//    	cout<<"Case "<<i<<":"<<endl;
        solve();
    }
    
	return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pint pair<int, int>
#define pll pair<ll, ll>
#define vint vector<int >
#define vll vector<ll >
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i,n) for (int i = 0; i < (n); ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    vint v(5);
    REP(i,5) cin >> v[i];
    REP(i,5){
        if(v[i] == 0){
            cout << i+1 << "\n";
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstring>
#include <map>
using namespace std;

int main()
{
  cout << setprecision(6);
  cout << setiosflags(ios::scientific);
  cout.flags(ios::fixed);


  while(true)
    {
      int m,f,r;
      cin >> m >> f >> r;
      int sum = m+f;

      if(m==-1&&f==-1 && r==-1)
	break;

      if(m==-1 || f == -1)
	cout << "F";
      else if(sum>=80)
	cout << "A";
      else if(sum >= 65)
	cout << "B";
      else if(sum >= 50)
	cout << "C";
      else if(sum >= 30 && r >= 50)
	cout << "C";
      else if(sum >=30)
	cout << "D";
      else 
	cout << "F";

      cout << endl;
    }

  }

Measured memory_bytes: 1152
#include <stdio.h>

int str_length(const char s[])
{
    int len = 0;
    while (s[len])
        len++;
    return len;
}

int main()
{
    char a[100];
    int i;

    scanf("%s", a);
    int length = str_length(a);
    printf("%c%d%c", a[0], length-2, a[length-1]);


    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>

int main(){
  std::string s;
  std::cin >> s;
  int c = 0;

  for(int i=0; i<s.size()/2; i++){
    if(s[i] != s[s.size()-1-i]) c++;
  }
  std::cout << c ;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
int arr[9], N, P[9], Q[9], s, t;
bool flg[9];
void dfs(int x){
	if(x == N){
		bool p=true, q = true;
		for(int i=0; i<N; i++){
			if(P[i] > arr[i])break;
			if(P[i] < arr[i]){
				p = false;
				break;
			}
		}
		for(int i=0; i<N; i++){
			if(Q[i] > arr[i])break;
			if(Q[i] < arr[i]){
				q = false;
				break;
			}
		}
		s += p;
		t += q;
	}
	for(int i=0; i<N; i++){
		if(!flg[i]){
			flg[i] = true;
			arr[x] = i + 1;
			dfs(x + 1);
			flg[i] = false;
		}
	}
	return;
}
int main(){
	scanf("%d", &N);
	for(int i=0; i<N; i++)scanf("%d", P+i);
	for(int i=0; i<N; i++)scanf("%d", Q+i);
	dfs(0);
	printf("%d\n", abs(s - t));
	return 0;
}


Measured memory_bytes: 1736
#include <iostream>
#include <vector>
using namespace std;
typedef long long i64;
const int MAXN = 2e5 + 10;

int N;
vector<int> Adj[MAXN];
int sz[MAXN], Lo[MAXN], mx1st[MAXN], mx2nd[MAXN];
char color[MAXN];
i64 answer;

inline void addEdge(int u, int v)
{
	Adj[u].push_back(v);
	Adj[v].push_back(u);
}

void DFS(int cur, int fa = 0)
{
	sz[cur] = (color[cur] == '1');
	Lo[cur] = (sz[cur] ? 0 : 0x7F7F7F7F);

	for (const int & to : Adj[cur])
	{
		if (to == fa)
			continue;
		DFS(to, cur);

		int tmp = mx1st[to] + 1;
		if (tmp > mx1st[cur])
			mx2nd[cur] = mx1st[cur], mx1st[cur] = tmp;
		else
			mx2nd[cur] = max(mx2nd[cur], tmp);

		if (sz[to])
			sz[cur] += sz[to], Lo[cur] = min(Lo[cur], tmp);
	}
}

void solve(int cur, int fa = 0)
{
	if (fa)
	{
		int tmp = (mx1st[fa] == mx1st[cur] + 1 ? mx2nd[fa] : mx1st[fa]) + 1;
		if(tmp > mx1st[cur])
			mx2nd[cur] = mx1st[cur], mx1st[cur] = tmp;
		else
			mx2nd[cur] = max(mx2nd[cur], tmp);
		if(sz[1] - sz[cur])
			Lo[cur] = min(Lo[cur], tmp);
	}

	int delta = min(mx2nd[cur] + 1, mx1st[cur] - 1) - Lo[cur] + 1;
	if(delta > 0)
		answer += delta;

	for(const int & to : Adj[cur])
		if(to != fa)
			solve(to, cur);
}

int main()
{
	int u, v;
	ios::sync_with_stdio(false), cin.tie(nullptr);

	cin >> N ;
	for(int i = 1; i < N; i++)
		cin >> u >> v , addEdge(u, v);
	cin >> (color + 1);

	DFS(1), solve(1);

	cout << answer + 1 << endl ;

	return 0;
}


Measured memory_bytes: 21632
N = int(input())
dp = [[0 for i in range(3)] for _ in range(N+1)] 

for i in range(1,N+1):
  ai,bi,ci = map(int,input().split())
  
  dp[i][0] = ai + max(dp[i-1][1],dp[i-1][2])
  dp[i][1] = bi + max(dp[i-1][0],dp[i-1][2])
  dp[i][2] = ci + max(dp[i-1][1],dp[i-1][0])
  
print(max(dp[N]))
  


Measured memory_bytes: 24308
# -*- coding: utf-8 -*-
"""
AtCoder A
"""

def main():
    A,B,C=list(map(int,input().split()))
    if A<C and C<B:
        print("Yes")
    elif A>C and C>B:
        print("Yes")
    else:
        print("No")
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 38512
import Foundation

let s = readLine()!
var ans = 999
for i in 0..<s.count-2 {
  let from = s.index(s.startIndex, offsetBy: i)
  let to = s.index(from, offsetBy: 2)
  let sub = String(s[from...to])
  ans = min(ans, abs(753 - Int(sub)!))
}
print(ans)

Measured memory_bytes: 13116
#include <iostream>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a * b / gcd(a, b); }

#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(long i=s;i<e;i++)
#define repeq(i,s,e) for(long i=s;i<=e;i++)


int main() {
	ll n;
	double ans;
	in(n);

	ans = n / 2;
	if (n % 2 == 1) {
		ans++;
	}

	outn(ans / n);

	return 0;

}


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

typedef long long LL;

int T, a, b, c, d, k;

bool check(int x) {
	return b - (x - 1) / k <= (LL)(a - x + 1) * k;
}
int main() {
	scanf("%d", &T);
	for (int cs = 1; cs <= T; cs++) {
		scanf("%d%d%d%d", &a, &b, &c, &d);
		k = (std::max(a, b) - 1) / (std::min(a, b) + 1) + 1;
		// printf("k = %d\n", k);
		int ans = -1;
		for (int l = 0, r = a; l <= r; ) {
			int mid = (l + r) >> 1;
			check(mid) ? l = (ans = mid) + 1 : r = mid - 1;
		}
		ans += (ans - 1) / k;
		for (int i = c; i <= std::min(ans, d); i++) {
			putchar(i % (k + 1) == 0 ? 'B' : 'A');
		}
		for (int i = std::max(ans + 1, c); i <= d; i++) {
			putchar((a + b - i + 1) % (k + 1) == 0 ? 'A' : 'B');
		}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#define fi first
#define se second
#define pb(i) push_back(i)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define mes(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 2e6+10;
const int INF = 0x3f3f3f3f;
const int inf = - INF;
const int mod = 1e9+7;
const double pi = acos(-1.0);

int p[N];
double kp[1010];
int sum[N];
int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    rep(i,1,1005){
        kp[i]=(double)(0.50*(double)(i*1.0+1.0));
    }
    rep(i,1,n){
        scanf("%d",&p[i]);
        sum[i]=sum[i-1]+p[i];
    }
    int maxl=0,maxr=0;
    int maxn=0;
    double res=0;
    rep(i,0,n-k){
        if(sum[i+k]-sum[i]>maxn){
            maxn=sum[i+k]-sum[i];
            maxl=i+1,maxr=i+k;
        }
    }
    rep(i,maxl,maxr){
        res+=(double)kp[p[i]];
    }
    printf("%.12f\n",res);
    return 0;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
#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 all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define do long double
void remax(int a, int b) { 
if (a < b)
a = b; }
  void remin(int a, int b) { 
if (a > b) 
a = b; }
using namespace std;
signed main(){
  int a,b;
  cin>>a>>b;
  vector<P> c(b);
  rep(i,b)
    cin>>c[i].second>>c[i].first;
  sort(all(c));
  int d=1;
  int e=c[0].first;
  rep(i,b){
    if(c[i].second>=e){
      e=c[i].first;
       d++;
      }
  }
  cout<<d<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <cmath>
#define INF 100000000
using namespace std;
#define pw(a) (a)*(a)

int main(){
  double x1,x2,x3,y1,y2,y3;
  int n;
  cin >> n;
  while(n--){
    cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
    double a,b,l,m,n;
    a = -1*(pw(x1) - pw(x2) + pw(y1) - pw(y2));
    b = -1*(pw(x1) - pw(x3) + pw(y1) - pw(y3));
    l = (a*(y1-y3)-b*(y1-y2))/((y1-y3)*(x1-x2)-(x1-x3)*(y1-y2));
    m = ((x1-x3)*a - (x1-x2)*b)/((x1-x3)*(y1-y2)-(y1-y3)*(x1-x2));
    n = -1*(pw(x1) + pw(y1)+ l*x1 + m*y1);
    printf("%.3f %.3f %.3f\n",-l/2.0,-m/2.0,sqrt((pw(l) + pw(m) - 4*n))/2.0);
  }
  return 0;
}

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

using namespace std;
typedef unsigned long ul;
typedef pair<ul, ul> P;

int main(){
    string str[50];
    int H,W;
    int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
    int dy[8] = {1, 1, 1, 0, 0, -1, -1, -1};

    cin >> H >> W;

    rep(i, H){
        cin >> str[i];
    }

    rep(i, H){
        rep(j, W){
            if(str[i][j] == '#')
                continue;

            int sum = 0;
            rep(k, 8){
                int di = i + dx[k];
                int dj = j + dy[k];

                if (di < 0 || di >= H) continue;
                if (dj < 0 || dj >= W) continue;
                if (str[di][dj] == '#') sum++;
            }
            str[i][j] = char(sum + '0');
        }
    }

    rep(i, H) cout << str[i] << endl;
} 

Measured memory_bytes: 256
#include <stdio.h>

int count;
int solve(int i, int c, int n, int s, int sum) {
	if(c == n) {
		if(s == sum) {
			count++;
		}
		return;
	}
	
	if(i > 9) return;
	solve(i+1, c+1, n, s, sum+i);
	solve(i+1, c, n, s, sum);
}

int main(void) {
	int n, s;
	while(scanf("%d %d\n", &n, &s)==2) {
		if(n == 0 && s == 0) break;
		
		count = 0;
		solve(0, 0, n, s, 0);
		printf("%d\n", count);
	}
	return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1012345678;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

int main() {
 int N, D; cin >> N >> 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 ans = 0;
 for (int i = 0; i < N; ++i) {
 for (int j = i+1; j < N; ++j) {
 int norm = 0;
 for (int k = 0; k < D; ++k) {
 int diff = abs(X[i][k] - X[j][k]);
 norm += diff * diff;
 }
 // check whether norm = k for some k
 bool flag = false;
 for (int k = 0; k <= norm; ++k) {
 if (k * k == norm) {
 flag = true;
 }
 }
 if (flag) ++ans;
 }
 }
 cout << ans << endl;
 }


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

int main() {
    int N;
    cin >> N;
    for(int a = 0; a <= N / 7; a++) {
        if((N - 7 * a) % 4 == 0){
            puts("Yes");
            goto FIND;
        }
    }
    puts("No");
    FIND :
    return 0;

}

Measured memory_bytes: 256