akhauriyash/Code-Regression huggingface dataset:
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_A&lang=jp
//ƒxƒ‹ƒ}ƒ“ƒtƒH[ƒh–@
#include<iostream>
#define MAX_V 100000
#define MAX_E 500000
#define INF 1e9
using namespace std;
struct edge {
	int from, to, cost;
};
edge es[MAX_E];
int d[MAX_V];
int V;
int E;



bool find_negative_loop(int s)
{
	d[s] = 0;
	int count = 0;
	while (true)
	{
		bool update = false;
		count++;
		for (int i = 0; i < E; i++)
		{

			if (d[es[i].from] != INF && d[es[i].to] > d[es[i].from] + es[i].cost)
			{
				if (count == V)
				{
					return true;
				}
				d[es[i].to] = d[es[i].from] + es[i].cost;
				update = true;
			}
		}
		if (update == false)
		{
			break;
		}


	}
	return false;
}

int main()
{

	int r;
	cin >> V >> E >> r;
	for (int i = 0; i < MAX_V; i++)
	{
		d[i] = INF;
	}
	for (int i = 0; i < E; i++)
	{
		cin >> es[i].from >> es[i].to >> es[i].cost;
	}
	if (find_negative_loop(r))
	{
		cout << "NEGATIVE CYCLE" << endl;
	}
	else
	{
		for (int i = 0; i < V; i++)
		{
			if (d[i] == INF)
			{
				cout << "INF" << endl;
			}
			else
			{
				cout << d[i] << endl;
			}
		}
	}

	return 0;
}


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

int main() {
    int N;
    cin >> N;
    int count = 0;
    for (int i = 0; i < N; i++) {
        int l, r;
        cin >> l >> r;
        count += (r - l) + 1;
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n, m int32
	fmt.Scanf("%d %d", &n, &m)

	a := make([]string, n)
	for i := int32(0); i < m; i++ {
		var pi int32
		var si string
		fmt.Scanf("%d %s", &pi, &si)
		if si == "AC" {
			a[pi-1] += "A"
		} else if si == "WA" {
			a[pi-1] += "W"
		}
	}

	cn := int32(0)
	pn := int32(0)
	for _, v := range a {
		tc, tp := count(v)
		cn += tc
		pn += tp
	}
	fmt.Println(cn, pn)
}

func count(s string) (int32, int32) {
	p := int32(0)
	for _, v := range s {
		if string(v) == "A" {
			return int32(1), p
		} else if string(v) == "W" {
			p++
		}
	}
	return int32(0), int32(0)
}


Measured memory_bytes: 8704
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define vector2(a,b,c) vector<vector<int>> a(b/*縦！w*/,vector<int>(c/*横！w*/))
#define INF 1e10
#define MOD 1e9+7
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;
signed main(){
  int a,b;
  cin>>a>>b;
  int c=a*3+b;
  cout<<c/2<<endl;
}

Measured memory_bytes: 256
n = int(input())
s = input()

keys = []

for i in range(10):
    i_str = str(i)
    if i_str not in s:
        continue
    else:
        t = s[s.index(i_str)+1:]
        for j in range(10):
            j_str = str(j)
            if j_str not in t:
                continue
            else:
                u = t[t.index(j_str)+1:]
                for k in range(10):
                    k_str = str(k)
                    if k_str in u:
                        keys.append(i_str + j_str + k_str)

print(len(keys))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <cstdlib>
#include <vector>
#include <string>
#include <unordered_map>

using namespace std;

int main() {
    int n;
    unordered_map<string, long long> mp;
    long long cnt = 0;
    cin >> n;
    string str[n];
    for(int i = 0; i < n; i++) {
      cin >> str[i];
    }
    for(int i = 0; i < n; i++) {
      sort(str[i].begin(), str[i].end());
      if(mp.count(str[i])){
        mp[str[i]] += 1;
      }else {
        mp[str[i]] = 1;
      }
    }
    for(auto& i : mp) {
        if(i.second > 1) {
          long long s = (i.second)*(i.second - 1) / 2;
          cnt += s;
        }
    }
    cout << cnt;

    return 0;
}


Measured memory_bytes: 17572
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#define gec getchar
#define puc putchar
#define File(S) (freopen(S".in","r",stdin),freopen(S".out","w",stdout))
using namespace std;
typedef long long ll;
template <typename T>
inline void read(T&a){
	static char ch;
	static bool sign;
	for(ch=gec(),sign=0;ch<'0'||ch>'9';ch=gec())sign^=(ch=='-');
	for(a=0;ch>='0'&&ch<='9';ch=gec())a=((a+(a<<2))<<1)+(ch^'0');
	if(sign)a=-a;
}
const int N=1e5+10;
vector<int>vec[N];
int dep[N],fa[N],Size[N];
void Dfs(int x,int f){
	fa[x]=f;Size[x]=1; 
	for(int i=0,Sz=vec[x].size();i<Sz;i++)
    	if(vec[x][i]!=f){
    		int son=vec[x][i];
			dep[son]=dep[x]+1;
        	Dfs(son,x);
        	Size[x]+=Size[son];
		}
}
int n,x,y;
int main()
{
	read(n);
	for(int i=1;i<n;i++){
		read(x);read(y);
		vec[x].push_back(y);
		vec[y].push_back(x);
	}
	Dfs(1,0);
	int D=dep[n]-((dep[n]-1)>>1),i;
	for(i=n;dep[i]>D;i=fa[i]);
	if(Size[i]>=n-Size[i])printf("Snuke");
	else printf("Fennec");
	return 0;
}


Measured memory_bytes: 14720
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };

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

#[allow(unused_macros)]
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
    };

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      n: usize,
      ps: [usize; n],
    }

    let mut b = ps.clone();
    b.sort();

    let mut diff = 0;
    for i in 0..n {
        if ps[i] != b[i] {
            diff += 1;
        }
    }
    if diff > 2 {
        puts!("{}\n", "NO");
    } else {
        puts!("{}\n", "YES");
    }
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define bit(n,m)(((n)>>(m))&1)

ll h,w;
char ss[20][20];
ll a[20];

void g(int s,int flag){
	if(s+1==(1<<w)){
		puts("YES");
		exit(0);
	}
	int i=0;
	while(bit(s,i))i++;
	if(flag){
		int b=1;
		rep(k,0,h)if(ss[k][i]!=ss[a[k]][i]){
			b=0;
			break;
		}
		if(b)g(s^(1<<i),0);
	}
	rep(j,i+1,w)if(!bit(s,j)){
		int b=1;
		rep(k,0,h)if(ss[k][i]!=ss[a[k]][j]){
			b=0;
			break;
		}
		if(b)g(s^(1<<i)^(1<<j),flag);
	}	
}

void f(int s,int flag){
	if(s+1==(1<<h))g(0,w%2);
	int i=0;
	while(bit(s,i))i++;
	if(flag){
		a[i]=i;
		f(s^(1<<i),0);
	}
	rep(j,i+1,h)if(!bit(s,j)){
		a[i]=j;
		a[j]=i;
		f(s^(1<<i)^(1<<j),flag);
	}
}

int main(){
	scanf("%lld%lld",&h,&w);
	rep(i,0,h)scanf(" %s",ss[i]);
	f(0,h%2);
	puts("NO");
}


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

typedef unsigned int U;
#define L 3194304
bool HA[L];
char T[256];

int main() {
    U n, sum, t;
    char c;
    T['A'] = (char)1, T['C'] = (char)2, T['G'] = (char)3, T['T'] = (char)4;
    scanf("%d", &n);
    while ( getchar() != '\n' );
    for ( register U i = 0; i++ < n; ) {
        sum = 0;
        t = 1;
        bool flag = ( c = getchar() ) == 'i';
        while ( ( c = getchar() ) != ' ' );
        while ( ( c = T[getchar()] ) != 0 ) {
            sum += c * t;
            t *= 4;
        }
        if ( flag ) {
            HA[sum] = true;
        } else {
            puts( HA[sum] ? "yes" : "no" );
        }
    }
    return 0;
}

Measured memory_bytes: 2100
#include <cstdint>
#include <vector>

using namespace std;

#define GRAPH_SIZE 100000

enum state_t {
  WHITE,
  GRAY,
  BLACK,
};

struct vertex_t {
  uint32_t color;
  vector<uint32_t> connections;
};

static vertex_t graph[GRAPH_SIZE];
static state_t state[GRAPH_SIZE];

static void colorize(uint32_t index, uint32_t color)
{
  if (state[index] == WHITE) {
    state[index] = GRAY;
    graph[index].color = color;
    for (uint32_t i = 0; i < graph[index].connections.size(); i++) {
      colorize(graph[index].connections[i], color);
    }
    state[index] = BLACK;
  }
}

void check_connection(size_t num)
{
  for (uint32_t i = 0; i < num; i++) {
    state[i] = WHITE;
  }

  uint32_t color = 1;
  for (uint32_t i = 0; i < num; i++) {
    colorize(i, color);
    color++;
  }
}

#include <iostream>

int32_t main()
{
  uint32_t n, m;
  cin >> n >> m;

  for (uint32_t i = 0; i < m; i++) {
    uint32_t index, to;
    cin >> index >> to;
    graph[index].connections.push_back(to);
    graph[to].connections.push_back(index);
  }

  check_connection(n);

  uint32_t qs;
  cin >> qs;

  for (uint32_t i = 0; i < qs; i++) {
    uint32_t from, to;
    cin >> from >> to;

    if (graph[from].color == graph[to].color) {
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }
  }

  return 0;
}

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

int main()
{
  int a,b;
  int n=1;
  int cnt=0;

  cin >> a >> b;
  if(n<b)
  {
    n=a, cnt++;
  }
  while(n<b)
  {
    n+=a-1;
    cnt++;
  }

  cout << cnt << endl;
}

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

void bubbleSort(string A[], int n) {
    for (int i=0; i<n; i++) {
        for (int j=n-1; j > i; j--) {
            if ((A[j][1] - '0') < (A[j-1][1] - '0')) {
                string t=A[j]; A[j]=A[j-1]; A[j-1]=t;
            }
        }
    }
}

void selectionSort(string A[], int n) {
    for (int i=0; i<n-1; i++) {
        int mini = i;
        for (int j=i+1; j<n; j++) {
            if ((A[j][1] - '0') < (A[mini][1] - '0')) mini = j;
        }
        string t=A[mini]; A[mini]=A[i]; A[i]=t;
    }
}

void pp(string A[], int n) {
    for (int i=0; i<n; i++) {
        cout << A[i];
        if (i < n-1) cout << " ";
    }
    cout << "\n";
}
int main ()
{
    int n;
    cin >> n;
    string A[36];
    string B[36];
    string S[36];
    for (int i=0; i<n; i++) cin >> A[i];
    for (int i=0; i<n; i++) B[i] = A[i];
    for (int i=0; i<n; i++) S[i] = A[i];
    bubbleSort(B, n);
    selectionSort(S, n);
    pp(B, n);
    cout << "Stable\n";
    pp(S, n);
    bool stable = true;
    for (int i=0; i<n; i++) {
        if (B[i] != S[i]) stable = false;
    }
    if (stable) {
        cout << "Stable\n";
    } else {
        cout << "Not stable\n";
    }
    return 0;
}

Measured memory_bytes: 1208
#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define ft first
#define sd second
#define Max 10000005
bool arr[Max];//initialize as false all the elements
vector<ll>prime;

void seive()
{
    arr[1]=true;
    for(ll i=4; i<=Max; i+=2)
    {
        arr[i]=true;
    }
    for(ll i=3; i*i<=Max; i+=2)
    {
        if(arr[i]==false)
        {
            for(ll j=i*i; j<=Max; j=j+(2*i))
                arr[j]=true;
        }
    }
    prime.push_back(2);
    for(ll i=3; i<=Max; i+=2)
    {
        if(arr[i]==false)
            prime.push_back(i);
    }

}

int main()
{

    seive();
    ll t,n,m;
    cin>>n;
    ll l=lower_bound(prime.begin(),prime.end(),n)-prime.begin();
    cout<<prime[l];

}







Measured memory_bytes: 20204
#include<stdio.h>

int main (void){
	
	int H,W,i,t;
	
	for(;;){
	scanf("%d %d",&H,&W);
	if(H==0&&W==0)break;
	for(i=1;i<=H;i++){
		for(t=1;t<=W;t++){
			if((i+t)%2 == 0){
				printf("#");
			}else{
				printf(".");
			}
		}
	printf("\n");
	}
	printf("\n");
	}
	
return 0;
}

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

long h[333], d[333][333];
int main() {
    int n, k;
    cin >> n >> k;
    for(int i = 0; i < n; i++)
        cin >> h[i];
    for(int x = 0; x < n; x++)
        fill(d[x], d[x] + k + 1, 1e18);
    for(int i = 0; i < n; i++) {
        for(int j = k + 1; j--;) {
            d[i][j] = 1e18;
            for(int x = 0; x <= n; x++) {
                if(i)
                    d[i][j] = min(d[i][j], d[x][j] + max(h[i] - h[x], 0l));
                else
                    d[i][j] = h[i];
                if(x != i)
                    d[x][j] = j ? d[x][j - 1] : 1e18;
            }
        }
    }
    for(int i = 0; i <= n; i++)
        d[0][k] = min(d[0][k], d[i][k]);
    cout << d[0][k] << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  string a, b; cin >> a >> b;
  auto pa = make_pair(a.size(), a);
  auto pb = make_pair(b.size(), b);
  if (pa > pb) {
    cout << "GREATER" << '\n';
  } else if (pa < pb) {
    cout << "LESS" << '\n';
  } else {
    cout << "EQUAL" << '\n';
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T iabs(const T& x) { return max(x, -x); }
// #define abs gabs

const i64 mod = 1e9 + 7;
i64 ipow(i64 a, i64 b) {
    i64 x = a, y = 1;
    for (; b > 0; b >>= 1) {
        if (b & 1) (y *= x) %= mod;
        (x *= x) %= mod;
    }
    return y;
}
i64 inv(i64 x) {
    return ipow(x, mod - 2);
}
i64 fact(i64 x) {
    static vector<i64> f;
    i64 i = f.size();
    if (x >= i) {
        f.resize(x + 1);
        for (; i <= x; ++i) {
            f[i] = i == 0 ? 1 : i * f[i - 1] % mod;
        }
    }
    return f[x];
}
i64 perm(i64 n, i64 k) {
    return k <= n ? fact(n) * inv(fact(n - k)) % mod : 0;
}
i64 conb(i64 n, i64 k) {
    return k <= n ? fact(n) * inv(fact(k) * fact(n - k) % mod) % mod : 0;
}

int main() {
    i64 n, m, k;
    cin >> n >> m >> k;
    i64 ans = 0;
    for (int i = 0; i < 2; ++i) {
        i64 c = n * n % mod * conb(n * m - 2, k - 2) % mod;
        for (i64 d = 1; d < m; ++d) {
            (ans += (m - d) * d % mod * c % mod) %= mod;
        }
        swap(n, m);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
/*
 * hujx.cpp
 *
 *  Created on: 2015年5月21日
 *      Author: dell
 */
#include<stdio.h>
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<time.h>
#include<queue>
#include<stack>
#include<iterator>
#include<math.h>
#include<stdlib.h>
#include<limits.h>
#include<map>
#include<set>
#include<bitset>
//#define ONLINE_JUDGE
#define eps 1e-5
#define INF 0x7fffffff
#define FOR(i,a) for((i)=0;i<(a);(i)++)
#define MEM(a) (memset((a),0,sizeof(a)))
#define sfs(a) scanf("%s",a)
#define sf(a) scanf("%d",&a)
#define sfI(a) scanf("%I64d",&a)
#define pf(a) printf("%d\n",a)
#define pfI(a) printf("%I64d\n",a)
#define pfs(a) printf("%s\n",a)
#define sfd(a,b) scanf("%d%d",&a,&b)
#define sft(a,b,num) scanf("%d%d%d",&a,&b,&num)
#define for1(i,a,b) for(int i=(a);i<b;i++)
#define for2(i,a,b) for(int i=(a);i<=b;i++)
#define for3(i,a,b)for(int i=(b);i>=a;i--)
#define MEM1(a) memset(a,0,sizeof(a))
#define MEM2(a) memset(a,-1,sizeof(a))
#define ll long long
const double PI=acos(-1.0);
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
using namespace std;
//#pragma comment(linker,"/STACK:1024000000,1024000000")
int n,m,c;
#define N 210
#define M 100010
#define Mod 1000000000
#define p(x,y) make_pair(x,y)
const int MAX_len=550;
int main(){
    ll a,b;
    while(scanf("%lld%lld",&a,&b)!=EOF){
    	ll GCD = gcd(a,b);
    	ll LCM = a/GCD*b;
    	printf("%lld %lld\n",GCD,LCM);
    }
    return 0;
}

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

int main(){
  int n,tmp,ans_max = 0,ans_min = 0;
  bool colors[8];
  int flg = 0;

  for(int i = 0; i < 8; i++){
    colors[i] = false;
  }

  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> tmp;

    if( 1 <= tmp and tmp <= 399 and colors[0] == false) colors[0] = true;
    else if( 400 <= tmp and tmp <= 799 and colors[1] == false) colors[1] = true;
    else if( 800 <= tmp and tmp <= 1199 and colors[2] == false) colors[2] = true;
    else if( 1200 <= tmp and tmp <= 1599 and colors[3] == false) colors[3] = true;
    else if( 1600 <= tmp and tmp <= 1999 and colors[4] == false) colors[4] = true;
    else if( 2000 <= tmp and tmp <= 2399 and colors[5] == false) colors[5] = true;
    else if( 2400 <= tmp and tmp <= 2799 and colors[6] == false) colors[6] = true;
    else if( 2800 <= tmp and tmp <= 3199 and colors[7] == false) colors[7] = true;
    else if(3200 <= tmp) ans_max++;
  }

  for(int i = 0; i < 8; i++){
    if(colors[i] == true){
      ans_max++;
      ans_min++;
      flg = 1;
    }
    //cout << colors[i];
  }
  if(flg == 0) ans_min = 1;
  //cout << endl;
  cout << ans_min << ' ' << ans_max << endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(int(x) for x in input().split())
B = [0]
a = len(A)
sa = sorted(A)
su = 0
p = 10**9+7

for i in range(a):
    B.append(B[i] + sa[i])

for j in range(a):
    su += sa[j]*B[j]

print(su%p)

Measured memory_bytes: 31608
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <climits>

using namespace std;

int main() {
	int n, m, s, g1, g2;

	while( true ){
		cin >> n >> m >> s >> g1 >> g2;

		if(n == 0 && m == 0 && s == 0 && g1 == 0 && g2 == 0) {
			break;
		}

		int b1;
		int b2;
		int c;

		vector< vector < int > > map(n + 1, vector< int >(n + 1, INT_MAX / 4));

		for(int i = 0; i < m; i++) {
			cin >> b1 >> b2 >> c;
			map[b1][b2] = c;
		}
		for(int i = 0; i < n + 1; i++) {
			map[i][i] = 0;
		}
		
		for(int k = 0; k < n + 1; k++) {
			for(int i = 0; i < n + 1; i++) {
				for(int j = 0; j < n + 1; j++) {
					map[i][j] = min(map[i][j], map[i][k] + map[k][j]);
				}
			}
		}
		
		int total = INT_MAX / 2;
		for(int k = 0; k < n + 1; k++) {
			total = min(total, map[s][k] + map[k][g1] + map[k][g2]);
		}

		cout << total << endl;

	}
}

Measured memory_bytes: 1264
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define sz(a) ll((a).size())
#define all(a) (a).begin(), (a).end()
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPD(i,n) for(int i=(n)-1;i>=0;--i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define FORD(i,a,b) for(int i=(a);i>=(b);--i)
const ll MOD = 1E9+7;
const int INF = 1E9;
const double EPS = 1E-9;
const double PI = atan(1.0) * 4.0;
template<class T> T getbit(T s, int i) {return s>>i&1;}
template<class T> void flipbit(T& s, int i) {s^=(1LL<<i);}
constexpr int cntbit(ll x) {return __builtin_popcountll(x);}
constexpr int lg2(ll x) {return __lg(x);} // return int(log2(x))
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); 
ll fpow(ll a,ll p){ll res=1LL;while(p){if(p&1LL) res=res*a%MOD;a=a*a%MOD;p>>=1LL;} return res;}

const int N=2005;
int n,a[2*N],invb[N],invw[N];
int posb[N],posw[N];
ll costb[N][N],costw[N][N],dp[N][N];
char c[2*N];

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n;
	REP(i,2*n){
		cin>>c[i]>>a[i];
		if(c[i]=='B') posb[a[i]]=i;
		else posw[a[i]]=i;
	}
	FOR(i,0,2*n-1)
		FOR(j,i+1,2*n-1)
			if(c[i]==c[j]&&a[i]>a[j]){
				if(c[i]=='B') ++invb[a[i]];
				else ++invw[a[i]];
			}
	FOR(i,1,n){
		costb[i][0]=invb[i];
		costw[0][i]=invw[i];
		FOR(j,1,n){
			costb[i][j]=costb[i][j-1];
			costw[j][i]=costw[j-1][i];
			if(posw[j]>posb[i]) ++costb[i][j];
			if(posb[j]>posw[i]) ++costw[j][i];
		}
	}
	FOR(i,0,n)
		FOR(j,0,n) dp[i][j]=INF;
	dp[0][0]=0;
	FOR(i,0,n)
		FOR(j,0,n){
			if(i+1<=n) dp[i+1][j]=min(dp[i+1][j],dp[i][j]+costb[i+1][j]);
			if(j+1<=n) dp[i][j+1]=min(dp[i][j+1],dp[i][j]+costw[i][j+1]);
		}
	cout<<dp[n][n]<<'\n';
}



Measured memory_bytes: 97716
/**
 *      AGC 7 A
 *      author  : kyomukyomupurin
 *      created : 2018-10-11 10:22:02
**/

#include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#define int64 long long
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int H, W; cin >> H >> W;
    string A[H] = {};
    for (auto i = 0; i < H; ++i) {
        cin >> A[i];
    }

    int cnt = 0;

    for (auto i = 0; i < H; ++i) {
        for (auto j = 0; j < W; ++j) {
            if (A[i][j] == '#') ++cnt;
        }
    }

    cnt == H + W - 1 ? cout << "Possible" << endl : cout << "Impossible" << endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());
		long k = Integer.parseInt(sc.next());
		long[] a = new long[n + 1];
		long[] b = new long[m + 1];
		a[0] = 0;
		b[0] = 0;
		for (int i = 1; i <= n; i++) {
			a[i] = Integer.parseInt(sc.next()) + a[i - 1];
		}
		for (int i = 1; i <= m; i++) {
			b[i] = Integer.parseInt(sc.next()) + b[i - 1];
		}
		int count = 0;
		int idx = m;
		for (int i = 0; i <= n && a[i] <= k; i++) {
			while (a[i] + b[idx] > k) {
				idx--;
			}
			count = Math.max(count, i + idx);
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 63420
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define popcnt(x) __builtin_popcount(x)
#define popcntll(x) __builtin_popcountll(x)
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class A500YenCoins {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        int K, X;
        in>>K>>X;
        if(500*K>=X) out<<"Yes\n";
        else out<<"No\n";
    }
};


int main() {
	A500YenCoins solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3604
# -*- coding: utf-8 -*-
H, W = map(int, input().split(' '))
table = [input() for _ in range(H)]

# BFS
dists = [[float('inf') for _ in range(W)] for _ in range(H)]
dists[0][0] = 0
nexts = [(1,0), (-1,0), (0,1), (0,-1)]

buf = [(0, 0)]
while buf:
    h, w = buf.pop(0)

    for dh, dw in nexts:
        next_h, next_w = h+dh, w+dw
        if 0 <= next_h < H and 0 <= next_w < W:
            if table[next_h][next_w] == '.':
                if dists[next_h][next_w] == float('inf'):
                    dists[next_h][next_w] = dists[h][w] + 1
                    buf.append((next_h, next_w))

num_white = 0
for row in table:
    for r in row:
        if r == '.':
            num_white += 1

# print(num_white)
if dists[H-1][W-1] == float('inf'):
        print(-1)

else:
    print(num_white - dists[H-1][W-1] - 1)




Measured memory_bytes: 41840
#include<stdio.h>
#include<string.h>
#include <math.h>

#define MAX 7777777777


typedef struct{
  int a1;
  int a2;
  int a3;
  int a4;
} Node;
int flag;
int hfunc(Node *,int,int);
void pre(Node *,int);
void in(Node *,int);
void pos(Node *,int);

int main(){
  
  int n,i,j,degree,point,c1,c2,depth=0,sum=0,height,root=0;
 
  Node z[25];
  
  for(i=0;i<25;i++){
    
    z[i].a1=z[i].a2=z[i].a3=z[i].a4=-1;
  }
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    
    scanf("%d%d%d",&point,&c1,&c2);
    
    if(c1!=-1)sum++;
    
    if(c2!=-1)sum++;
    
    z[point].a3=c1;
    
    z[point].a2=c2;
    
    if(c1!=-1){
      
    z[c1].a4=c2;
    
    z[c1].a1=point;
    
    }
    if(c2!=-1){
      
    z[c2].a4=c1;
    
    z[c2].a1=point;
    
    }
  }
  for(i=0;i<=sum;i++){
    
    if(z[i].a1==-1){root=i; break;}
    
  }
  printf("Preorder\n");
  
  pre(z,root);
  
  printf("\nInorder\n");
  
  in(z,root);
  
  printf("\nPostorder\n");
  
  pos(z,root);
  
  printf("\n");
    

  

  return 0;
}
void pre(Node z[],int i){
  
  if(z[i].a3==-1 && z[i].a2==-1){
    
    printf(" %d",i);
    
    return;
  }
  printf(" %d",i);
  
  if(z[i].a3!=-1)
    
  pre(z,z[i].a3);
  
  if(z[i].a2!=-1)
    
  pre(z,z[i].a2);
}
void in(Node z[],int i){
  
  if(z[i].a3==-1 && z[i].a2==-1)
    
  {
    printf(" %d",i);
    
    return;
  }
  if(z[i].a3!=-1)
    
  in(z,z[i].a3);
  
  printf(" %d",i);
  
  if(z[i].a2!=-1)
    
  in(z,z[i].a2);
}
void pos(Node z[],int i){
  
  if(z[i].a3==-1 && z[i].a2==-1)
    
    {
      
      printf(" %d",i);
      
      return;
    }
  if(z[i].a3!=-1)
    
  pos(z,z[i].a3);
  
  if(z[i].a2!=-1)
    
  pos(z,z[i].a2);
  
  printf(" %d",i);
}    




Measured memory_bytes: 2068
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int Q = sc.nextInt();
		int[][] A = new int[N][N];
		for(int i = 0; i < M; i++)
			A[sc.nextInt()-1][sc.nextInt()-1]++;
		int[][] S = new int[N+1][N+1];
		for(int i = 0; i < N; i++)
			for(int j = 0; j < N; j++)
				S[i+1][j+1] = S[i][j+1] + S[i+1][j] - S[i][j] + A[i][j];
		for(int i = 0; i < Q; i++) {
			int p = sc.nextInt()-1;
			int q = sc.nextInt();
			System.out.println(S[q][q]+S[p][p]-S[p][q]-S[q][p]);
		}
	}

}

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

int main()
{
    string S, T;
    cin >> S >> T;
    int cnt = 0;
    for (size_t i=0; i<=2; i++) {
        if (S[i] == T[i])
            ++cnt;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
class UnionFind:
    def __init__(self):
        '''\
Create an empty union find data structure.'''
        self.num_weights = {}
        self.parent_pointers = {}
        self.num_to_objects = {}
        self.objects_to_num = {}
        self.__repr__ = self.__str__
    def insert_objects(self, objects):
        '''\
Insert a sequence of objects into the structure.  All must be Python hashable.'''
        for object in objects:
            self.find(object);
    def find(self, object):
        '''\
Find the root of the set that an object is in.
If the object was not known, will make it known, and it becomes its own set.
Object must be Python hashable.'''
        if not object in self.objects_to_num:
            obj_num = len(self.objects_to_num)
            self.num_weights[obj_num] = 1
            self.objects_to_num[object] = obj_num
            self.num_to_objects[obj_num] = object
            self.parent_pointers[obj_num] = obj_num
            return object
        stk = [self.objects_to_num[object]]
        par = self.parent_pointers[stk[-1]]
        while par != stk[-1]:
            stk.append(par)
            par = self.parent_pointers[par]
        for i in stk:
            self.parent_pointers[i] = par
        return self.num_to_objects[par]
    def union(self, object1, object2):
        '''\
Combine the sets that contain the two objects given.
Both objects must be Python hashable.
If either or both objects are unknown, will make them known, and combine them.'''
        o1p = self.find(object1)
        o2p = self.find(object2)
        if o1p != o2p:
            on1 = self.objects_to_num[o1p]
            on2 = self.objects_to_num[o2p]
            w1 = self.num_weights[on1]
            w2 = self.num_weights[on2]
            if w1 < w2:
                o1p, o2p, on1, on2, w1, w2 = o2p, o1p, on2, on1, w2, w1
            self.num_weights[on1] = w1+w2
            del self.num_weights[on2]
            self.parent_pointers[on2] = on1
    def __str__(self):
        '''\
Included for testing purposes only.
All information needed from the union find data structure can be attained
using find.'''
        sets = {}
        for i in range(len(self.objects_to_num)):
            sets[i] = []
        for i in self.objects_to_num:
            sets[self.objects_to_num[self.find(i)]].append(i)
        out = []
        for i in sets.values():
            if i:
                out.append(repr(i))
        return ', '.join(out)

uf = UnionFind()
n, m = map(int, input().split())
uf.insert_objects(range(1, n+1))
for _ in range(m):
    a,b = map(int, input().split())
    uf.union(a,b)
from collections import defaultdict
cnt = defaultdict(int)
for i in uf.objects_to_num:
    cnt[uf.find(i)] += 1
print(max(cnt.values()))

# print(len(set(uf.find(k) for k in uf.objects_to_num)))


Measured memory_bytes: 83060
def f(n):
    a = [1]
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return list(set(a))

import fractions
A,B=map(int,input().split())
gcd=fractions.gcd(A,B)
print(len(f(gcd)))

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

int main (){
   int n;
   bool tf=true;
   cin >> n;
   map <int,int> mp;
   rep(i,n){
       int x;
       cin >> x;
       mp[x]++;
   }
   for (auto &p:mp){
       int a=p.second;
       if(a!=1) {
           tf=false;
           break;
       }
   }

   if(tf) cout << "YES";
   else cout << "NO";
    return 0;
}


Measured memory_bytes: 9600
#include <stdio.h>

int main(void)
{
	int num;
	int i;
	int cars[10];
	
	for (i = 0; i < 10; i++){
		cars[i] = 0;
	}
	
	while (scanf("%d", &num) == 1){
		if (num != 0){
			for (i = 0; i < 10; i++){
				if (cars[i] == 0){
					cars[i] = num;
					break;
				}
			}
		}
		else {
			for (i = 9; i >= 0; i--){
				if (cars[i] != 0){
					printf("%d\n", cars[i]);
					cars[i] = 0;
					break;
				}
			}
		}
	}
	return (0);
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; --i)
#define FOR(i, n, m) for (int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

typedef long long ll;
/**
 * C問以降は ll を使う.
 * double型にするのを忘れない.
 * nC2の求め方 (1/2)*n*(n-1)
 * vector<型> 変数名(要素数, 初期値)
 */
int main()
{
    int N, K;
    cin >> N >> K;
    int cnt = 0;
    REP(i, N)
    {
        int h;
        cin >> h;
        if(h >= K) {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define debugP int debug_point; cin>>debug_point;
const ll MOD= 1e9 + 7;
template <typename T>
void putv(vector<T>& V){
	// cout << "The elements in the vector are: " << endl;
	for(auto x: V)
		cout << x << " ";
	cout << endl;
}
template <class T>
vector<T> getv(ll n){
	vector<T> Vector_temp;
	rep(i,n){
		T input;
		cin >> input;
		Vector_temp.emplace_back(input);
	}
	return Vector_temp;
}
ll gcd(ll c,ll b){
    while(1){
        if(c%b!=0){
        ll tmp=b;
        b=c%b;
        c=tmp;
        }else{
            return b;
        }
    }
}
/* <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3*/


int main(){
    ll n,x;
    cin>>n>>x;
    vec(a,n);
    a=getv<ll>(n);
    vec(b,n-1);
    rep(i,n-1){
        b[i]=(a[i]+a[i+1]-x>0?a[i]+a[i+1]-x:0);
    }
    ll ans=0;
    rep(i,n-2){
        if(b[i]>0){
            if(b[i]<=a[i+1]){
                ((b[i+1]-b[i])>0?b[i+1]-=b[i]:b[i+1]=0);
                ans+=b[i];
            }else{
                ((b[i+1]-b[i])>0?b[i+1]-=a[i+1]:b[i+1]=0);
                ans+=b[i];
            }
        }
    }
    ans+=b[n-2];
    op(ans);
    return 0;
}

Measured memory_bytes: 2168
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000;

int main(){
    int n;
    cin >> n;
    int x[n];
    rep(i, n) cin >> x[i];
    int ans = inf;
    for (int i = 1; i <= 100; i++) {
        int a = 0;
        rep (j, n) {
            a += (i - x[j]) * (i - x[j]);
        }
        ans = min(ans, a);
    }

    cout << ans << endl;

    return 0;
} 

Measured memory_bytes: 3628
import java.util.*;
class Main{
	static Scanner scan = new Scanner(System.in);
	public static void main(String[] argv){
		String s = scan.next();
		char[] c = s.toCharArray();
		for(int i=0;i < c.length;i++){
			if(c[i]=='1')
				c[i] = '9';
			else
				c[i] = '1';
		}
		System.out.println(String.valueOf(c));
	}
}

Measured memory_bytes: 21716
n=int(input())
a=list(map(int,input().split()))

ans=[]
if n%2==0:
    num=n+2
    for i in range(n):
        if num==2:
            num=1
            ans.append(a[0])
        elif num%2==0:
            num-=2
            ans.append(a[num-1])
        else:
            num+=2
            ans.append(a[num-1])
else:
    num=n
    for i in range(n):
        if num==1:
            ans.append(a[0])
            num=2
        elif num%2!=0:
            ans.append(a[num-1])
            num-=2
        else:
            ans.append(a[num-1])
            num+=2
print(*ans)

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

#define vec                vector<int>
#define vecll              vector<ll>
#define vecd               vector<double>
#define vecst              vector<string>
#define vecb               vector<bool>
#define vec2(var, n, m)    vector<vector<int>> var(n, vector<int>(m, 0))
#define vecll2(var, n, m)  vector<vector<ll>> var(n, vector<ll>(m, 0))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt(ok ? "yes" : "no");}
//----------------------------------------------------------------
class Graph{

public:
  vector<vector<int>> graphs;
  vector<bool> check; // For DFS
  vector<ll> dist;   // For BFS
  queue<int> q; // For BFS

  Graph(int n){
    graphs.resize(n);
    init(n);
  }
  ~Graph(){}

  void addedge(int u, int v){
    u--; v--;
    graphs[u].push_back(v);
    //graphs[v].push_back(u);
  }

  void addedge_cin(int m){
    rep(i,m){
      int a, b;
      cin >> a >> b;
      addedge(a, b);
    }
  }

  void init(int n){
    check.resize(n, false);
    dist.resize(n, -1);
  }

  void reset(){
    rep(i,check.size()){
      check[i]=false;
      dist[i]=-1;
    }
  }

  void dfs(int v)
  {
    check[v] = true;

    for(auto next_v : graphs[v]){
      if(check[next_v]) continue;
      dfs(next_v);
    }
  }

  void bfs(int v)//----------------------
  {
    dist[v] = 0;
    q.push(v);

    while(!q.empty()){
      int cur_v = q.front();
      q.pop();

      for(int next_v : graphs[cur_v]){
        if(dist[next_v] != -1){
          continue;
        }

        dist[next_v] = dist[cur_v] + 1;
        q.push(next_v);
      }
    }
  }//-----------------------

};

int main(void) {
  int n;
  cin >> n;
  Graph g(n);

  rep(i,n){
    int ver, num;
    cin >> ver >> num;
    rep(j,num){
      int tmp;
      cin >> tmp;
      g.addedge(ver, tmp);
    }
  }

  g.bfs(0);

  rep(i,n){
    prt2(i+1, g.dist[i]);
  }

}



Measured memory_bytes: 3160
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    long long n, k; std::cin >> n >> k;
    std::vector<long long> pos, neg;
    long long zero = 0;
    for (int i = 0; i < n; i++) {
        long long a; std::cin >> a;
        if (a == 0) {
            zero++;
            continue;
        }
        (a >= 0 ? pos : neg).push_back(std::abs(a));
    }
    std::sort(pos.begin(), pos.end());
    std::sort(neg.begin(), neg.end());
    auto ok = [&](long long targ) -> bool {
        long long cnt = 0;
        if (targ >= 0) {
            for (long long t : pos) {
                cnt += std::upper_bound(pos.begin(), pos.end(), targ / t)
                    - pos.begin();
                cnt -= targ / t >= t;
            }
            for (long long t : neg) {
                cnt += std::upper_bound(neg.begin(), neg.end(), targ / t)
                    - neg.begin();
                cnt -= targ / t >= t;
            }
            cnt /= 2;
            cnt += pos.size()*neg.size();
            cnt += zero*(n - zero) + zero*(zero - 1) / 2;
        }
        else {
            for (long long t : pos) {
                cnt += neg.end() - std::lower_bound(
                    neg.begin(), neg.end(), (std::abs(targ) + t - 1) / t);
            }
        }
        return cnt >= k;
    };
    long long lo = -2e18, hi = 2e18;
    while (hi - lo > 1) {
        long long mid = lo + (hi - lo) / 2;
        if (ok(mid)) hi = mid;
        else lo = mid;
    }
    std::cout << hi << std::endl;
    return 0;
}


Measured memory_bytes: 2420
#include<iostream>

using namespace std;

long euclidean(long n, long m) {
    if (n == m)return m;
    if (n > m)swap(n, m);
    return euclidean(m - n, n);
}

int main() {
    long n, m;
    cin >> n >> m;
    cout << euclidean(n, m) << endl;
}


Measured memory_bytes: 3084
#include <cstdio>
#include <vector>
using namespace std;
vector<int> G[100001];
int N, M, H[100001], A[100001], B[100001], ans;
int main()
{
	scanf("%d%d", &N, &M);
	for(int i=1;i<=N;i++)
	    scanf("%d", &H[i]);
	for(int i=1;i<=M;i++)
	{
		scanf("%d%d", &A[i], &B[i]);
		G[A[i]].push_back(B[i]);
		G[B[i]].push_back(A[i]);
	}
	for(int i=1;i<=N;i++)
	{
		int sz = G[i].size(), ok = 1;
		for(int j=0;j<sz;j++)
		{
			int v = G[i][j];
			if(H[i]<=H[v])
			{
//				printf("%d不行\n", i);
				ok = 0;
				break;
			}
		}
		if(ok)
		    ans++;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 9548
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
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()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;
    cin>>a>>b;
    if(a<=8&&b<=8)cout<<"Yay!"<<"\n";
    else cout<<":("<<"\n";
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const int N = 2e5+5;
ll dp[N][2],pre[N];
int n,c[N];
int main(){
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>c[i];
    }
    dp[0][0]=1;
    for(int i=1;i<=n;i++){
        if(c[i]==c[i-1]){
            dp[i][0]=dp[i-1][0];
            dp[i][1]=dp[i-1][1];
        } else {
            dp[i][0]=(dp[i-1][0]+dp[i - 1][1])%mod;
            dp[i][1]=pre[c[i]];
            pre[c[i]]=(pre[c[i]]+dp[i][0])%mod;
        }
    }
    cout<<(dp[n][1]+dp[n][0])%mod<<endl;
}



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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> count(n,0);
  int v;
  for(int i=0;i<2*m;i++){
    cin >> v;
    count[v-1]++;
  }
  for(int i=0;i<n;i++){
    if(count[i]%2){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 640
// taskkill -im A.exe -f
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag,
        tree_order_statistics_node_update>
        PBDS;

#define int long long
#define endl "\n"
#define MOD 10
#define pb push_back
const int mxN = 1e6 + 500;
int ar[mxN];


int32_t main() {

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int t;
	// cin >> t;
	t = 1;

	while (t--) {

		int n, c = 0, ans = 0, l = 0;
		cin >> n;

		for (int i = 0; i < n; ++i)
		{
			cin >> ar[i];
		}

		for (int i = 0; i < n - 1; i++) {
			if (ar[i] > ar[i + 1]) {
				ans += abs(ar[i] - ar[i + 1]);
				ar[i + 1] += abs(ar[i] - ar[i + 1]);
			}
		}

		cout << ans;

		cout << endl;
	}

	return 0;
}



Measured memory_bytes: 5152
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace __gnu_pbds;
using namespace std;

#define ld long double
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define int long long
#define ull unsigned long long
#define pii pair<int,int>
#define vii vector<int>
#define f first
#define s second
#define endl "\n"
#define all(container) container.begin(), container.end()
#define onlyunique(v) v.erase(unique(all(v)), v.end());

#define TRACE
#ifdef AYUSH
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const multiset<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }

int const mod = 1e9 + 7;
int const inf = 1e18;

int power(int x, int y, int mod = 2e18) { int ans = 1; x %= mod; while (y) {if (y & 1)ans = (x * ans) % mod; x = (x * x) % mod; y >>= 1;} return ans;}
int modinv(int a, int m) {return power(a, m - 2, m);}

void solve() {
    int h1, m1, h2, m2, k;cin>>h1>>m1>>h2>>m2>>k;
    int s = h1*60 + m1, e = h2 * 60 + m2;
    if(e - k >= s){
        cout<<e-k - s<<endl;
    }
    else{
        cout<<0<<endl;
    }

}
signed main() {
    IOS
    int t = 1, T = 1;
    // cin>>t;
    while (t--) {
        // cout<<"Case #"<<T<<": ";
        solve();
        // ++T;
    }
    return 0;
}

Measured memory_bytes: 3652