akhauriyash/Code-Regression huggingface dataset:
use std::io::*;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let p: Vec<f64> = (0..n).map(|_| read()).collect();

    // dp[i][j] = iまででj枚表
    let mut dp: Vec<Vec<f64>> = vec![vec![0_f64; n+1]; n+1];
    dp[0][0] = 1_f64;
    for i in 0..n {
        for j in 0..n {
            dp[i+1][j+1] += dp[i][j] * p[i];
            dp[i+1][j] += dp[i][j] * (1_f64-p[i]);
        }
    }
    let mut ans: f64 = 0_f64;
    for i in 0..n+1 {
        if i * 2 >= n {
            ans += dp[n][i];
        }
    }
    println!("{}", ans);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .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: 90364
def gcd(a, b):
    if b == 0:
        return a;
    return gcd(b, a % b);

n = int(input());

res = 0;

for a in range(1, n + 1):
    for b in range(1, n + 1):
        g = gcd(a, b);
        for c in range(1, n + 1):
            res += gcd(g, c);

print(res);


Measured memory_bytes: 75140
#include <iostream>
#include <fstream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
int main()
{
	int n; cin >> n;
	vector<int> a(n);
	rep(i,n)cin>>a[i];
	a.push_back(0);
	a.insert(a.begin(),0);
	int sum = 0;
	n+=2;
	rep(i,n-1)
	{
		sum += abs(a[i]-a[i+1]);
	}
	for(int i = 1;i<n-1;i++)
	{
		if(a[i]>=a[i-1]&&a[i]<=a[i+1])
		{
			cout<<sum<<endl;
		}
		else if(a[i]<=a[i-1]&&a[i]>=a[i+1])
		{
			cout<<sum<<endl;
		}
		else if(a[i]>=a[i-1]&&a[i]>=a[i+1])
		{
			cout<<sum-abs(a[i]-a[i-1])-abs(a[i]-a[i+1])+abs(a[i-1]-a[i+1])<<endl;
		}
		else if(a[i]<=a[i-1]&&a[i]<=a[i+1])
		{
			cout<<sum-abs(a[i]-a[i-1])-abs(a[i]-a[i+1])+abs(a[i-1]-a[i+1])<<endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1656
#![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()
        })*
    };
}

fn main() {
    let v = read_vec::<i64>();
    let (n, x) = (v[0] as usize, v[1]);
    let mut tests = vec![];
    for _ in 0..n {
        let v = read_vec::<i64>();
        let (b, l, u) = (v[0], v[1], v[2]);
        let gain = (x - b) * u + b * l;
        tests.push((gain, b, l, u));
    }
    tests.sort();
    tests.reverse();
    let mut lost_sum = vec![0; n + 1];
    for i in 0..n {
        lost_sum[i + 1] = lost_sum[i] + tests[i].1 * tests[i].2;
    }
    let mut gain_sum = vec![0; n + 1];
    for i in 0..n {
        gain_sum[i + 1] = gain_sum[i] + (x - tests[i].1) * tests[i].3;
    }
    let mut should_win_num = 0;
    for i in 1..n + 1 {
        if gain_sum[i] >= lost_sum[n] - lost_sum[i] {
            should_win_num = i - 1;
            break;
        }
    }

    let initial_gain = gain_sum[should_win_num];
    let initial_lost = lost_sum[n] - lost_sum[should_win_num];
    // debug!(should_win_num, initial_gain, initial_lost);

    let mut min_point = x;
    for i in 0..n {
        let (current_gain, b, l, u) = (tests[i].0, tests[i].1, tests[i].2, tests[i].3);
        let current_lost = b * l;
        let residual;

        if i >= should_win_num {
            residual = (initial_lost - current_lost) - initial_gain;
        } else {
            residual = (initial_lost - current_lost) - initial_gain - tests[should_win_num].0
                + current_gain;
        }

        let mut point: i64 = x + 1;
        if residual <= 0 {
            point = b + (residual) / l;
        } else if (x - b) * u >= residual {
            // must win so we use u
            point = b + (residual + (u - 1)) / u;
        }
        // debug!(residual, point);
        min_point = min(min_point, point);
    }
    assert!(min_point <= x);
    println!("{:?}", (should_win_num as i64) * x + min_point);
}

fn binary_search<F>(lb: usize, ub: usize, criterion: F) -> usize
where
    F: Fn(usize) -> bool,
{
    let mut lb = lb;
    let mut ub = ub;
    while ub - lb > 1 {
        let mid = (ub + lb) / 2;
        if criterion(mid) {
            lb = mid;
        } else {
            ub = mid;
        }
    }
    lb
}

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: 10308
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n,t,a;
    cin >> n >> t >> a;
    vector<double> h(n);
    double min = 1e9;
    int ans;
    for(int i = 0;  i < n; i++){
        int h;
        cin >> h;
        if(abs(a-(t-h*0.006)) < min){
            min = abs(a-(t-h*0.006));
            ans = i + 1;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
using ll =long long;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
const ll INF = 1LL << 60;
const int mod = 1e9+7;
//Write From this Line

int main()
{
	int n ;
	cin >> n ;
	vector<int> a(n);
	rep(i,n) cin >>a[i];
	SORT(a);
	ll ans = INF ;
	for(int i = 1 ; i <= 100 ; i++){
		ll tmp = 0;
		rep(j,n){
			tmp += (a[j] - i) * (a[j] - i);
		}
		chmin(ans,tmp);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

const int MOD=1'000'000'007;
int N,M;
int a[100001];
int dp[100001];

int main(){
    cin>>N>>M;
    rep(i,M){
        int x;
        cin>>x;
        a[x]=1;
    }

    dp[0]=1;
    dp[1]=1;
    if(a[1]==1) dp[1]=0;
    for(int i=2;i<=N;i++){
        dp[i]=(dp[i-2]+dp[i-1])%MOD;
        if(a[i]==1) dp[i]=0;
    }

    cout<<dp[N]<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define int long long
#define INF 1000000000000000000
using namespace std;

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
template<typename T>
void debug(vector<vector<T>> m){ REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;} }

class CHT{
    using T = int;
    T id = -INF;

    struct line{
        T a, b;
        line(T a, T b): a(a), b(b){}
        T get(T x){return a * x + b;}
    };
    struct node{
        line l;
        node *lch, *rch;
        node(line l): l(l), lch(nullptr), rch(nullptr){}
    };

public:
    int n;
    vector<T> pos;
    node *root;
    bool calcMax;

    CHT(vector<T> pos, bool calcMax = true): n(pos.size()), pos(pos), root(nullptr), calcMax(calcMax){}

    node* modify(node *p, int lb, int ub, line &l){
        if(!p) return new node(l);
        if(p->l.get(pos[lb]) >= l.get(pos[lb]) && p->l.get(pos[ub]) >= l.get(pos[ub])) return p;
        if(p->l.get(pos[lb]) <= l.get(pos[lb]) && p->l.get(pos[ub]) <= l.get(pos[ub])){
            p->l = l;
            return p;
        }

        int c = (lb + ub) / 2;
        if(p->l.get(pos[c]) < l.get(pos[c])) swap(p->l, l);
        if(p->l.get(pos[lb]) <= l.get(pos[lb])) p->lch = modify(p->lch, lb, c, l);
        else p->rch = modify(p->rch, c + 1, ub, l);

        return p;
    }

    T sub(node *p, int lb, int ub, int t){
        if(!p) return id;
        if(ub - lb == 0) return p->l.get(pos[t]);
        int c = (lb + ub) / 2;
        if(t <= c) return max(p->l.get(pos[t]), sub(p->lch, lb, c, t));
        else return max(p->l.get(pos[t]), sub(p->rch, c + 1, ub, t));
    }

    void insert(T a, T b){
        if(!calcMax){a *= -1; b *= -1;};
        line l(a, b);
        root = modify(root, 0, n - 1, l);
    }

    T get(T x){
        int t = Lower_bound(pos, x);
        assert(t < n && pos[t] == x);
        T res = sub(root, 0, n - 1, t);
        if(!calcMax) res *= -1;
        return res;
    }
};


signed main(){

    int N, C; cin >> N >> C;
    vec h(N);
    readv(h);
    vec dp(N);
    CHT cht(h, false);
    dp[0] = 0;
    FOR(i, 1, N){
        cht.insert(-2 * h[i - 1], dp[i - 1] + h[i - 1] * h[i - 1] + C);
        dp[i] = cht.get(h[i]) + h[i] * h[i];
    }
    cout << dp[N - 1] << endl;

    return 0;
}


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

int main(){
    ll n,k; cin>>n>>k;
    const ll mod = 998244353;
    vector<pair<ll,ll>> s(k);
    rep(i,k) cin>>s[i].first>>s[i].second;
    vector<ll> dp(n+1,0);
    dp[0] = 1;
    dp[1] = -1;
    rep(i,n){
        ll now = dp[i] = (dp[i]%mod+mod)%mod;
        dp[i+1] += now;

        rep(j,k){
            ll l = s[j].first;
            ll r = s[j].second;
            if(i+l<n) dp[i+l] += now;
            if(i+r<n) dp[i+r+1] -= now;
        }
    }
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 4800
n = int(input())
x = list(map(float, input().split()))
y = list(map(float, input().split()))

res = 0
for i in range(n):
    res += abs(x[i] - y[i])

print(res)

res = 0
for i in range(n):
    res += (x[i] - y[i]) ** 2

print(res ** (1/2))

res = 0
for i in range(n):
    res += abs(x[i] - y[i]) ** 3

print(res ** (1/3))

res = 0
for i in range(n):
    res = max(res, abs(x[i] - y[i]))

print(res)



Measured memory_bytes: 5660
package main

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

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

func main() {
	defer write.Flush()

	var n int
	fmt.Fscan(read, &n)

	cnt := 0
	mi := 300000
	for i := 0; i < n; i++ {
		var a int
		fmt.Fscan(read, &a)

		if mi > a {
			cnt++
			mi = a
		}
	}
	fmt.Fprintln(write, cnt)
}


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

typedef long long ll;

ll N;
vector<int> A;

void calcu(void) {
	ll x = N - 1;
	A.clear();
	while (x >= 0) {
		int r = (int)(x % 26);
		A.push_back(r);
		x /= 26;
		--x;
	}
}

string solve(void) {
	string ret = "";
	for (int i = (int)A.size() - 1; i >= 0; --i) {
		char c = A[i] + 'a';
		ret += c;
	}
	return ret;
}

int main(void) {
	cin >> N;
	calcu();
	string ans = solve();
	cout << ans << '\n';
	return 0;
}


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

int main(){
	string str;
	string::reverse_iterator ri;
	while(cin>>str){
		ri=str.rbegin();
		while(ri!=str.rend()){
			cout<<*ri;
			++ri;
		}
		cout<<endl;
	}
	return 0;
}

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

int main(){
    ll h,w,ans=0,tmp=0;
    cin>>h>>w;
    int LR[2200][2200]={0},RL[2200][2200]={0},UD[2200][2200]={0},DU[2200][2200]={0};
    string s[h];
    rep(i,0,h)cin>>s[i];

    rep(i,0,h)if(s[i][0]=='.')LR[i][0]=1;
    rep(i,0,w)if(s[0][i]=='.')UD[0][i]=1;
    
    rep(i,0,h){
        rep(j,1,w){
            if(s[i][j]=='.')LR[i][j]=LR[i][j-1]+1;
            else LR[i][j]=0;
        }
        irep(j,w-1,0){
            if(s[i][j]=='.')RL[i][j]=RL[i][j+1]+1;
            else RL[i][j]=0;
        }
    }

    rep(i,0,w){
        rep(j,1,h){
            if(s[j][i]=='.')UD[j][i]=UD[j-1][i]+1;
            else UD[j][i]=0;
        }
        irep(j,h-1,0){
            if(s[j][i]=='.')DU[j][i]=DU[j+1][i]+1;
            else DU[j][i]=0;
        }
    }

     rep(i,0,h){
        rep(j,0,w){
            tmp=0;
            if(s[i][j]=='.')tmp=LR[i][j]+RL[i][j]+UD[i][j]+DU[i][j]-3;
            ans=max(ans,tmp);
        }
    }
    cout<<ans;
}

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

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

using namespace std;

ll cal(ll k){
    ll sum = 0;
    for (ll i = 1; i <= k; ++i)
    {
        sum += i;
    }
    if(k <= 0) return 0;
    else return sum;
}

int main() {

    string s; cin >> s;
    int n = s.length();
    int c = 2;
    int mid = 0;


    while(1){
        mid = (n-c)/2;

        if(s.substr(0,mid) == s.substr(mid,mid)){
            break;
        }
        c += 2;
    }

    cout << n-c;


    return 0;
}











Measured memory_bytes: 3616
import std.stdio;
import std.ascii;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.random;
import std.regex;
import std.typecons;

struct P {
    int id, score;
}

void main() {
    auto map = redBlackTree!("a[0] < b[0]", false, Tuple!(int, int));
    string s;
    P[] ps;
    while (true) {
        s = readln.chomp;
        if (s == "0,0") break;
        auto t = s.split(",").map!(to!int);
        int id = t[0],
            score = t[1];
        ps ~= P(id, score);
    }
    ps.sort!"a.score > b.score";
    int prev_score = ps[0].score;
    int cur_rank = 1;
    for (int i = 0; i < ps.length; i++) {
        if (prev_score == ps[i].score) {
            map.insert(tuple(ps[i].id, cur_rank));
        } else {
            cur_rank++;
            map.insert(tuple(ps[i].id, cur_rank));
            prev_score = ps[i].score;
        }
    }
    while (true) {
        s = readln.chomp;
        if (stdin.eof) break;
        int x = s.to!int;
        writeln(map.equalRange(tuple(x, -1)).front[1]);
    }
}

Measured memory_bytes: 1148
import sys
input = lambda: sys.stdin.readline().rstrip()
inpl = lambda: list(map(int,input().split()))
N, M = inpl()
AB = []
children = [set() for _ in range(N)]
parents = [set() for _ in range(N)]
for _ in range(N+M-1):
    A, B = inpl()
    A -= 1
    B -= 1
    children[A].add(B)
    parents[B].add(A)

parent = [-1]*N
pool = list(range(N))
L = []
visited = [False]*N
while pool:
    i = pool.pop()
    if i >= N:
        L.append(i-N)
    elif visited[i]:
        continue
    else:
        visited[i] = True
        pool.append(i+N)
        for c in children[i]:
            pool.append(c)
L = L[::-1]
position = [None]*N
for i in range(N):
    position[L[i]] = i
for i in range(N):
    if not parents[i]:
        print(0)
    else:
        print(L[max(position[c] for c in parents[i])]+1)

Measured memory_bytes: 101840
n,a,b=map(int,input().split())
ans=[0]*37
def ssum(n):
  li=list(str(n))
  ret=0
  for i in li:
    ret+=int(i)
  return(ret)
  
while n!=0:
  ans[ssum(n)]+=n
  n-=1

print(sum(ans[a:b+1]))

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

#define LL long long

LL simplified_mahjong(vector<int> v){

	LL count = 0;
	int remain = 0;

	for (int i = 0; i < v.size(); ++i) {
		if(remain > 0 && v[i] > 0)
		{
			v[i]--;
			count++;
		}
		count += (v[i]/2);
		remain = (v[i]%2);
	}
	return count ;
}

int main (){
	vector<int> v;
	int n, x ;
	cin >> n ;
	for (int i = 0; i < n; ++i) {
		cin >> x;
		v.push_back(x);
	}
	cout << simplified_mahjong(v);
	return 0 ;
}


Measured memory_bytes: 1144
/// Author: Sarfaraz Alam
# include <bits/stdc++.h>
# define pb push_back
# define ll long long

# define fi first
# define se second
# define all(vc) vc.begin(),vc.end()
# define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
# define DEBUG
typedef unsigned long long int ull;
using namespace std;
#include<string>
#include<cmath>
const int N = 1e5 + 7;
const int mod = 1e9 + 7;


int main()
{
    speed;
    #ifdef DEBUGfd
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif // DEBUG

    //Code begins
    string a, b;
    cin>>a>>b;


    int flag = 0;
    int n = a.size();
    int n2 = b.size();
    int l = min(n, n2);
    if(n == n2)
    {
      l = n;
    for(int i = 0; i<l ; i++)
    {
      if(a[i] <b[i])
      {flag = 2;break;}
      else if(a[i] > b[i])
      {
        flag = 1;
        break;
      }
    }
    if(flag == 0)
    {
      // if(n < n2)
      // cout<<"LESS\n";
      // else if( n > n2)
      // cout<<"GREATER\n";
      // else if(n == n2)
      cout<<"EQUAL\n";
    }
    else if(flag  == 1)
    cout<<"GREATER\n";
    else if(flag == 2)
    cout<<"LESS\n";
    }
    else if(n !=n2)
    {
      if(n < n2)
      cout<<"LESS\n";
      else if(n> n2)
      cout<<"GREATER\n";
    }









    return 0;
}


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

public class Main {
	public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int num=Integer.parseInt(reader.readLine());
        System.out.println(num*num*num);
	}
}

Measured memory_bytes: 24180
#include <iostream>
#define MAX_D 100

using namespace std;
int main(){
	int N;
	cin >> N;
	int d[MAX_D];
	long long wa[21] = {0};
	int n0;
	cin >> n0;
	wa[n0] = 1;
	for(int i = 1; i < N-1; ++i){
		int n;
		cin >> n;
		long long nextwa[21] = {0};
		for(int i = 0; i <= 20; ++i){
			if(wa[i]){
				if(i+n <= 20){
					nextwa[i+n] += wa[i];
				}
				if(i-n >= 0){
					nextwa[i-n] += wa[i];
				}
			}
		}
		for(int i = 0; i <= 20; ++i){
			wa[i] = nextwa[i];
		}
	}
	int nN;
	cin >> nN;
	cout << wa[nN] << endl;
}

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

using namespace std;
typedef vector<vector<bool> > matrix;
typedef pair<int,int> P;

matrix mult(const matrix &m, const matrix &n) {
  int size = m.size();
  matrix ans(size,vector<bool>(size, false));
  for (int x=0; x<size; x++)
    for (int y=0; y<size; y++)
      for (int i=0; i<size; i++)
	ans[x][y] = ans[x][y]||(m[i][y]&&n[x][i]);
  return ans;
}

matrix power(matrix m, int c) {
  int size = m.size();
  matrix ans(size, vector<bool>(size, false));
  for (int i=0; i<size; i++)
    ans[i][i] = true;
  for(; c!=0; c>>=1) {
    if ((c&1) == 1)
      ans = mult(ans, m);
    m = mult(m,m);
  }
  return ans;
}

int main() {
  int N,M,Z;

  while (cin >> N >> M >> Z, N) {
    vector<vector<int> > station(N, vector<int>(N, -1));
    matrix road(2*M, vector<bool>(2*M, false));
    vector<P> roadlist(2*M);

    for (int i=0; i<M; i++) {
      int s,d;
      cin >> s >> d;
      station[s-1][d-1] = i*2;
      station[d-1][s-1] = i*2+1;
      roadlist[i*2] = P(s,d);
      roadlist[i*2+1] = P(d,s);
    }

    for (int i=0; i<N; i++) {
      for (int j=0; j<N; j++) {
	int from,to;
	if((from = station[i][j]) != -1) {
	  for (int k=0; k<N; k++) {
	    if ((to = station[j][k]) != -1) {
	      road[from][to] = (i!=k);
	    }
	  }
	}
      }
    }

    // for (int y=0; y<2*M; y++) {
    //   for (int x=0; x<2*M; x++)
    // 	cout << road[x][y] << " ";
    //   cout << endl;
    // }
    // 	cout << endl;

    bool flag = false;

    if (Z == 1) {
      flag = (station[0][N-1]!=-1);
    } else {    
      matrix fin(power(road,Z-1));
      // for (int y=0; y<2*M; y++) {
      // 	for (int x=0; x<2*M; x++)
      // 	  cout << fin[x][y] << " ";
      // 	cout << endl;
      // }

      for (int from=0; from<2*M; from++)
	for (int to=0; to<2*M; to++)
	  if (fin[from][to] &&
	      roadlist[from].first==1 && 
	      roadlist[to].second==N)
	    flag = true;
    }

    if (flag)
      cout << "yes" << endl;
    else
      cout << "no" << endl;      
  }
}

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

// iterator
#define REP(i,init, n) for(lli i=init;i<n;i++)
#define REPE(i,init, n) for(lli i=init;i<=n;i++)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define cout2(x, y)      cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z)   cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl;;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

#define coutp(p)         cout << #p << ":" <<  " (" << p.first << ", " << p.second << ")" << endl;

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;

// dp[i][j] := i個目までの品物で、価値がjとなるときの最小の重さ
lli dp[101][100001];

int main() {
    lli n, W;
    cin2(n, W);
    lli w[n+1];
    lli v[n+1];
    REP(i,0,n) {
        cin >> w[i+1] >> v[i+1];
    }
    REP(i,0,101) {
        REP(j,0,100001) {
            dp[i][j] = LLONG_MAX/10;
        }
    }
    dp[0][0] = 0;

    lli x = 100001;
    //lli x = 141;
    REPE(i,1,n) {
        REP(j,0,x) {
            if (j - v[i]>= 0) {
                // i個目を使わない or i個目を使った結果価値jになる
                dp[i][j] = min(dp[i-1][j], dp[i-1][j-v[i]] + w[i]);
            }
            else {
                dp[i][j] = dp[i-1][j];
            }
            //cout2(i,j);
            //cout1(dp[i][j]);
        }
    }
    for(lli i = x-1; i >= 0; i--) {
        if (dp[n][i] <= W) {
            cout << i << endl;
            return 0;
        }
    }


}


Measured memory_bytes: 79104
#!/usr/bin/env python3
# https://atcoder.jp/contests/abc137/tasks/abc137_b

k, x = [int(x) for x in input().split()]
if x - k + 1 < -1000000:
    mi = -1000000
    ma = x + k - 1
if x + k - 1 > 1000000:
    mi = x - k + 1
    ma = 1000000
else:
    mi = x - k + 1
    ma = x + k - 1
r = map(str, list(range(mi, ma + 1)))
print(" ".join(r))


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>

#define rep(i,n) for(long long i=0;i<n;i++)
using namespace std;

long long aa(long long cnt)
{
	return cnt * (cnt - 1) / 2;
}


int main() {
	

	long long  n;
	cin >> n;

	vector<long long> A(n);
	rep(i, n) cin >> A[i];
	rep(i, n) A[i]--;

	vector<long long> cnt(n);
	rep(i, n) cnt[A[i]] += 1;

	long long ans = 0;

	rep(i, n) ans += aa(cnt[i]);

	long long anss;
	rep(i, n)
	{
		anss = 0;

		anss = ans + aa(cnt[A[i]] - 1)- aa(cnt[A[i]]);

		cout << anss << endl;
	}
	
	

	return 0;
}




Measured memory_bytes: 5760
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Graph= vector<vector<ll>>;
struct edge{ll to ; ll cost ;} ;
using graph =vector<vector<edge>> ;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second 
#define set20 cout<<fixed<<setprecision(20) ;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
double pi=acos(-1) ;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
 
 
 int main(){
   ll n,m ; cin>>n>>m ;
   vector<ll> A(m),B(m) ;
   rep(i,m) {
     cin>> A[i]>>B[i] ;
   A[i]--; B[i]-- ;
   }
   vector<vector<ll>> x(n,vector<ll>(n,0)) ;
   vector<ll> ww ;
   rep(i,n){
     bool ok=1 ;
    x[i][i]++ ;
    rep(j,m){
      ll a= A[m-1-j] ; ll b= B[m-1-j] ;
      if(x[i][a]==1&&x[i][b]==1){
        ok=0 ;
        break ;
      }
      if(x[i][a]==1&&x[i][b]==0) x[i][b]++ ;
      if(x[i][a]==0&&x[i][b]==1) x[i][a]++ ;
    }
    if(ok) ww.pb(i) ;
   }

   ll k= ww.size() ;
   ll ans=0 ;
   rep(i,k){
     ll ii =ww[i] ; 
     rep(j,k){
       ll jj = ww[j] ;
       bool ko=1 ;
       rep(f,n){
         if(x[ii][f]==1&&x[jj][f]==1) ko=0 ;
       }
       if(ko) ans++ ;
     }
   }
   cout<<ans/2<<endl ;
   return 0 ;
 }



Measured memory_bytes: 5884
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
const int maxn=10010;
int n,a[maxn],s[maxn];
int k,pri[maxn];
bool mark[maxn];
vector<int> ans;
void pre()
{
	for (int i=2;i<=n;i++)
	{
		if (!mark[i])
		{
			pri[k++]=i;
		}
		for (int j=0;j<k;j++)
		{
			int m=i*pri[j];
			if (m>n)
			{
				break;
			}
			mark[m]=true;
			if (i%pri[j]==0)
			{
				break;
			}
		}
	}
}
void upd(int &x,int v,int p)
{
	x=((x+v)%p+p)%p;
}
void factor(int x)
{
	for (int i=2;i*i<=x;i++)
	{
		if (x%i==0)
		{
			ans.pb(i);
			while (x%i==0)
			{
				x/=i;
			}
		}
	}
	if (x>1)
	{
		ans.pb(x);
	}
}
bool check(int p)
{
	for (int i=0;i<p-1;i++)
	{
		s[i]=0;
	}
	for (int i=0;i<=n;i++)
	{
		upd(s[i%(p-1)],a[i],p);
	}
	for (int i=0;i<p-1;i++)
	{
		if (s[i])
		{
			return false;
		}
	}
	return true;
}
int main()
{
	scanf("%d",&n);
	pre();
	int g=0;
	for (int i=n;i>=0;i--)
	{
		scanf("%d",&a[i]);
		g=__gcd(g,abs(a[i]));
	}
	factor(g);
	for (int i=0;i<k;i++)
	{
		if (a[0]%pri[i]==0)
		{
			if (check(pri[i]))
			{
				ans.pb(pri[i]);
			}
		}
	}
	sort(ans.begin(),ans.end());
	for (int i=0;i<ans.size();i++)
	{
		printf("%d\n",ans[i]);
	}
	return 0;
}


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

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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i, N) {
        cin >> A[i];
    }
    
    REP(i, N) {
        int temp = A[i];
        int j = i - 1;
        while(j >= 0 && A[j] > temp) {
            A[j + 1] = A[j];
            A[j] = temp;
            j--;
        }
        REP(k, N-1) {
            cout << A[k] << " ";
        }
        cout << A[N-1] << endl;
    }
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define eps LDBL_EPSILON
#define moder 1000000007
#define int long long
#define ll long long
#define INF LLONG_MAX/3
#define P std::pair<int,int>
#define prique priority_queue<int,vector<int>,greater<int>>
using namespace std;
int n,a[100010],b[100010];
signed main(){
	cin>>n;
	rep(i,n){
		cin>>a[i];
		b[i]=a[i];
	}
	sort(b,b+n);
	int ans=0;
	rep(i,n){
		ans+=abs(i-(lower_bound(b,b+n,a[i])-b))%2;
	}
	cout<<(ans+1)/2<<endl;
    return 0;
}

Measured memory_bytes: 1792
import java.util.*;

class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        HashMap<String,Integer> hmap = new HashMap<String,Integer>();
        
        int N = sc.nextInt();
        String[] S = new String[N];
        
        int max = 1;
        for(int i=0; i<N; i++){
            S[i] = sc.next();
            if(hmap.get(S[i]) == null){
                hmap.put(S[i],1);
            } else {
                int nextcount = hmap.get(S[i])+1;
                hmap.put(S[i],nextcount);
                if(nextcount > max) max = nextcount;
            }
        }

        ArrayList<String> maxS = new ArrayList<String>();

        for(String key : hmap.keySet()){
            if(hmap.get(key) == max) maxS.add(key);
        }

        Collections.sort(maxS);

        for(int i=0; i<maxS.size(); i++){
            System.out.println(maxS.get(i));
        }
    }
}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N;
    cin >> N;

    vector<ll> B(N-1);
    rep (i, N-1) {
        cin >> B[i];
    }

    ll ans = B[0];
    rep (i, N-2) {
        if (B[i] > B[i+1]) {
            B[i] = B[i+1];
        }
        ans += B[i];
    }

    ans += B[N-2];

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct apple
{
	int x,y,z;
	apple(int x=0,int y=0,int z=0):x(x),y(y),z(z){}
	bool operator<(const apple &other)const
	{
		return z<other.z;
	}
}e[1000005];
int h[400005],fa[200005];
int findfather(int x){return x==fa[x]?x:fa[x]=findfather(fa[x]);}
int main()
{
	memset(h,127,sizeof(h));
	int n,q,m=0;
	cin>>n>>q;
	for(int i=0;i<n;i++)fa[i]=i;
	for(int i=1;i<=q;i++)
	{
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		e[++m]=apple(a,b,c);
		h[a+1]=min(h[a+1],c+1);
		h[b+1]=min(h[b+1],c+2);
	}
	for(int i=1;i<(n<<1);i++)h[i]=min(h[i],h[i-1]+2);
	for(int i=1;i<(n<<1);i++)
	{
		int l1=i%n,l2=(i-1)%n;
		e[++m]=apple(l1,l2,h[i]);
	}
	sort(e+1,e+m+1);
	long long ans=0;
	for(int i=1;i<=m;i++)
	{
		int x=e[i].x,y=e[i].y,z=e[i].z;
		int l1=findfather(x),l2=findfather(y);
		if(l1!=l2)
		{
			ans+=z;
			fa[l1]=l2;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 17760
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll L,a,b,mod;
struct Matric
{
    ll a[3][3];
    Matric(){memset(a,0,sizeof(a));}
    Matric operator*(const Matric&o)const
    {
        Matric ans;
        for(int i=0;i<3;i++)
            for(int j=0;j<3;j++)
            for(int k=0;k<3;k++)
            ans.a[i][j]=(ans.a[i][j]+a[i][k]*o.a[k][j]%mod)%mod;
        return ans;
    }
};
Matric Mqpow(Matric a,ll n)
{
    Matric ans;
    ans.a[0][0]=ans.a[1][1]=ans.a[2][2]=1;
    while(n)
    {
        if(n&1) ans=ans*a;
        a=a*a;
        n>>=1;
    }
    return ans;
}
ll qpow(ll a,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans=ans*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return ans;
}
int getlen(ll x)
{
    int ans=0;
    while(x)
    {
        x/=10;
        ans++;
    }
    return ans;
}
ll getpos(int x)
{
    ll l=1,r=L,ans=1;
    while(l<=r)
    {
        ll m=l+r>>1;
        if(getlen(a+(m-1)*b)<=x) ans=m,l=m+1;
        else r=m-1;
    }
    return ans;
}
/*
si=s(i-1)*qpow(10,i)+qi+B;
gi=g(i-1)+B;
|10i 1 1| |si-1|
|0   1 1| |gi-1|
|0   0 1| |B|
*/
int main()
{
    scanf("%lld%lld%lld%lld",&L,&a,&b,&mod);
    //mod=1e9+7;
    ll ans=a%mod,res=a%mod,now=1;
    for(int i=1;i<=18;i++)
    {
        ll p=getpos(i);
        if(p==now) continue;
        Matric A;
        A.a[0][0]=qpow(10,i);A.a[0][1]=0;A.a[0][2]=0;
        A.a[1][0]=1;A.a[1][1]=1;
        A.a[2][0]=1;A.a[2][1]=1;A.a[2][2]=1;
        A=Mqpow(A,p-now);
        ans=(A.a[0][0]*ans%mod+res*A.a[1][0]%mod+b%mod*A.a[2][0]%mod)%mod;
        res=(res+b*(p-now))%mod;
        now=p;
        //cout<<ans<<endl;
    }
    printf("%lld\n",ans);
}


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

using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
string S,T;






int main()
{

	cin >> S >> T;
	bool flag1 = false;
	int qcount = 0;
	RREP(i,S.length()){
		if(S[i]=='?' || S[i] == T[0]){
			if(T.length()>(S.length()-i)+1)
				continue;
			int head = 0;
			bool flag = true;
			while(head < T.length()){
				if(!(S[i+head] == '?' || S[i+head] == T[head])){
					flag = false;
					break;
				}
				head++;
			}
			if(flag){
				REP(j,T.length()){
					S[i+j] = T[j];
				}
				flag1=true;
				break;

			}
		}
	}

	if(flag1){
		REP(i,S.length()){
			if(S[i]=='?')
				cout << 'a';
			else
				cout << S[i];
		}
	} else {
		cout << "UNRESTORABLE";
	}




}





Measured memory_bytes: 256
#include <bits/stdc++.h>
 using namespace std;
 using pii = pair<int, int>;
 using ll = long long;
 #define rep(i, j, n) for(int i = j; i < (int)(n); i++)
 const ll MOD = 1000000007;
 const ll INFL = 1LL << 60;
 const int INFI = (1 << 30);

 int N, A, B, C;
 vector<int> L;

 int rec(int i, int a, int b, int c) {
     if (i == N) {
         if (a == 0 || b == 0 || c == 0) return INFI; // A, B, C いずれも竹は 1 本は必ず使ってないとダメ
         return abs(a - A) + abs(b - B) + abs(c - C); // 合体してできた a, b, c を A, B, C にするコスト
     }
     int res = rec(i + 1, a, b, c);
     res = min(res, rec(i + 1, a + L.at(i), b, c) + (a ? 10 : 0));
     res = min(res, rec(i + 1, a, b + L.at(i), c) + (b ? 10 : 0));
     res = min(res, rec(i + 1, a, b, c + L.at(i)) + (c ? 10 : 0));
     return res;
 }
 int main() {
     cin >> N >> A >> B >> C;
     L.resize(N);
     for (int i = 0; i < N; i++) cin >> L.at(i);
     cout << rec(0, 0, 0, 0) << endl;
 }


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

int main()
{
        int K;

        cin >> K; //初期値の読み込み

        if(K%2==0){
        cout << (K/2)*(K/2) ;
        }else{
        cout << (K/2)*(K/2+1);
        }

        return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pll pair<ll,ll>
#define fr first
#define se second
#define ull unsigned long long
#define getbit(x,i) (x>>i)&1

void solve(){
    ll n,k;cin>>n>>k;
    vector<ll> p(n);
    for(ll i=0;i<n;i++) cin>>p[i];
    sort(p.begin(),p.end());
    ll ans=0;
    for(ll i=0;i<k;i++) ans+=p[i];
    cout<<ans<<endl;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    ll qu=1;
    // cin>>qu;
    for(ll cas=1;cas<=qu;cas++){
        // cout<<"Case #"<<cas<<": ";
        solve();
    }
}

Measured memory_bytes: 3652
while True:
    S = input()
    if S=="#":
        exit()
    B = []
    W = 0
    for c in S:
        if c == "b":
            B.append(1)
        elif c != "/":
            B.extend([0] * int(c))
        elif W==0:
            W = len(B)
    assert len(B) % W == 0
    H = len(B) // W
    a,b,c,d = map(lambda x: int(x)-1, input().split())
    B[a*W+b] = 0
    B[c*W+d] = 1
    ans = ""
    cnt = 0
    for y in range(H):
        for x in range(W):
            if B[y*W+x] == 0:
                cnt += 1
            else:
                if cnt>0:
                    ans+=str(cnt)
                cnt = 0
                ans += "b"
        if cnt>0:
            ans += str(cnt)
        cnt = 0
        ans += "/"
    print(ans[:-1])



Measured memory_bytes: 5604
#include <iostream>
#include <vector>
#define rep(i, n) for(int (i)=0;(i)<(n);++(i))
using namespace std;

const int INF = 1001001001;

int main() {
    int n, c; cin >> n >> c;
    vector<vector<int>> d(c, vector<int>(c, 0));
    vector<vector<int>> grid(n, vector<int>(n, 0));
    rep(i, c)rep(j, c) cin >> d[i][j];
    rep(i, n)rep(j, n) {
        cin >> grid[i][j];
        --grid[i][j];
    }

    // cost[i][j] あまりがiのマスをj色に塗るのにかかるコスト
    vector<vector<int>> cost(3, vector<int>(c, 0));
    rep(i, n)rep(j,n)rep(color, c) cost[(i + j) % 3][color] += d[grid[i][j]][color];

    int ans = INF;
    rep(c0, c)rep(c1, c)rep(c2,c) {
        if (c0 == c1 || c1 == c2 || c2 == c0) continue;
        ans = min(ans, cost[0][c0] + cost[1][c1] + cost[2][c2]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 1280
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T>using vv = vector<vector<T>>;
template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 28, MOD = int(1e9) + 7; constexpr ll LINF = 1ll << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

int main() {
    int N;
    cin >> N;
    string S, T;
    cin >> S >> T;

    ll ans = 1;
    int i;
    if (S[0] == T[0]) {
        ans *= 3;
        i = 1;
    }
    else {
        ans *= 6;
        i = 2;
    }
    for ( ; i < N; ) {
        if (S[i - 1] == T[i - 1]) {
            if (S[i] == T[i]) {
                ans = ans * 2 % MOD;
                i++;
            }
            else {
                ans = ans * 2 % MOD;
                i += 2;
            }
        }
        else {
            if (S[i] == T[i]) {
                ans = ans;
                i++;
            }
            else {
                ans = ans * 3 % MOD;
                i += 2;
            }
        }
    }
    
    write(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD (int)(1e9+7)
#define ceil(x, y) (x%y==0? (x/y) : (x/y+1))
#define FOR(i, N) for(int i = 0; i < N; ++i)
#define FOR1(i, N) for(int i = 1; i <= N; ++i)
#define vi vector <int>
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mset(a, v) memset(a, v, sizeof(a))
#define all(v) (v).begin(), (v).end()
#define INF 2e9
#define EPS 1e-9
#define int long long
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef cc_hash_table<int, int, hash<int>> ht; // while using, comment #define int long long  */

void __print(int x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
using namespace std;
int dfs(vector<int> adj[], int s, bool vis[]){
    vis[s] = true;
    int ans = 1;
    for(int neigh : adj[s]){
        if(vis[neigh] == false){
            ans += dfs(adj, neigh, vis);
        }
    }
    return ans;
}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("in5.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    int T=1;
    // cin >> T;
    FOR1(tt, T){
        // cout << "Case #" << tt << ": ";
        int n, m;
        cin >> n >> m;
        vector<int> adj[n+1];
        FOR1(i, m){
            int a, b;
            cin >> a >> b;
            adj[a].pb(b);
            adj[b].pb(a);
        }

        int maxi = 0;
        bool vis[n+1]; mset(vis, false);
        for(int i = 1; i <= n; i++){
            if(vis[i] == false){
                maxi = max(maxi, dfs(adj, i, vis));
            }
        }
        cout << maxi;
        cout << '\n';
    }
    return 0;
}


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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int N,K;
    Scd2(N,K);

    vl a(N);
    vl s(N+1);
    vl t(N+1);
    Rep(i,N) {
        Scll(a[i]);
        s[i+1] += s[i] + a[i];
        t[i+1] += t[i] + max( a[i], 0ll );
    }

    ll ans = 0;
    Rep(i,N-K+1){
        ans = max( ans, (t[i]-t[0]) + (s[i+K]-s[i]) + (t[N]-t[i+K]));
        ans = max( ans, (t[i]-t[0]) + (t[N]-t[i+K]));
    }

    printf ("%lld\n", ans );

    return 0;
}



Measured memory_bytes: 2560
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
    ll n, k;
    cin >> n >> k;
    vector<int> a(n+1, 0);
    for (int i = 1; i < n+1; i++) {
        cin >> a[i];
    }
    
    int n1 = a[1], n2 = a[1];
    do {
        n1 = a[n1];
        n2 = a[a[n2]];
    } while(n1 != n2);
    n2 = a[1];
    int l = 1;
    do {
        n1 = a[n1];
        n2 = a[n2];
        l++;
    } while(n1 != n2);
    int u = 0;
    do {
        n1 = a[n1];
        n2 = a[a[n2]];
        u++;
    } while(n1 != n2);
        
    ll nn;
    if (k > l)
        nn = l + ((k - l) % u);
    else
        nn = k;
    
    int ans = 1;
    for (int i = 0; i < nn; i++)
        ans = a[ans];
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 4052
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(sc.nextInt());
        }

        Collections.sort(list);

        int center1 = list.get(n/2 -1);
        int center2 = list.get(n/2);

        System.out.println(center2 - center1);

    }
}

Measured memory_bytes: 57920
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

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

	if(X <= A+B && X >= A)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>

namespace IO{
    const int insiz = 1 << 12, outsiz = 1 << 18;
    char in[insiz], *A(in), *B(in); char out[outsiz], *ptr(out);
    inline char getc(){
    	#ifndef LOCAL
        return (A == B) && (B = (A = in) + fread(in, 1, insiz, stdin), A == B) ? EOF : *A++;
        #endif
        return getchar();
    }
    template <typename T> inline T read(){
        T ret(0), p(1); char ch(getc());
        while(ch < '0' || ch > '9'){
            if(ch == '-') p = -1; ch = getc();
        }
        while(ch >= '0' && ch <= '9') ret = ret * 10 + ch - '0', ch = getc();
        return ret*p;
    }
    inline void flush(){ fwrite(out, 1, ptr - out, stdout); ptr = out; }
    template <typename T> inline void write(T x, char cmd = '\n'){
        if(x < 0) *ptr++ = '-', x = -x;
        if(x == 0) *ptr++ = '0';
        static char s[123]; int cnt = 0;
        for(; x; x /= 10) s[++cnt] = x % 10 + '0';
        for(; cnt; --cnt) *ptr++ = s[cnt];
        *ptr++ = cmd;
        if((outsiz >> 1) > ptr - out) flush();
    }
} using IO::getc; using IO::read; using IO::write; using IO::flush;

typedef long long ll;
const int maxn = 112345;

ll v[maxn], dp[maxn][2];

int main(){
	int n = read<int>();
	for(int i(1); i <= n; ++i) v[i] = read<ll>();
	dp[1][0] = v[1]; dp[1][1] = -v[1];
	for(int i(2); i < n; ++i){
		dp[i][0] = std::max(dp[i-1][0]+v[i], dp[i-1][1]-v[i]);
		dp[i][1] = std::max(dp[i-1][0]-v[i], dp[i-1][1]+v[i]);
	}
	write(std::max(dp[n-1][0]+v[n], dp[n-1][1]-v[n]));
	flush(); return 0;
}




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

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

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  map<int,int> mp;
  rep(i,N){
    int x;
    cin >> x; 
    ++mp[x];
  }
  int count = 0;
  for(auto &m : mp){
    count += m.second - 1;
  }
  cout << N - (count+1)/2*2 << endl;
  return 0;
}


Measured memory_bytes: 4992
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>
#define PI 3.141592653589793238462643383279
 
 
void change(int *x, int *y){
	int z;
	z = *x;
	*x = *y;
	*y = z;
}
int compare_int(const void *a, const void *b){
	return *(int*)a - *(int*)b;
}
 
int gcd(int a, int b)
{
    int c;
    if (a < b) {
        a+=b; b=a-b; a-=b;
    }
    while (b != 0) {
        c = a % b;
        a = b;
        b = c;
    }
    return a;
}
int main(void){
	int n;
	scanf("%d", &n );
	int h[n];
	for(int i=0;i<n;i++)	scanf("%d", &h[i]);
	
	int ans=0;
	int ansmax=0;
	int num=h[0];
	
	for(int i=1;i<n;i++){
		if(num >= h[i]){
          	ans++;
        }else{
           if(ansmax < ans)	ansmax=ans;
          ans = 0;
        }
		
		num = h[i];
	}
	if(ans!=0 && ans > ansmax)	ansmax = ans;
	printf("%d", ansmax );
	
	return 0;
}


Measured memory_bytes: 512