akhauriyash/Code-Regression huggingface dataset:
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function main()
	a = readline() |> parseInt
	b = readline() |> parseInt
	c = readline() |> parseInt
	d = readline() |> parseInt
	e = readline() |> parseInt
	k = readline() |> parseInt
	println(e-a<=k?"Yay!":":(")
end
main()

Measured memory_bytes: 164904
import sys,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

n = onem()

a = []
b = []
c = []

a = l()
b = l()
c = l()
co = 0
for i in range(n):
    co += b[a[i]-1]
    if i >= 1:
        if a[i] == a[i-1]+1:
            co += c[a[i-1]-1]
    
print(co)


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

int main( void ) {
    
    int n, a, b; string str;
    cin >> n >> a >> b >> str;
    
    int cnt1 = 0, cnt2 = 0;
    for( char ch : str ) {
        if( ch == 'c' )
            cout << "No\n";
    
        if( ch == 'b' ) {
            if( cnt1 < a + b && cnt2 < b ) {
                cout << "Yes\n";
                cnt1 ++; cnt2 ++;
            }
            else
                cout << "No\n";
        }
        
        if( ch == 'a' ) {
            if( cnt1 < a + b ) {
                cout << "Yes\n";
                cnt1 ++;
            }
            else
                cout << "No\n";
        }
    }
    
    return 0;
}

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

int main() {
    int64_t N;
    std::cin >> N;

    std::vector<int64_t> count(N + 1, 0);
    for (int64_t i = 1; i < N + 1; ++i) {
        for (int64_t j = i; j < N + 1; j += i) {
            count[j] += 1;
        }
    }

    int64_t ans = 0;
    for (int64_t i = 1; i < N + 1; ++i) {
        ans += i * count[i];
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 81368
#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdio.h>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <functional>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long
#define SORT(v) sort((v).begin(),(v).end())
//#define scanf scanf_s

int main()
{
	bool prime[200000];
	memset(prime, true, sizeof(prime));
	prime[0] = prime[1] = false;
	for (int i = 2; i*i < 200000; i++)
	{
		if (prime[i] == true)
		{
			for (int j = 2; i*j < 200000; j++)
			{
				prime[i*j] = false;
			}
		}
	}

	int n, p;
	while (cin >> n >> p)
	{
		if (n == -1) break;
		vector<int> v, s;

		for (int i = n+1; v.size() < 100; i++)
		{
			if (prime[i] == true) v.push_back(i);
		}
		REP(i, 100)for (int j = i; j < 100; j++)
		{
			s.push_back(v[i] + v[j]);
		}
		SORT(s);
		cout << s[p - 1] << endl;

	}
	return 0;
}

Measured memory_bytes: 1472
N,M,X = map(int,input().split())
An = list(map(int,input().split()))
advancescore = 0
backscore = 0
for i in range(0,X):
    if i in An:
        advancescore+=1
for i in range(X,N):
    if i in An:
        backscore+=1
print(min(advancescore,backscore))

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

int main() {
    string s, t; cin >> s >> t;
    ll A, B; cin >> A >> B;
    string u; cin >> u;
    if (u == s) A--;
    if (u == t) B--;
    cout << A << " " << B << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)(a);i<=(sign)(b);++i)
#define Fordown(i,a,b) for(register sign i=(sign)(a);i>=(sign)(b);--i)
const int N=100+5;
template<typename T>bool cmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool cmin(T &a,T b){return (a>b)?a=b,1:0;}
template<typename T>T read()
{
	T ans=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')f=-1,ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
	return ans*f;
}
template<typename T>void write(T x,char y)
{
	if(x==0)
	{
		putchar('0'),putchar(y);
		return;
	}
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	static char wr[20];
	int top=0;
	for(;x;x/=10)wr[++top]=x%10+'0';
	while(top)putchar(wr[top--]);
	putchar(y);
}
void file()
{
#ifndef ONLINE_JUDGE
	freopen("in","r",stdin);
	freopen("out","w",stdout);
#endif
}
int n,a[N];
void input()
{
	n=read<int>();
	For(i,1,n)a[i]=read<int>();
}
int ans;
void work()
{
	int r;
	For(l,1,n)
	{
		for(r=l;r<n&&a[r+1]==a[l];r++);
		ans+=(r-l+1)/2;
		l=r;
	}
	write(ans,'\n');
}
int main()
{
	//file();
	input();
	work();
	return 0;
}


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

#include <vector>
#include <algorithm>
int main()
{
    int k,n;
    cin>>k>>n;
    vector<int>res;
    int num;
    for(int i=0;i<k;i++)
    {
        cin>>num;
        res.push_back(num);
    }
    sort(res.begin(),res.end(),[](int a,int b){
         return a>b;});
    long long sum =0;
    for(int i=0;i<n;i++)
    {

        sum+=1ll*res[i];
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
using namespace std;

int a[8];

int main()
{
    int n,sum,ans;
    while(~scanf("%d",&n))
    {
        memset(a,0,sizeof(a));
        sum=0;
        ans=0;
        for(int i=0;i<n;i++)
        {
            int x;
            scanf("%d",&x);
            x=x/400;
            if(x<8)
            {
                a[x]=1;
            }
            else
            {
                sum++;
            }
        }
        for(int i=0;i<=7;i++)
        {
            ans+=a[i];
        }
        printf("%d %d\n",ans==0?1:ans,ans+sum);
    }
    return 0;
}


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

int main(){
  int n;
  string a="No";
  cin>>n;
  if(n<82){
    for(int i=1;i<10;i++){
      if(n%i==0&&n/i<10){
        a="Yes";
        break;
      }
    }
  }
  cout<<a<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

using namespace std;

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

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;   // INFの値は1152921504606846976

const int V_MAX = 305;

int main()
{
    int n;  cin >> n;
    ll a[n][n];
    bool use[n][n];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            cin >> a[i][j];
            use[i][j] = true;
        }
    }
    bool e = true;
    for(int k = 0; k < n; k++){
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                if(k == i || k == j) continue;
                if(a[i][j] > a[i][k] + a[k][j]) e = false;
                if(a[i][j] == a[i][k] + a[k][j]){
                    use[i][j] = false;
                }
            }
        }
    }
    if(!e){
        cout << -1 << endl;
    }else{
        ll sum = 0;
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                if(use[i][j]) sum += a[i][j];
            }
        }
        cout<<sum/2;
    }
}   

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define MAXN 100005
const int mod = 1e9 + 7;
using namespace std;

int main()
{
    string s,t;
    cin>>s>>t;
    int len_s = s.length();
    if(t.substr(0,len_s) == s) {
        cout<<"Yes"<<endl;
    }
    else {
        cout<<"No"<<endl;
    }
}


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

using namespace std;

int main(){
    string s,c;
    int n,i,j,k,l,sum=0;
    cin>>n>>l;
    int f[n];
    for(i=0;i<n;i++){
            f[i]=l+i;
            sum+=f[i];
    }
    int dif=INT_MAX,flag=0;
    for(i=0;i<n;i++){
        dif=min(abs(f[i]),dif);
        //cout<<"This is diff "<<dif<<endl;
        if(dif==abs(f[i])){flag=f[i];}
    }
    cout<<sum-flag;



    return 0;
}


Measured memory_bytes: 3632
// -*- coding:utf-8-unix -*-
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
  }

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
    // 3
    // 1 2
    // 1 3
    // 1 4
    // のようなタイプ
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
  }

fn main() {
    input! {
        n: usize,
    }
    let loop_end = (n as f64).sqrt() as usize + 1;

    let mut min = 2000000000000;
    let mut x = 0;

    for i in 1..loop_end {
        if n % i == 0 {
            if i + (n / i) < min {
                min = i + (n / i);
                x = i;
            }
        }
    }
    println!("{}", (x - 1) + (min - x - 1));
}


Measured memory_bytes: 4352
let pi = 4. *. atan 1.

let to_radian degree = pi *. degree /. 180.

type point = { x : float; y : float }

let print_point e = Printf.printf "%f %f\n" e.x e.y

let rec koch n a b =
  if n = 0 then () else
  let s =
    let x = (2. *. a.x +. b.x) /. 3. in
    let y = (2. *. a.y +. b.y) /. 3. in
    { x; y } in
  let t =
    let x = (a.x +. 2. *. b.x) /. 3. in
    let y = (a.y +. 2. *. b.y) /. 3. in
    { x; y } in
  let u =
    let x = (t.x -. s.x) *. cos (to_radian 60.) -. (t.y -. s.y) *. sin (to_radian 60.) +. s.x in
    let y = (t.x -. s.x) *. sin (to_radian 60.) +. (t.y -. s.y) *. cos (to_radian 60.) +. s.y in
    { x; y } in
  koch (n - 1) a s;
  print_point s;
  koch (n - 1) s u;
  print_point u;
  koch (n - 1) u t;
  print_point t;
  koch (n - 1) t b

let () =
  let n = read_int () in
  let p1 = { x = 0.; y = 0. } in
  let p2 = { x = 100.; y = 0. } in
  print_point p1;
  koch n p1 p2;
  print_point p2

Measured memory_bytes: 4660
#include<iostream>
#include <string>
using namespace std;
int main(){
  // 整数の入力
  string a;
  cin >> a;
	int count = 0;
  if(a[0]=='1')count++;
  if(a[1]=='1')count++;
  if(a[2]=='1')count++;
  cout<<count <<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>

#define SPACE string(" ")

using namespace std;

int main(void) {
	int n, m;
	cin >> n >> m;

	int **a = new int*[n];
	for (int i = 0; i < n; i++) {
		a[i] = new int[m];
	}

	int *b = new int[m];

	cin >> ws;
	string str;
	int c;
	for (int x = 0; x < n; x++) {
		c = 0;
		getline(cin, str);

		string::size_type spos = 0;
		string::size_type epos = 0;
		while ((epos = str.find(SPACE, spos)) != string::npos) {
			a[x][c++] = atoi(str.substr(spos, epos - spos).c_str());
			spos = epos + SPACE.length();
		}
		a[x][c] = atoi(str.substr(spos).c_str());
	}

	for (int y = 0; y < m; y++) {
		int h;
		cin >> h;
		b[y] = h;
	}

	for (int z = 0; z < n; z++) {
		int sum = 0;
		for (int w = 0; w < m; w++) {
			sum += a[z][w] * b[w];
		}
		cout << sum << endl;
	}

	delete[] b;
	
	for (int j = 0; j < n; j++) {
		delete[] a[j];
	}
	delete[] a;

	return 0;
}

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

int main() {
   int x, t;
   cin >> x >> t;

   if (x >= t) {
        cout << x - t << endl;
   } else {
       cout << 0 << endl;
   }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
int main(){
  long long X; cin >> X;
  long long A, B;
  bool end = false;
  for (long long i = 0; i < 1000; i++){
    for (long long j = 0; j < 1000; j++){
      if(pow(i, 5) - pow(j, 5) == X){
        A = i;
        B = j;
        end = true;
      } else if(pow(i, 5) + pow(j, 5) == X){
        A = i;
        B = (-1) * j;
        end = true;
      }
      if (end) break;
    }
    if (end) break;
  }
  cout << A << " " << B << endl;
  return 0;
}

Measured memory_bytes: 4012
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define P pair<int,int>
#define PI 3.141592653589793
const int INF = 1001001001;

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

int dp[100005];

int main() {
	int n;
	cin >> n;
	vector<int> h(n);
	rep(i, n) cin >> h[i];

	rep(i, 100005) dp[i] = INF;
	dp[0] = 0;

	for(int i = 1;i < n;i++) {
		chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
		if (i > 1) {
			chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
		}
	}
	cout << dp[n - 1] << endl;
}


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

int main(){
    int n;
    cin >> n;
    rep(i,n) {
        int a; 
        cin >> a;
        if(a%2==0) {
            if(a%3!= 0 && a%5!=0) {
                cout << "DENIED" << endl;
                return 0;
            }
        }
        else continue;
    }
    cout << "APPROVED" << endl;
    return 0;
}

Measured memory_bytes: 256
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.split_whitespace().map(|s| s.parse().unwrap());
    let (a, b, c): (i64, i64, i64) = (iter.next().unwrap(), iter.next().unwrap(), iter.next().unwrap());
    let ans = if c >= a && c <= b {
        "Yes"
    } else {
        "No"
    };
    println!("{}", ans);
}


Measured memory_bytes: 4352
def func(x, y, total):
    if y == 0:
        return total
    else:
        total += x // y
        new_x = x % y
        new_y = y // 10
        return func(new_x,new_y,total) 

n, a, b = [int(i) for i in input().split()]

ans = sum([
	i for i in range(1, n+1)
	if a <= func(i, 10**4, 0) <= b])
print(ans)

Measured memory_bytes: 9232
import sys
import math
import numpy as np
INF = 1000000000
MOD = 2019


def input():
    return sys.stdin.readline().rstrip()


def main():
    l, r = [int(e) for e in input().split()]
    ans = INF
    for i in range(l, min(l + MOD, r + 1)):
        for j in range(i + 1, min(l + MOD, r + 1)):
            ans = min(ans, ((i % MOD) * (j % MOD)) % MOD)
    print(ans)


main()


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

int n,k,ans,hoge;
string s;
vector<int> v;

signed main() {
    cin >> n >> k >> s;
    if (s[0] == '1') hoge++;
    s.pb(1);
    v.pb(0);
    rep(i,s.size()-1) if (s[i] != s[i+1]) v.pb(i+1);
    v.pb(n);
    while(hoge < v.size()) {
        ans = max(ans,v[hoge]-v[max(0LL,hoge-k*2-1)]);
        hoge += 2;
    }
    cout << ans << endl;

}


Measured memory_bytes: 1528
#include<iostream>
#include<math.h>
#include<stdio.h>
using namespace std;

int main(){
 int n;
 while(cin >> n && n!=0){
 double s[n],m,sum=0;
 for(int i=0; i<n; i++){
   cin >> s[i];
   sum += s[i];
 }
 m = sum/n;
 sum = 0;
 for(int i=0; i<n; i++){
   sum += (s[i] -m)*(s[i]-m);
 }
 printf("%.5f\n", sqrt(sum/n) );
 }
}


Measured memory_bytes: 3300
#include <bits/stdc++.h>
#define PI acos(-1)
#define eq(x,y) (fabs((x)-(y)) < eps)
#define debug(x) cerr<<#x<<" = "<<x<<endl;
#define pb push_back
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define bump cout<<"bleh\n"
#define all(v) (v).begin(),(v).end()

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;

typedef long long ll;
typedef unsigned long long llu;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf=1e9+7;
const int nmax=1e5+10;
const int eps=1e-8;
const ll infll=1e15;


int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n,r,ans;
    cin>>n>>r;

    if(n>=10){
        ans=r;
    }else{

        ans=r+100*(10-n);
    }

    cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

typedef long long ll;

using namespace std;

const ll inf = 1ll << 60;

ll mult(ll a, ll b){
  if(inf / a < b) throw 0;
  return a * b;
}

int main(){
  ll n, m, a, b, p, q;
  cin >> n >> m >> a >> b >> p >> q;
  if(a == 1 && b == 1){
    ll tmp = min(n + 1, m / (p + q));
    ll ans = inf;
    for(ll t = max(0ll, tmp - 2); t < min(n + 1, tmp + 2); t++){
      ll tt = t * (p + q);
      ans = min(ans, std::abs(m - tt));
    }
    cout << ans << endl;
    return 0;
  }

  if(n > 40) n = 40;

  vector<ll> v;
  ll aa = 1;
  ll bb = 1;

  try{
    REP(i,n){
      ll val = mult(p, aa) + mult(q, bb);
      if(val <= m + m) v.push_back(val);
      else break;
      aa = mult(aa, a);
      bb = mult(bb, b);
    }
  }catch(int n){}

  vector<ll> as;
  vector<ll> bs;

  n = v.size();

  if(n == 1){
    cout << min(m, std::abs(m - v[0])) << endl;
    return 0;
  }

  REP(i,1<<(n/2)){
    ll tmp = 0;
    REP(j,n/2) if(i & (1 << j)) tmp += v[j];
    as.push_back(tmp);
  }

  REP(i,1<<(n/2 + n%2)){
    ll tmp = 0;
    REP(j,n/2 + n%2) if(i & (1 << j))
      tmp += v[j + n / 2];
    bs.push_back(tmp);
  }

  sort(as.begin(), as.end());
  sort(bs.rbegin(), bs.rend());

  size_t ai = 0, an = as.size() - 1;
  size_t bi = 0, bn = bs.size() - 1;
  ll ans = m;

  while(ai < an || bi < an){
    ll tmp = as[ai] + bs[bi];
    ans = min(ans, std::abs(m - tmp));
    if(tmp > m){
      if(bi != bn) bi++;
      else ai++;
    }else{
      if(ai != an) ai++;
      else bi++;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 16000
#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
#include <vector>
int read(){
	register int x = 0;
	register char f = 1, ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') f ^= 1;
	for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ '0');
	return f ? x : -x;
}
int n, h, w, fa[200005], g[200005];
long long ans;
struct node{
	int r, c, v;
	bool operator < (const node &rhs) const {
		return v > rhs.v;
	}
}a[100005];
int find(int x){
	return fa[x] == x ? x : (fa[x] = find(fa[x]));
}
bool merge(int x, int y){
	x = find(x), y = find(y);
	if (x == y) if (g[x]) return 0; else return g[x] = 1, 1;
	if (g[x] && g[y]) return 0;
	return fa[y] = x, g[x] |= g[y], 1;
}
int main(){
	n = read(), h = read(), w = read();
	for (register int i = 1; i <= n; ++i)
		a[i].r = read(), a[i].c = read(), a[i].v = read();
	std :: sort(a + 1, a + 1 + n);
	for (register int i = 1; i <= h + w; ++i) fa[i] = i, g[i] = 0;
	for (register int i = 1; i <= n; ++i)
		if (merge(a[i].r, a[i].c + h)) ans += a[i].v;
	printf("%lld\n", ans);
}


Measured memory_bytes: 3712
import sys
input = sys.stdin.readline
vs = set()
def dfs_w(d, stack):
    depth = defaultdict(int)
    pvs = set()
    while stack:
        v = stack.pop()
        vs.add(v)
        pvs.add(v)
        for u, dpd in d[v]:
            if u in pvs:
                if depth[u] != depth[v] + dpd:
                    return False
            if u in vs:
                continue
            depth[u] = depth[v] + dpd
            stack.append(u)
    return True

if __name__ == '__main__':
    from collections import defaultdict
    N, M = map(int, input().split())
    G = defaultdict(set)
    for _ in range(M):
        a, b, c = map(int, input().split())
        G[a].add((b,c))
        G[b].add((a,-c))
    for i in range(N):
        if i+1 in vs:
            continue
        stack = [i+1] 
        r =  dfs_w(G, stack)
        if not r:
            break
    if r:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 121048
/*
    ThunderClap and Flash.
    Raunaq Singh
*/
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
#define ThunderClap ios::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
#define debugg(something)   cout<<#something<<" - "<<something<<"\n";
#define vi vector
#define umap unordered_map
#define uset unordered_set
#define mset multiset
#define LB lower_bound
#define UB upper_bound
#define mp make_pair
#define pb push_back
#define in insert
#define s second
#define f first
#define pQueue priority_queue
#define maxElement *max_element
#define minElement *min_element
#define MAX 100000LL
#define mod 1000000007LL
#define inf 1000000000000000000LL
#define mI2 500000004LL
inline ll add(ll a, ll b){ return ((a%mod)+(b%mod))%mod;}
inline ll mul(ll a, ll b){ return ((a%mod)*(b%mod))%mod;}
inline ll sub(ll a, ll b){ return ((a%mod)-(b%mod)+mod)%mod;}

void Flash(){
    ll n,x,y;
    cin>>n>>x>>y;
    vi<ll>adj[n];
    for(ll i=0;i<n-1;i++){
        adj[i].pb(i+1),adj[i+1].pb(i);
    }
    adj[x-1].pb(y-1),adj[y-1].pb(x-1);
    ll distance[n][n+5];
    memset(distance,0,sizeof(distance));
    ll temp,d,nn;
    for(ll i=0;i<n;i++){
        queue<ll>q;
        bool vis[n]={};
        q.push(i);
        d=0;
        while(!q.empty()){
            nn=q.size();
            for(ll j=0;j<nn;j++){
                temp=q.front();
                vis[temp]=true;
                q.pop();
                ++distance[i][d];
                for(auto it:adj[temp]){
                    if(!vis[it]){
                        vis[it]=true;
                        q.push(it);
                    }
                }
            }
            ++d;
        }
    }
    ll ans=0;
    for(ll i=1;i<n;i++){
        ans=0;
        for(ll j=0;j<n;j++){
            ans+=distance[j][i];
        }
        cout<<ans/2<<"\n";
    }
}

int main(int argc, char const *argv[]){
    ThunderClap;
    ll t=1;
    //cin>>t;
    for(ll i=1;i<=t;i++){
        //cout<<"Case #"<<i<<": ";
        Flash();
    }
    return 0;
}

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

int main() {
  int H, W, D, Q;
  cin >> H >> W >> D;
  vector<vector<int>> A(H, vector<int>(W));
  rep(i, H) rep(j, W) cin >> A[i][j];
  cin >> Q;
  vector<int> L(Q), R(Q);
  rep(i, Q) cin >> L[i] >> R[i];
  
  vector<int> Z(H * W + 1);
  rep(i, H) rep(j, W) Z[A[i][j]] = i * W + j;
  vector<int> S(H * W + 1, 0);
  for (int i = D + 1; i < H * W + 1; ++i) {
    int x = Z[i - D] / W;
    int y = Z[i - D] % W;
    int X = Z[i] / W;
    int Y = Z[i] % W;
    S[i] = S[i - D] + abs(x - X) + abs(y - Y);
  }
  
  for (int i = 0; i < Q; ++i) cout << S[R[i]] - S[L[i]] << endl;
  return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <numeric>
#include <algorithm>
#include <vector>
#include <array>
#include <string>
#include <queue>
#include <cmath>
#include <iterator>
#include <math.h>
#include <cstdio>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <tuple>

using namespace std;
using lli = long long int;
using ulli = unsigned long long int;

namespace atcoder{
    void judge_outer(bool judge_exp,string ok = "Yes",string ng = "No"){
        if(judge_exp){
            cout << ok << endl;
        }else{
            cout << ng << endl;
        }
    }
}

using namespace atcoder;

//3 -5  1  0
//3 11 17 18

//   5 11 12
//3+8-5

//3     5  6
//8+6-2

//3 11    16
//6+1-5

int main(void){
    int n;
    cin >> n;
    vector<int> a(n+2);
    a[0] = 0;
    for(int i=1;i<=n;i++){
        cin >> a[i];
    }
    a[n+1] = 0;
    int total = 0;
    for(int i=1;i<=n+1;i++){
        total += abs(a[i-1]-a[i]);
    }
    for(int i=1;i<=n;i++){
        cout << total - (abs(a[i-1]-a[i]) + abs(a[i]-a[i+1]) -abs(a[i-1]-a[i+1]) ) << endl;
    }
    
    
    
    
    return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#include <numeric>
#include <limits>
#include <numeric>
#include <type_traits>
using namespace std;
typedef pair<int, int> P;

typedef long long ll;
const int MOD = 1000000007;

int main(){  
  ll L,R,min = 2019;
  cin >> L >> R;
  if(L/2019 != R/2019 - 1 && L/2019 != R/2019){
    cout << 0;
  }else{
    for(int i=0;i<R-L+1;i++){
      for(int j=i+1;j<R-L+1;j++){
        if(min > ((L+i)*(L+j))%2019) min = ((L+i)*(L+j))%2019;
      }
    }
      cout << min;
  }
}



Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<bitset>
//aoj0525
using namespace std;
int h,l;
bitset<10003> bs[13];
int ans;
void dfs(int cs)
{
	if(cs>h)
	{
		int lsa=0;
		for(int i=1;i<=l;i++)
		{
			int ls=0;
			for(int j=1;j<=h;j++)
			{
				if(bs[j][i])
				{
					ls++;
				}
			}
			lsa+=max(ls,h-ls);
		}
		ans=max(ans,lsa);
		return;
	}
	bs[cs].flip();
	dfs(cs+1);
	bs[cs].flip();
	dfs(cs+1);
}
int main()
{
	while(1)
	{
		ans=0;
		scanf("%d%d",&h,&l);
		if(h==0&&l==0)
		{
			break;
		}
		for(int i=1;i<=h;i++)
		{
			for(int j=1;j<=l;j++)
			{
				int ls;
				scanf("%d",&ls);
				bs[i][j]=ls;
			}
		}
		dfs(1);
		printf("%d\n",ans);
	}
	return 0;
}
















Measured memory_bytes: 2732
from heapq import heappush, heappop


def dijkstra(graph: list, n: int, v_s: int, INF: int = float('inf')) -> list:
    # graph[v_from] = [v_to, ...]
    dist = [INF] * n

    dist[v_s] = 0
    heap = [(0, v_s)]  # heap = [(dist[v], v), ...]
    while heap:
        _, v_from = heappop(heap)
        for v_to in graph[v_from]:
            dist_cand = dist[v_from] + 1
            if dist_cand < dist[v_to]:
                dist[v_to] = dist_cand
                heappush(heap, (dist[v_to], v_to))
    return dist


n, x, y = map(int, input().split())
x -= 1
y -= 1
g = [[] for _ in range(n)]
for i in range(n):
    if i - 1 >= 0:
        g[i].append(i - 1)
    if i + 1 < n:
        g[i].append(i + 1)
g[x].append(y)
g[y].append(x)

d = [dijkstra(g, n, i) for i in range(n)]
# print(*d, sep='\n')

ans = [0] * n
for i in range(n):
    for j in range(i + 1, n):
        ans[d[i][j]] += 1

for k in range(1, n):
    print(ans[k])


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    string O, E;
    cin >> O >> E;

    REP(i,0,SZ(E)) cout << O[i] << E[i];
    if(SZ(O) != SZ(E)) cout << O[SZ(O)-1];
    cout << endl;

    return 0;
}

/*



*/

Measured memory_bytes: 3580
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  if (s == "SUN")
    cout << 7 << endl;
  if (s == "MON")
    cout << 6 << endl;
  if (s == "TUE")
    cout << 5 << endl;
  if (s == "WED")
    cout << 4 << endl;
  if (s == "THU")
    cout << 3 << endl;
  if (s == "FRI")
    cout << 2 << endl;
  if (s == "SAT")
    cout << 1 << endl;
  return 0;
}


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

from collections import deque, defaultdict
from copy import deepcopy

MAX = 100000
NIL = -1

#グラフGはdictで管理する
G = defaultdict(lambda:deque())
color = [NIL]*MAX

#頂点r,探索ごとに異なる数cによって深さ優先探索をする関数
#つながっている部分は全て色が同じになる
def dfs(r, c):
    S = deque()
    S.append(r) 
    color[r] = c
    while S: #Sが存在する間以下の処理を実行
        u = S.popleft()
        for v in G[u]:#Gのvalueはqueueとなっている
            if color[v] == NIL:#色がない場合のみ以下の操作を行う
                color[v] = c
                S.append(v) #深さを深くして次の頂点を探す準備をする

def make_color():
    id = 1
    for u in range(n):
        if color[u] == NIL:
            dfs(u, id) #色を塗る
            id += 1 #色を変える
        
    
    
n, m = map(int, input().split())

for _ in range(m):
    s, t = map(int, input().split())
    G[s].append(t)
    G[t].append(s)
    

make_color()

q = int(input())
for _ in range(q):
    s, t = map(int, input().split())
    if color[s] == color[t]:
        print('yes')
    else:
        print('no')


Measured memory_bytes: 83384
#include<bits/stdc++.h>
#define N 300005
#define int long long
using namespace std;

int n,l,t;
int x[N],w[N];
int v[N];
signed main()
{
    scanf("%lld%lld%lld",&n,&l,&t);
    l*=2;t*=2;
    for(int i=1;i<=n;i++)
    {
        scanf("%lld%lld",&x[i],&w[i]);
        x[i]*=2;
        if(w[i]==2)w[i]=-1;
        v[i]=((x[i]+1LL*w[i]*t%l)%l+l)%l;
    }int kk=v[1];
    sort(v+1,v+n+1);
    for(int i=n+1;i<=3*n;i++)v[i]=v[i-n];

    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(w[i]!=w[1])
        {
            int rst=t;
            int dis;
            if(w[1]==1)dis=x[i]-x[1];
            else dis=x[1]+(l-x[i]);
            if(rst>dis/2)
            {
                rst-=dis/2;cnt++;
                cnt+=(rst-1)/(l/2);
            }
        }
    }
    //cout<<cnt<<endl;
    cnt%=n;
    int now=1;
    if(w[1]==-1)
    {
        for(int i=1;i<=cnt;i++)
        {
            now--;
            if(!now)now=n;
        }
    }
    else
    {
        for(int i=1;i<=cnt;i++)
        {
            now++;
            if(now==n+1)now=1;
        }
    }
    int pos=0;
    if(w[1]==1)
    {
        for(int i=1;i<=n;i++)
        {
            if(v[i]==kk)
            {
                pos=i;break;
            }
        }
    }
    else
    {
        for(int i=n;i>=1;i--)
        {
            if(v[i]==kk)
            {
                pos=i;break;
            }
        }
    }

    //cout<<now<<' '<<pos<<endl;

    for(int i=1;i<=n;i++)
    {
        printf("%lld\n",v[n+i-now+1+pos-1]/2);
    }
    return 0;
}


Measured memory_bytes: 7296
#include<cstdio>

using namespace std;

int a[101];
int b[101];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=n;i;i--){
		int o=0;
		for(int j=1;j<=i;j++)
			if(a[j]==j)o=j;
		if(o==0){
			printf("-1\n");
			return 0;
		}
		b[++b[0]]=o;
		for(int j=o;j<i;j++)
			a[j]=a[j+1];
	}
	for(int i=b[0];i;i--)
		printf("%d\n",b[i]);
}

Measured memory_bytes: 1664
#include<iostream>
#include<string>
using namespace std;
int main(){
	string s;
	while (cin >> s){
		if      (s[0] == s[1] && s[1] == s[2] && s[2] != 's')cout << s[0];
		else if (s[3] == s[4] && s[4] == s[5] && s[5] != 's')cout << s[3];
		else if (s[6] == s[7] && s[7] == s[8] && s[8] != 's')cout << s[7];
		else if (s[0] == s[3] && s[3] == s[6] && s[6] != 's')cout << s[0];
		else if (s[1] == s[4] && s[4] == s[7] && s[7] != 's')cout << s[1];
		else if (s[2] == s[5] && s[5] == s[8] && s[8] != 's')cout << s[2];
		else if (s[0] == s[4] && s[4] == s[8] && s[8] != 's')cout << s[0];
		else if (s[2] == s[4] && s[4] == s[6] && s[6] != 's')cout << s[2];
		else cout << 'd';
		cout << endl;
	}
}

Measured memory_bytes: 3044
#include <bits/stdc++.h>
#define rep0(i,n) for (int i = 0; i < (n); ++i)  //0index
#define rep1(i,n) for (int i = 1; i < (n); ++i)  //1index
#define REP(i,a,b) for (int i = a; i < (b); ++i)  //aからb - 1まで
#define mREP(i,a,b) for (int i = a; i > (b); --i)  //逆
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;  //最大値兼MOD
typedef long long ll;
using namespace std;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }  //GCD
int main(){
    int n;
    cin >> n;
    vector<int>v(n);
    rep0(i,n)cin>>v[i];
    int ans = 0;
    rep0(i,n){
        rep0(j,n){
            if(i == j)continue;
            ans += v[j] * v[i];
        }
    }
    cout << ans / 2<< endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input(''))
adl = input('')

a = list(map(int,adl.split(' ')))

number = 0

mod = 1000000007

amari = 0

all_a = 0

for i in range(n):
    all_a = all_a + a[i]

for i in range(n):
    all_a = all_a - a[i]
    number = number + (a[i] * all_a)
    number = number % mod
amari = number % mod
print(amari)


Measured memory_bytes: 93088
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
const int N = 55;
const int Mod = 2019;
#define pi acos(-1)
#define INF 1e18
#define INM INT_MIN
#define pb(a)  push_back(a)
#define mk(a,b) make_pair(a,b)
#define dbg(x) cout << "now this num is " << x << endl;
#define met0(axx) memset(axx,0,sizeof(axx));
#define metf(axx) memset(axx,-1,sizeof(axx));
#define sd(ax) scanf("%d",&ax)
#define sld(ax) scanf("%lld",&ax)
#define sldd(ax,bx) scanf("%lld %lld",&ax,&bx)
#define sdd(ax,bx) scanf("%d %d",&ax,&bx)
#define sddd(ax,bx,cx) scanf("%d %d %d",&ax,&bx,&cx)
#define sfd(ax) scanf("%lf",&ax)
#define sfdd(ax,bx) scanf("%lf %lf",&ax,&bx)
#define pr(a) printf("%d\n",a)
#define plr(a) printf("%lld\n",a)
/*
最短路的变形,首先要明确一些条件.
对于金币换银币的操作,在一个地方只能用一枚金币换到c[i]枚银币.(也就是说不能用2,3...枚金币,只能进行一次一枚的兑换)
*/
int n,m,s,c[N],dd[N];
struct Node{int to,a,b;};
vector<Node> G[N];
LL dis[N][N*N];//边界控制
void slove()
{
	for(int i=0;i<=n;++i)
		for(int j=0;j<=2500;++j) dis[i][j] = INF;
	typedef tuple<LL,int,int> ple;//dis,u,money,多元组容器
	priority_queue<ple,vector<ple>,greater<ple> > Q;
	s = min(2500,s);//s很可能会超过2500,需要过滤一下,不然会re
	dis[1][s] = 0;//初始化,类似dis[s] = 0.
	Q.push(ple(0,1,s));
	while(!Q.empty())
	{
		int u = get<1>(Q.top());
		LL d = get<0>(Q.top());
		int mon = get<2>(Q.top());//身上的银币数
		Q.pop();
		if(d > dis[u][mon]) continue;
		for(int i=0;i<G[u].size();++i)//更新相邻点的距离
		{
			int y = G[u][i].to,a = G[u][i].a,b = G[u][i].b;
			if(mon >= a && dis[y][mon-a] > d+b)
			{
				dis[y][mon-a] = d+b;
				Q.push(ple(dis[y][mon-a],y,mon-a));
			}
		}
		if(dis[u][min(2500,mon+c[u])] > dis[u][mon]+dd[u])//兑换
		{
			dis[u][min(2500,mon+c[u])] = dis[u][mon]+dd[u];
			Q.push(ple(dis[u][min(2500,mon+c[u])],u,min(2500,mon+c[u])));
		}
	}
}
int main()
{
	sddd(n,m,s);
	while(m--)
	{
		int x,y,a,b;
		sdd(x,y),sdd(a,b);
		G[x].push_back({y,a,b});
		G[y].push_back({x,a,b});
	}
	for(int i=1;i<=n;++i) sdd(c[i],dd[i]);
	slove();
	for(int i=2;i<=n;++i)
	{
		LL ans = INF;
		for(int j=0;j<=2500;++j) ans = min(ans,dis[i][j]);
		plr(ans);
	}
	//system("pause");
	return 0;
}

Measured memory_bytes: 6548
#Macで実行する時
import sys
import os
if sys.platform=="darwin":
	base = os.path.dirname(os.path.abspath(__file__))
	name = os.path.normpath(os.path.join(base, '../atcoder/input.txt'))
	sys.stdin = open(name)

l = list(input())
#print(l)
set_l = set(l)
if len(set_l)==1:
    print("No")
else:
    print("Yes")




Measured memory_bytes: 9112
// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
//
// See the bottom of file for solution.
// -----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

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

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let (N, M) = read!(usize, usize);
    let mut X = read![[i64]];
    X.sort();

    let mut Y = vec![0; M - 1];
    for i in 0..M - 1 {
        Y[i] = X[i + 1] - X[i];
    }
    Y.sort();
    Y.reverse();

    println!("{}", Y.iter().skip(N - 1).sum::<i64>())
}


Measured memory_bytes: 6396
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <sstream>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <numeric>
#include <bitset>
#include <ext/algorithm>
#include <ext/numeric>
#define ffor(_a,_f,_t) for(int _a=(_f),__t=(_t);_a<__t;_a++)
#define all(_v) (_v).begin() , (_v).end()
#define sz size()
#define pb push_back
#define SET(__set, val) memset(__set, val, sizeof(__set))
#define FOR(__i, __n) ffor (__i, 0, __n)
typedef long long LL; using namespace std;


const int MAXN = 1100;
const int MAXVAL = 5500;

vector<int> children[MAXN];
int X[MAXN], P[MAXN];
int dp[MAXN][MAXVAL];
int best[MAXN];

int main() {
	int N;
	cin >> N;
	FOR (i, N)
		children[i].clear();
	int w;
	FOR (i, N - 1) {
		cin >> P[i];
		P[i]--;
		children[P[i]].pb(i + 1);
	}
	FOR (i, N)
		cin >> X[i];
	int newval;
	for (int v = N - 1; v > -1; v--) {
		FOR (i, children[v].sz + 1)
			FOR (j, MAXVAL)
				dp[i][j] = -1;
		dp[0][0] = 0;
		FOR (i, children[v].sz) {
			int w = children[v][i];
			FOR (j, X[v] + 1) {
				if (dp[i][j] == -1)
					continue;
				newval = j + X[w];
				if (newval <= X[v]) {
					if (dp[i + 1][newval] == -1 || dp[i + 1][newval] > dp[i][j] + best[w])
						dp[i + 1][newval] = dp[i][j] + best[w];
				}
				newval = j + best[w];
				if (newval <= X[v]) {
					if (dp[i + 1][newval] == -1 || dp[i + 1][newval] > dp[i][j] + X[w])
						dp[i + 1][newval] = dp[i][j] + X[w];
				}
			}
		}
		best[v] = 1 << 30;
		int ch = children[v].sz;
		FOR (i, X[v] + 1)
			if (dp[ch][i] != -1)
				best[v] = min(best[v], dp[ch][i]);
		if (best[v] == 1 << 30) {
			cout << "IMPOSSIBLE" << endl;
			return 0;
		}
	}
	cout << "POSSIBLE" << endl;
	return 0;
}

Measured memory_bytes: 22784
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <math.h>
#include <queue>
#include <map>
#include <set>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;

struct edge {long long to,cost;};
typedef pair<long long,long long> P;
long long INF=100000000000000;
vector<edge> G[100020];
vector<edge> GR[100020];
long long d[100020];
long long dR[100020];
//dijkstra法の実装
//s・・・start point、v・・・number of points
void dijkstra(long long s,long long V){
  priority_queue<P,vector<P>,greater<P>> que;
  fill(d,d+V,INF);
  //始点への距離は0
  d[s]=0;
  que.push(P(0,s));

  while(!que.empty()){
    P p=que.top();que.pop();
    long long v=p.second;
    //これ以上小さくなり得ない奴は削除
    if(d[v]<p.first)continue;
    for(int i=0;i<G[v].size();++i){
      edge e=G[v][i];
      if(d[e.to]>d[v]+e.cost){
        d[e.to]=d[v]+e.cost;
        que.push(P(d[e.to],e.to));
      }
    }
  }
}

void dijkstra_rev(long long s,long long V){
  priority_queue<P,vector<P>,greater<P>> que_rev;
  fill(dR,dR+V,INF);
  //始点への距離は0
  dR[s]=0;
  que_rev.push(P(0,s));

  while(!que_rev.empty()){
    P p=que_rev.top();que_rev.pop();
    long long v=p.second;
    //これ以上小さくなり得ない奴は削除
    if(dR[v]<p.first)continue;
    for(int i=0;i<GR[v].size();++i){
      edge e=GR[v][i];
      if(dR[e.to]>dR[v]+e.cost){
        dR[e.to]=dR[v]+e.cost;
        que_rev.push(P(dR[e.to],e.to));
      }
    }
  }
}

int main(){
  long long n,m,s,t,u,v,a,b;
  cin>>n>>m>>s>>t;
  //条件入力
  for(int i=0;i<m;++i){
    cin>>u>>v>>a>>b;
    u--;v--;
    //円
    G[u].push_back(edge{v,a});
    G[v].push_back(edge{u,a});
    //スヌーく
    GR[v].push_back(edge{u,b});
    GR[u].push_back(edge{v,b});
  }
  //計算
  dijkstra(s-1,n);
  dijkstra_rev(t-1,n);
  long long ans=0;
  long long tmp;
  long long ans_list[n];
  for(int i=0;i<n;++i){
    tmp=(1000000000000000-(d[n-1-i]+dR[n-1-i]));
    if(tmp>ans){
      ans=tmp;
    }
      ans_list[n-1-i]=ans;
  }
  for(int i=0;i<n;++i){
    cout<<ans_list[i]<<"\n";
  }
return 0;
}

Measured memory_bytes: 19200
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<iostream>
# define ll int64_t
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;

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

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

ll gcd(ll a,ll b)
{
   if (a%b == 0) return(b);
   else return(gcd(b,a%b));
}

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

//累乗だってさ
ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}
//逆元だってさ
ll modinv(ll a,ll mod1) {
    return modpow(a, mod1 - 2, mod1);
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,m;
    cin>>n>>m;
    if(abs(n-m)>1) cout<<0<<endl;
    else if(n==m) cout<<2*factorial(n)*factorial(m)%mod<<endl;
    else cout<<factorial(n)*factorial(m)%mod<<endl;
    return 0;
}


Measured memory_bytes: 256
def kaijo(n):
    if n == 1 or n == 0:
        return 1
    else:
        return n * kaijo(n-1)

def counter(P):
    c = 0
    i = 0
    while i < len(P):
        c += (P[0]-1) * kaijo(len(P)-1)
        q = 1
        while q < len(P):
            if P[q] > P[0]:
                P[q] -= 1
            q += 1
        P = P[1:]
    return c

n = int(input())
P = list(map(int,input().split(' ')))
Q = list(map(int,input().split(' ')))
print(abs(counter(P)-counter(Q)))

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

int main(){
  int N,M;
  cin >> N >> M;
  priority_queue<long long> que;
  for (int i=0; i<N; i++){
    long long A;
    cin >> A;
    que.push(A);
  }
  for (int i=0; i<M; i++){
    long long tmp;
    tmp = que.top();
    que.pop();
    tmp /= 2;
    que.push(tmp);
  }
  long long ans = 0;
  while(!que.empty()){
    ans += que.top();
    que.pop();
  }
  cout << ans << endl;
}


Measured memory_bytes: 1400
#include <algorithm>
#include <iostream>
#include <string>
#include <algorithm>
#define ll long long
const int maxn = 1e5+5;
ll a[maxn];

using namespace std;

int main() {
	int n;
	cin >> n;
	long long res = 1; 
	long long  maxi = ((ll)1000000000) * ((ll)1000000000);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a,a+n);
	if (a[0] == 0) { cout << 0 <<endl; return 0; }
	for (int i = 0; i < n; i++) {
		ll remain = maxi / a[i];
		if (res > remain || res * a[i] > maxi) {
			cout << "-1" << endl; return 0;
		}
		res *= a[i];
	}
	cout << res;
	
}     

Measured memory_bytes: 4368
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var sp = input.split("\n");
var n = Number(sp[0]);
var ai = sp[1].split(" ").map(Number);
console.log( Math.min.apply( null, ai ) + " " + Math.max.apply( null, ai ) + " " + ai.reduce( ( a, b ) => a + b ) );

Measured memory_bytes: 18200