akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

const (
	initialBufSize = 1024
	maxBufSize     = 1e6
)

var (
	scanner = bufio.NewScanner(os.Stdin)
)

// 解説見た
func main() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, initialBufSize), maxBufSize)
	l, r := scanInt(), scanInt()
	if r-l >= 2019 {
		fmt.Println(0)
		return
	}

	min := math.MaxInt64
	for i := l; i < r; i++ {
		for j := (i + 1); j <= r; j++ {
			m := (i * j) % 2019
			if m < min {
				min = m
			}
		}

		if min == 0 {
			break
		}
	}

	fmt.Println(min)
}

func scanInt() int {
	i, _ := strconv.Atoi(scanText())
	return i
}

func scanInts(size int) []int {
	ints := make([]int, size)
	for i := 0; i < size; i++ {
		ints[i] = scanInt()
	}
	return ints
}

func scanFloat64() float64 {
	f, _ := strconv.ParseFloat(scanText(), 64)
	return f
}

func scanFloat64s(size int) []float64 {
	f := make([]float64, size)
	for i := 0; i < size; i++ {
		f[i] = scanFloat64()
	}
	return f
}

func scanText() string {
	scanner.Scan()
	return scanner.Text()
}

func scanTexts(size int) []string {
	s := make([]string, size)
	for i := 0; i < size; i++ {
		s[i] = scanText()
	}
	return s
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

func pow(x, y int) int {
	return int(math.Pow(float64(x), float64(y)))
}

func min(n []int) (min, idx int) {
	min = math.MaxInt64
	for i := 0; i < len(n); i++ {
		if n[i] < min {
			min = n[i]
			idx = i
		}
	}
	return
}

func max(n []int) (max, idx int) {
	max = math.MinInt64
	for i := 0; i < len(n); i++ {
		if n[i] > max {
			max = n[i]
			idx = i
		}
	}
	return
}


Measured memory_bytes: 640
#include<cstdio>
long long n,ans;
inline void Judge(long long m,long long x){
	if(!m)return;
    if(n/m==x&&n%m==x)ans+=m;
}
int main(){
	scanf("%lld",&n);
	for(register long long i=1;i*i<=n;i++){
		Judge(i-1,n/i);
		if(i*i<n)Judge(n/i-1,i);
	}
	printf("%lld",ans);
}

Measured memory_bytes: 128
#![allow(non_snake_case, unused_imports)]

// Input
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, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        A: [i64; 3],
    }
    let mut maxv = 0;
    for i in 0..3{
        maxv = max(maxv, A[i]);
    }
    let mut diff = 0;
    for i in 0..3{
        diff += maxv-A[i];
    }
    println!("{}", if diff%2==0 {diff/2} else {diff/2+2});
}

Measured memory_bytes: 4352
// Aizu 1127: Building a Space Station
// 2017.9.19 bal4u@uu

#include <stdio.h>
#include <math.h>

#define EPS 1e-7
#define INF 1e7
typedef struct { double x, y, z, r; char f; } PP;
PP pp[105];

int main()
{
    int i, j, n, cnt, nx;
	double ans, min, d;
	PP  *p, *q;

    while (scanf("%d", &n) && n) {
		for (i = 0; i < n; i++) 
			scanf("%lf%lf%lf%lf", &pp[i].x, &pp[i].y, &pp[i].z, &pp[i].r), pp[i].f = 0;
        ans = 0, pp[0].f = 1, cnt = 1;
        while (cnt < n) {
            for (nx = -1, min = INF, p = pp, i = 0; i < n; i++, p++) {
                if (p->f == 0) continue;
                for (q = pp, j = 0; j < n; j++, q++) {
                    if (q->f) continue;
                    d = sqrt((p->x-q->x)*(p->x-q->x) + (p->y-q->y)*(p->y-q->y) +
						(p->z-q->z)*(p->z-q->z)) - (p->r+q->r);
					if (nx < 0 || d + EPS < min) min = d, nx = j;
                }
            }
            pp[nx].f = 1, cnt++; if (min > EPS) ans += min;
        }
        printf("%.3lf\n", ans);
    }
    return 0;
}

Measured memory_bytes: 1752
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vi  = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(int i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
const ll INF = 1000000000000000;
const ll MOD = 1000000007;
const double PI = acos(-1);
//||
#define DBG(a,b,c,d) //cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl
//DBG("","","","");

signed main(){
	IO_STREAM;
	int A,B;
	cin>>A>>B;
	cout<<(6-A-B)<<endl;
	return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
long long int max(long long int a, long long int b) {
  return a>b?a:b;
}
int main() {
  long long int a, b, c, d;
  cin>>a>>b>>c>>d;
  cout<<max(a*c, max(a*d, max(b*c, b*d)));
}

Measured memory_bytes: 3632
#include<iostream>
using namespace std;
int n,m;

int main()
{
	cin>>n>>m;
	for(int i=m/n+1;i>=1;i--)
	{
		if(m%i==0&&m/i>=n)
		{
			cout<<i; return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
static const ll INF=1000000000000000;
ll n;
ll N,Q,A,B;
ll dp[4][200005];
ll dat[4][800010];
void init(ll n_){
n=1;while(n<=n_)n*=2;
  for(int i=0;i<4;i++)
    for(int j=0;j<2*n-1;j++)
      dat[i][j]=INF;
}
void update(ll w,ll k,ll a){
k+=n-1;
  if(dat[w][k]<=a)
    return;
  dat[w][k]=a;
  while(0<k){
  k=(k-1)/2;
    dat[w][k]=min(dat[w][2*k+1],dat[w][2*k+2]);
  }
    
}
ll query(ll w,ll a,ll b,ll k,ll l,ll r){
if(a<=l && r<=b)
  return dat[w][k];
  else if(r<=a || b<=l)
    return INF;
  else{
  ll val=query(w,a,b,2*k+1,l,(l+r)/2);
    ll var=query(w,a,b,2*k+2,(l+r)/2,r);
    return min(val,var);
  }

}
int main(){
  cin>>N>>Q>>A>>B;init(200001);
  vector<ll>x(Q+2);x[0]=A;x[1]=B;
  for(int i=2;i<=Q+1;i++)
    cin>>x[i];
  vector<ll>sum(Q+1);
  for(int i=0;i<=Q;i++)
    sum[i]=abs(x[i]-x[i+1]);
  for(int i=1;i<=Q;i++)
    sum[i]=sum[i]+sum[i-1];
  dp[0][0]=INF;dp[1][0]=INF;dp[2][0]=0;dp[3][0]=INF;
  update(0,A,dp[2][0]-sum[0]+A);
  update(1,A,dp[2][0]-sum[0]-A);
  for(int i=1;i<=Q;i++){
  dp[0][i]=min(dp[0][i-1],dp[1][i-1])+abs(x[i+1]-x[i]);
    dp[3][i]=min(dp[2][i-1],dp[3][i-1])+abs(x[i+1]-x[i]);
dp[1][i]=min(query(0,x[i+1],200004,0,0,n)-x[i+1],query(1,0,x[i+1],0,0,n)+x[i+1])+sum[i-1];
dp[2][i]=min(query(2,x[i+1],200004,0,0,n)-x[i+1],query(3,0,x[i+1],0,0,n)+x[i+1])+sum[i-1]; 
 update(0,x[i],dp[2][i]-sum[i]+x[i]);
    update(1,x[i],dp[2][i]-sum[i]-x[i]);
    update(2,x[i],dp[1][i]-sum[i]+x[i]);
    update(3,x[i],dp[1][i]-sum[i]-x[i]);
  }ll ans=INF;
  for(int i=0;i<4;i++)
    if(dp[i][Q]<ans)ans=dp[i][Q];
  cout<<ans<<endl;
  
  return 0;
}

Measured memory_bytes: 29108
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1 << 18;
const int LG = 18;
const int INF = 1e9 + 7;
pair <int, int> merge(pair <int, int> a, pair <int, int> b) {
    vector <int> v = {a.first, a.second, b.first, b.second};
    sort(v.begin(), v.end());
    return {v[2], v[3]};
}   
int a[N];
pair <int, int> dp[N][LG + 1];
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    int n;
    cin >> n;
    for (int i = 0; i < (1 << n); ++i) cin >> a[i];
    for (int i = 0; i < (1 << n); ++i) {
        dp[i][LG] = {a[i], -INF};
        for (int p = LG - 1; p >= 0; --p) {
            if ((i >> p) & 1) {
                dp[i][p] = merge(dp[i][p + 1], dp[i - (1 << p)][p + 1]);
            }   
            else {
                dp[i][p] = dp[i][p + 1];
            }
        }   
    }   
    int ans = 0;
    for (int i = 1; i < (1 << n); ++i) {
        ans = max(ans, dp[i][0].first + dp[i][0].second);
        cout << ans << '\n';
    }   
}   

Measured memory_bytes: 82944
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		while (sc.hasNext()) {
			double a = sc.nextDouble();
			double b = sc.nextDouble();
			double c = sc.nextDouble();
			double d = sc.nextDouble();
			double e = sc.nextDouble();
			double f = sc.nextDouble();
			double x = 0;
			double y = 0;

			// x?????????????§£???
			x = (e * c - b * f) / (a * e - d * b);

			// x?????????????§£???
			y = (a * f - c * d) / (a * e - b * d);

			BigDecimal xbd = new BigDecimal(x);
			BigDecimal xbd2 = xbd.setScale(3, BigDecimal.ROUND_HALF_UP);
			BigDecimal ybd = new BigDecimal(y);
			BigDecimal ybd2 = ybd.setScale(3, BigDecimal.ROUND_HALF_UP);
			;

			if (x == -0) {
				x = 0;
			}
			if (y == -0) {
				y = 0;
			}
			System.out.printf("%.3f %.3f", xbd2, ybd2);
			System.out.println("");

		}

	}

}

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

#include "bits/stdc++.h"
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))

using namespace std;
using ll = long long;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);

int bpm(int x, int y) {
  if (x == 0)
    return 0;
  else if (y == 0) {
    return 1;
  }
  int ans = 1;
  x %= MOD;
  int digit = (int)((log((double)y) / log((double)2) / 1 + 1));
  for (int i = 0; i < digit; i++) {
    if (((y >> i) & 1u) == 1) {
      ans *= x;
      ans %= MOD;
    }
    x = x * x;
    x %= MOD;
  }
  return ans;
}

class COtoshidama {
public:
  int solve(std::istream &cin, std::ostream &cout) {
    int N, Y;
    cin >> N >> Y;
    rep(i, 20001) {
      rep(j, 2001 - i) {
        if (i + j + (Y - 10000 * i - 5000 * j) / 1000 == N &&
            (Y - 10000 * i - 5000 * j) / 1000 >= 0) {
          cout << i << " " << j << " " << (Y - 10000 * i - 5000 * j) / 1000
               << endl;
          return 0;
        }
      }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
  }
};

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


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

int main()
{
	int n, k, q;
	cin >> n >> k >> q;
	int a[2000];
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	int ans = mod;
	for(int i = 0; i < n; i++){
		// y = a[i]となるような時を考える
		priority_queue<int> qu;
		vector<int> v;
		for(int j = 0; j < n; j++){
			if(a[j] < a[i]){
				int m = qu.size();
				for(int l = 0; l < m - k + 1; l++){
					v.push_back(-qu.top());
					qu.pop();
				}
				while(!qu.empty()){
					qu.pop();
				}
			} else {
				qu.push(-a[j]);
			}
		}
		int m = qu.size();
		for(int l = 0; l < m - k + 1; l++){
			v.push_back(-qu.top());
			qu.pop();
		}
		sort(v.begin(), v.end());
		if(v.size() >= q) ans = min(ans, v[q - 1] - a[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
 
using namespace std;
 
int main()
{
  int N;
  vector<string> S;
  string s;

  cin >> N;

  for(int i = 0; i < N; i++){
    cin >> s;
    S.push_back(s);
  }

  sort(S.begin(), S.end());

  int ans = 1;

  for(int i = 0; i < N - 1; i++){
    if(S[i] != S[i+1]) ans++;
  }

  cout << ans << endl;

  return 0;
}

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

using namespace std;

class contair {
private:
	int value;
	contair *next, *before;
public:
	contair(int);
	int get_value();
	void set_value(int);
	contair* get_next();
	contair* get_before();
	void set_next(contair*);
	void set_before(contair*);
};

contair::contair(int a) {
	value = a;
}
int contair::get_value() {
	return value;
}
void contair::set_value(int a) {
	value = a;
}
contair* contair::get_next() {
	return next;
}
contair* contair::get_before() {
	return before;
}
void contair::set_before(contair* a) {
	before = a;
}
void contair::set_next(contair* a) {
	next = a;
}

class Mylist {
public:
	contair* front, * back;
	int size;
	Mylist();
	void insert(int);
	void del(int);
	void delfirst();
	void dellast();
	void disp();
};

Mylist::Mylist() {
	size = 0;
}
void Mylist::insert(int a) {
	if (size == 0) {
		front = back = new contair(a);
	}
	else {
		contair* work=new contair(a);
		front->set_before(work);
		work->set_next(front);
		front = work;
	}
	size++;
}
void Mylist::del(int a) {
	contair* p = front;
	while (1) {
		if (p->get_value() == a) {
			size--;
			if (size == 1) {
				free(p);
			}
			else if (p == front) {
				front = p->get_next();
				free(p);
			}
			else if (p == back) {
				back = p->get_before();
				free(p);
			}
			else {
				p->get_before()->set_next(p->get_next());
				p->get_next()->set_before(p->get_before());
				free(p);
			}
			break;
		}
		if (p == back)break;
		p = p->get_next();
	}
}
void Mylist::delfirst() {
	if (size == 1) {
		free(front);
	}
	else {
		front = front->get_next();
		free(front->get_before());
	}
	size--;
}
void Mylist::dellast() {
	if (size == 1) {
		free(back);
	}
	else {
		back = back->get_before();
		free(back->get_next());
	}
	size--;
}
void Mylist::disp() {
	contair* p=front;
	for (int i = 0;i < size;i++) {
		cout << p->get_value();
		if (p != back)cout << " ";
		p = p->get_next();
	}
	cout << endl;
}


int main() {
	int n;
	cin >> n;
	string com;
	Mylist ls;
	getline(cin, com);
	for (int i = 0;i < n;i++) {
		getline(cin, com);
		if (com == "deleteFirst") {
			ls.delfirst();
		}
		else if (com == "deleteLast") {
			ls.dellast();
		}
		else if (com.substr(0, 6) == "delete") {
			ls.del(atoi(com.substr(7).c_str()));
		}
		else {
			ls.insert(atoi(com.substr(7).c_str()));
		}
	}
	ls.disp();

}


Measured memory_bytes: 34404
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const double PI=3.1415926535;

int main(){
    int N;
    cin>>N;
    vll A(N);
    vll B(N+1);
    B[0]=0;
    for(int i=0;i<N;i++){
        cin>>A[i];
        B[0]+=(i%2)?(-A[i]):A[i];
    }
    B[N]=B[0];
    for(int i=1;i<N;i++){
        B[i]=A[i-1]*2-B[i-1];
    }
    for(int i=0;i<N;i++){
        cout<<B[i];
        if(i<N-1){
            cout<<" ";
        }else{
            cout<<endl;
        }
    }


}


Measured memory_bytes: 2944
#include <iostream>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>

using namespace std;

#define all(c) c.begin(),c.end()
#define repeat(i,n) for(int i=0;i<static_cast<int>(n);i++)
#define debug(x) #x << "=" << (x)
#define dump(x) cerr << debug(x) << " (L:" << __LINE__ << ")"<< endl

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<string> vs;

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec){
    os << "[";
    for(int i = 0; i < vec.size(); i++){
        os << vec[i] << ",";
    }
    os << "]";
    return os;
}

template<typename T>
T input(){
    T t;
    cin >> t;
    return t;
}

template<typename T>
vector<T> input(const int N){
    vector<T> v(N);
    repeat(i,N) cin >> v[i];
    return v;
}

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

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

long long mul(const long long& a, const long long& b, const long long& mod) {
    return ((a % mod) * (b % mod)) % mod;
}

long long power(const long long& x, const long long& y, const long long& mod) {
    if (y == 0) {
        return 1;
    } else if (y == 1) {
        return x % mod;
    } else {
        long long value = power(x, y / 2, mod);
        if (y % 2 == 0) {
            return mul(value, value, mod);
        } else {
            return mul(value, value, mod) * x % mod;
        }
    }
}

long long div(const long long& a, const long long& b, const long long& mod) {
    return mul(a, power(b, mod - 2, mod), mod);
}

map<long long, long long> factorials;
long long factorial(const long long& n, const long long& mod) {
    if (n == 0 || n == 1) {
        return 1;
    }
    if (factorials[n] != 0) {
        return factorials[n];
    }
    factorials[n] = n * factorial(n - 1, mod) % mod;
    return factorials[n] % mod;
}

long long combination(const long long& n, const long long& x, const long long& mod) {
    long long numerator = 1;
    long long denominator = 1;
    repeat(i, x) {
        numerator *= (n - i) % mod;
        numerator %= mod;
        denominator *= (i + 1) % mod;
        denominator %= mod;
    }
    return div(numerator, denominator, mod);
}

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if ((a * 100 + b * 10 + c) % 4 == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a+b<b+c&&a+b<a+c||a+b==b+c&&a+b==a+c){
		printf("%d\n",a+b);
	}
	else if(b+c<a+c&&b+c<a+b||a+b==b+c&&a+b==a+c){
		printf("%d\n",b+c);
	}
	else if(a+c<b+c&&a+c<a+b||a+b==b+c&&a+b==a+c){
		printf("%d\n",a+c);
	}
	return 0;
}

Measured memory_bytes: 128
//
// tested with : g++ (GCC) 8.3.0
//

#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    int N;
    cin >> N;
    int* A = new int [N];
    for (int i = 0; i < N; i++)
        cin >> A[i];

    sort(A,A+N);//昇順にソートされる。
    int result = A[N - 1] - A[0];

    cout << result << endl;

    return 0;
}


Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int arr[n];
	for (int i=0;i<n;i++)
		cin>>arr[i];
	int dp[n];
	dp[0]=arr[0];
	dp[1]=abs(arr[1]-arr[0]);
	int v,u;
	for (int i=2;i<n;i++)
	{
		v=abs(arr[i]-arr[i-1])+dp[i-1];
        if (i==2)
            u=abs(arr[i]-arr[i-2]);
        else
		u=abs(arr[i]-arr[i-2])+dp[i-2];
		dp[i]=min(v,u);
	}
	cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 1024
a,b,c,d = gets.chomp.split("").map(&:to_i)
op = [[1,-1],["+","-"]]
2.times do |i|
  2.times do |j|
    2.times do |k|
      if a+b*op[0][i]+c*op[0][j]+d*op[0][k] == 7
        print a,op[1][i],b,op[1][j],c,op[1][k],d,"=7\n"
        exit
      end
    end
  end
end

Measured memory_bytes: 1916
import math
import sys
from typing import List


def warshall_floyd(table: List[List[int]], vertex_num: int) -> None:
    for k in range(vertex_num):
        for i in range(vertex_num):
            for j in range(vertex_num):
                table[i][j] = min(table[i][j], table[i][k] + table[k][j])


if __name__ == "__main__":
    V, E = map(lambda x: int(x), input().split())
    adj = [[sys.maxsize] * V for i in range(V)]
    for i in range(V):
        adj[i][i] = 0

    odd_b = 0  # bit DP to record odd vertex
    ans = 0

    for _ in range(E):
        s, t, d = map(lambda x: int(x), input().split())
        min_d = min(d, adj[s][t])
        adj[s][t] = min_d
        adj[t][s] = min_d
        odd_b ^= 1 << s
        odd_b ^= 1 << t
        ans += d

    if odd_b:
        warshall_floyd(adj, V)

        # Minimum weighted matching
        mw = [sys.maxsize] * (odd_b + 1)
        mw[0] = 0
        digits = int(math.log2(odd_b)) + 1

        for b, mw_b in enumerate(mw):
            if 1 == b % 2:
                continue
            for i in range(0, digits):
                if b & (1 << i):
                    continue
                for j in range(i + 1, digits):
                    if b & (1 << j):
                        continue
                    t_b = b + (1 << i) + (1 << j)
                    if t_b == t_b & odd_b:
                        t_w = mw[t_b]
                        mw[t_b] = min(t_w, mw_b + adj[i][j])
        ans += mw[odd_b]
        print(ans)
    else:
        print(ans)



Measured memory_bytes: 7388
#include<bits/stdc++.h>
#define int long long
#define ll int64_t
using namespace std;
 
const int M = 1e9+7;
 
vector<int> minp(1000005);
void soe() {
	for(int i = 0; i < 1000005; i++) minp[i] = i;
	for(int i = 2; i*i <= 1000005; i++) {
		if(minp[i] == i) {
			for(int j = i*i; j < 1000005; j += i) if(minp[j] == j) minp[j] = i;
		}
	}
}
 
map<int,int> lcm;
void pfact(int n) {
	map<int,int> map;
	while(n != 1) {
		map[minp[n]]++;
		n /= minp[n];
	}
	for(auto p:map) {
		lcm[p.first] = max(lcm[p.first] , p.second);
	}
}
 
int _power(int x , int p) {
	int res = 1;
	while(p) {
		if(p & 1) res = (res * x)%M;
		p /= 2;
		x = (x * x)%M;
	}
	return res;
}
 
int calc() {
	int res = 1;
	for(auto p:lcm) {
		res = (res * _power(p.first , p.second))%M;
	}
	return res;
}
 
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
	soe();
	int n;
	cin >> n;
	int a[n] , LCM = 1;
	for(int i = 0; i < n; i++) cin >> a[i] , pfact(a[i]);
	LCM = calc();
	int ans = 0;
	for(int i = 0; i < n; i++) {
		int val = (LCM * _power(a[i] , M-2));
		ans = (ans + val)%M;
	}
	cout << ans << "\n";
		
    return 0;
}

Measured memory_bytes: 8832
#include<bits/stdc++.h>
#define lld long long
#define pb push_back
#define mk make_pair
#define MAX (lld)1e18+7
#define lim (lld)1e9+7
#define MAX2 (lld)2e5+9
#define ff first
#define ss second
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

const lld mod=lim;

lld power(lld x, lld y, lld p)  
{   lld res = 1;     x = x % p; if (x == 0) return 0;  
  
    while (y > 0)  
    { if (y & 1) res = (res*x) % p;  y = y>>1; x = (x*x) % p;   }  
    return res;  } 


lld extend_gcd(lld a, lld b, lld& x, lld& y) {
    if (b == 0) { x = 1;y = 0;return a;}
    lld x1, y1;
    lld d = extend_gcd(b, a % b, x1, y1);
    x = y1; y = x1 - y1 * (a / b);return d;	}

lld rowNum[]={-1,0,0,1};
lld colNum[]={0,-1,1,0};

int main()
{
	fastio
	string s;
	cin>>s;

	int n=s.size();

	if(s[n-1]=='s')
		s+="es";
	else
		s+="s";
	cout<<s<<endl;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#pragma warning (disable : 4996)
using namespace std;
int main()
{
	int n;
	scanf("%d", &n);
	vector<int> a;
	for (int i = 0, x; i < n; i++) scanf("%d", &x), a.push_back(x);
	sort(a.begin(), a.end());
	int ans = -1;
	for (int i = 0; i < n - 1; i++)
	{
		if (a[i] * 2 > a[n - 1])
		{
			if (ans < a[n - 1] - a[i]) ans = a[i];
		}
		else ans = max(ans, a[i]);
	}
	return !printf("%d %d", a[n - 1], ans);
}

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


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

typedef pair<int, int> P;



int main() {


    int n; cin >> n;
    vector<int> a(n);
    vector<int> sort_a(n);
    rep(i, n) {
        int tmp; cin >> tmp;
        a[i] = tmp;
        sort_a[i] = tmp;
    }

    sort(sort_a.begin(), sort_a.end(), greater<int>());
    rep(i,n) {
        if(a[i] == sort_a[0]) {
            cout << sort_a[1] << endl;
        } else {
            cout << sort_a[0] << endl;
        }
    }

    return 0;

}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
const ll INF = 1e18;
#define print(x) cout << (x) << endl;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    int ans = 0;
    for (int i = 0; i < S.size(); i++) {
        for (int j = i; j < S.size(); j++) {
            bool check = true;
            for (int k = i; k <= j; k++) {
                if ((S.at(k) != 'A') & (S.at(k) != 'T') & (S.at(k) != 'C') & (S.at(k) != 'G')) {
                    check = false;
                }
            }
            if (check) ans = max(ans, j-i+1);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,m,a[51],b[51];
bool graph[51][51],vis[51];
void dfs(int v){
	if(vis[v])return;
	vis[v]=1;
	for(int i=0;i<n;i++){
		if(graph[v][i])dfs(i);
	}
}
int main(){
	int i,j;
	cin>>n>>m;
	for(i=0;i<m;i++){
		cin>>a[i]>>b[i];
		a[i]--,b[i]--;
		graph[a[i]][b[i]]=graph[b[i]][a[i]]=1;
	}
	int ans=0;
	for(i=0;i<m;i++){
		graph[a[i]][b[i]]=graph[b[i]][a[i]]=0;
		for(j=0;j<n;j++)vis[j]=0;
		dfs(0);
		for(j=0;j<n;j++){
			if(!vis[j]){
				ans++;
				break;
			}
		}
		graph[a[i]][b[i]]=graph[b[i]][a[i]]=1;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import collections


def solve(N: int, S: "List[str]"):

    dic = collections.defaultdict(int)
    for s in S:
        s = "".join(sorted(s))
        dic[s] += 1

    res = 0
    for k,v in dic.items():
        if v > 1:
            res += v*(v-1)/2

    print(int(res))



# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = [ next(tokens) for _ in range(N) ]  # type: "List[str]"
    solve(N, s)

if __name__ == '__main__':
    main()


Measured memory_bytes: 25304
import java.util.*;
import java.io.*;

/**
 * Made by egor https://github.com/chermehdi/egor.
 * 
 * @author azize
   
 */
public class Main {

    void solve(Scanner in, PrintWriter out) {
        int k = in.nextInt();
        int sum = 0;
        for (int a = 1; a <= k; ++a) {
            for (int b = 1; b <= k; ++b) {
                for (int c = 1; c <= k; ++c) {
                    sum += gcd(a, b, c);
                }
            }
        }

        out.println(sum);
    }

    public int gcd(int a, int b, int c) {
        return gcd(a, gcd(b, c));
    }

    public int gcd(int a, int b) {
        if (b == 0) return a;
        return gcd(b, a % b);
    }

    public static void main(String[] args) {
        try(Scanner in = new Scanner(System.in);
            PrintWriter out = new PrintWriter(System.out)) {
            new Main().solve(in, out);
        }
    }
}


Measured memory_bytes: 35920
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = int_fast64_t;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  ll a, b;
  cin >> a >> b;
  a--; b--;
  vector<bool> ans(3, true);
  ans[a] = false; ans[b] = false;
  rep(i, 3) if(ans[i]) cout << i+1 << "\n";
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int x = Integer.parseInt(scanner.nextLine());
        int lastPow = 1;
        for (int i = 2; i <= x; i++) {
            int pow = i;
            while (pow * i <= x) {
                pow *= i;
            }
            if (i < pow && pow <= x && lastPow < pow) {
                lastPow = pow;
            }
        }
        System.out.println(lastPow);
    }
}


Measured memory_bytes: 21844
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass
{
    static void Main()
    {
        var HWK = ReadLine().Split().Select(int.Parse).ToArray();
        int H = HWK[0], W = HWK[1], K = HWK[2];
        var map = new bool[H, W];
        for (int i = 0; i < H; i++)
        {
            var line = ReadLine();
            for (int j = 0; j < W; j++)
            {
                map[i, j] = line[j] == '#';
            }
        }

        var ans = new int[H, W];
        for (int i = 0; i < H; i++)
        {
            for (int j = 0; j < W; j++)
            {
                ans[i, j] = -1;
            }
        }
        int num = 1;
        for (int i = 0; i < H; i++)
        {
            for (int j = 0; j < W; j++)
            {
                if (map[i, j])
                {
                    int yu = i, yd = i;
                    int xr = j, xl = j;
                    while (true)
                    {
                        if (yu - 1 >= 0 && !map[yu - 1, j]&&ans[yu-1,j]==-1) yu--;
                        else break;
                    }
                    while (true)
                    {
                        bool frag = true;
                        for (int y = yu; y <= yd; y++)
                        {
                            if (xr - 1 >= 0 && !map[y, xr - 1]&& ans[y,xr-1]==-1) continue;
                            else frag = false;
                        }
                        if (frag) xr--;
                        else break;
                    }
                    while (true)
                    {
                        bool frag = true;
                        for (int y = yu; y <= yd; y++)
                        {
                            if (xl + 1 < W && !map[y, xl + 1]&&ans[y,xl+1]==-1) continue;
                            else frag = false;
                        }
                        if (frag) xl++;
                        else break;
                    }
                    while (true)
                    {
                        bool frag = true;
                        for (int x = xr; x <= xl; x++)
                        {
                            if (yd + 1 < H && !map[yd + 1, x]&& ans[yd+1, x] == -1) continue;
                            else frag = false;
                        }
                        if (frag) yd++;
                        else break;
                    }

                    for (int y = yu; y <=yd; y++)
                    {
                        for (int x = xr; x <=xl; x++)
                        {
                            ans[y, x] = num;
                        }
                    }
                    num++;
                }
            }
        }

        for (int i = 0; i < H; i++)
        {
            var line = new int[W];
            for (int j = 0; j < W; j++)
            {
                line[j] = ans[i, j];
            }
            WriteLine(string.Join(" ",line));
        }
    }
}


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

const int MOD = (int)1e9+7;

int main(){
	int N;
	cin >> N;
	vector<int> p(N);
	for(int i=0;i<N;i++)	cin >> p.at(i);

	int ans=0;
	for(int i=0;i<N;i++){
		if(p.at(i)==i+1)	ans++;
	}
	for(int i=0;i<N-1;i++){
		if(p.at(i)==i+1 && p.at(i+1)==i+2){
			ans--;
			i++;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 640
a,b=map(int, input().split())
if a>b+1:
    print(2*a-1)
elif a==b+1:
    print(a+b)
elif b==a+1:
    print(a+b)
elif b>a+1:
    print(2*b-1)
elif a==b:
    print(a+b)

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


int main() {
    int N, K;
    cin >> N >> K;
    vector<double> p(N);
    for(int i=0;i<N;i++) cin >> p.at(i);
    vector<double> kitai(N-K+1,0.0);

    for(int i=0;i<K;i++){
        kitai.at(0) += (p.at(i)+1)/2;
    }

    for(int i=1;i<kitai.size();i++){
        kitai.at(i) = kitai.at(i-1) + (p.at(i+K-1)+1)/2 - (p.at(i-1)+1)/2;
    }

    double ans=0.0;
    for(auto i:kitai){
        if(i>ans) ans=i;
    }

    cout << fixed << setprecision(10);
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    map<int, int> mp;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        mp[a[i]]++;
    }
    sort(a.begin(), a.end());
    if (mp[0] == n)
    {
        cout << "Yes" << endl;
        return 0;
    }
    if (n % 3 != 0)
    {
        cout << "No" << endl;
        return 0;
    }
    if (mp[0] == n / 3 && mp[a[n - 1]] == n * 2 / 3)
    {
        cout << "Yes" << endl;
        return 0;
    }
    int cnt = 0;
    int x = -10;
    for (auto &p : mp)
    {
        if (p.second == n / 3)
        {
            if (cnt == 0)
            {
                x = p.first;
            }
            else
            {
                x ^= p.first;
            }
            cnt++;
        }
    }
    if (x == 0 && cnt == 3)
    {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
}


Measured memory_bytes: 4224
#nowarn "25"

open System

let INF = int64 1e18

let [|n; m|] = stdin.ReadLine().Split() |> Array.map(int)

let mutable graph = Array.create (int n + 1) []
for i in 1 .. m do
    let [|a; b|] = stdin.ReadLine().Split() |> Array.map(int)
    graph.[a] <- b :: graph.[a]
    graph.[b] <- a :: graph.[b]

let d = Array.create (n + 1) INF
let prev = Array.create (n + 1) (-1)

d.[1] <- 0L

let mutable q = Set<int64 * int> [ (0L, 1) ]

let rec loop () =
    if not q.IsEmpty then
        let (c, v) = q.MinimumElement
        q <- q.Remove (c, v)

        for t in graph.[v] do
            let c2 = d.[v] + 1L
            if d.[t] > c2 then
                d.[t] <- c2
                prev.[t] <- v
                q <- q.Add (d.[t], t)
        
        loop ()
loop ()

printfn "Yes"
for i in 2 .. n do
    printfn "%d" prev.[i]

Measured memory_bytes: 69408
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    static class Task {

        private char[] arr;
        private int len;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            arr = in.next().toCharArray();
            this.len = arr.length;

            int maxPCount = len / 2;
            long ans = 0;
            for (int i = 0; i < len; i++) {
                if (i < maxPCount) {
                    if (arr[i] == 'g') {
                        ans++;
                    }
                } else {
                    if (arr[i] == 'p') {
                        ans--;
                    }
                }
            }

            out.println(ans);
        }
    }

    private static void sort(double[] arr) {
        Double[] objArr = Arrays.stream(arr).boxed().toArray(Double[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void sort(int[] arr) {
        Integer[] objArr = Arrays.stream(arr).boxed().toArray(Integer[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void sort(long[] arr) {
        Long[] objArr = Arrays.stream(arr).boxed().toArray(Long[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void solve() {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task task = new Task();
        task.solve(1, in, out);
        out.close();
    }

    public static void main(String[] args) {
        new Thread(null, () -> solve(), "1", 1 << 26).start();
    }

    static class InputReader {

        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

    }

}

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


using namespace std;

class maxFlow_with_demond{ ///dinic_maxflow with lower bounds and capacity
public:
#define MN 1000010
#define LL long long

  int head[MN], nxt[MN], to[MN], nodes;
  int demond[MN], q[MN], src, dst, dist[MN], nowi[MN];
  const LL LL_INF = 1e18;

public:
  int cap[MN], cnt;

  void init(){
    cnt = 2;
    memset(head, 0, sizeof head);
  }

  void insert_Edge(int _from, int _to, int _cap){
    to[cnt] = _to, cap[cnt] = _cap, nxt[cnt] = head[_from], head[_from] = cnt ++;
    to[cnt] = _from, cap[cnt] = 0, nxt[cnt] = head[_to], head[_to] = cnt ++;
  }

  void add_Edge(int _from, int _to, int _low, int _cap){
    insert_Edge(_from, _to, _cap - _low);
    demond[_from] -= _low;
    demond[_to] += _low;
  }

  bool dinic_bfs(){
    fill(dist, dist + nodes, -1);
    int qt = 0;
    dist[src] = 0, q[qt ++] = src;
    for(int qh = 0; qh < qt; qh ++){ int u = q[qh];
      for(int id = head[u]; id; id = nxt[id]) if(cap[id]) { int v = to[id];
	  if(dist[v] == -1){ dist[v] = dist[u] + 1, q[qt ++] = v; }
	}
    } return dist[dst] >= 0;
  }

  LL dinic_dfs(int u, LL f){
    if(u == dst) return f;
    LL ret = 0;
    for(int &id = nowi[u]; id; id = nxt[id]) if(cap[id]) { int v = to[id];
	if(dist[v] == dist[u] + 1){
	  LL tmp = dinic_dfs(v, min(f, (LL)cap[id]));
	  f -= tmp, ret += tmp, cap[id] -= tmp, cap[id^1] += tmp;
	  if(!f) return ret;
	}
      } return ret;
  }

  LL dinic_MaxFlow(int _src, int _dst){
    LL flow = 0;
    src = _src, dst = _dst;
    while(dinic_bfs()){
      for(int i = 0; i <= nodes; i ++) nowi[i] = head[i];
      flow += dinic_dfs(src, LL_INF);
    } return flow;
  }

  LL MaxFlow(int S, int T, int _nodes){
    nodes = _nodes + 1;
    int SS = nodes ++, TT = nodes ++;
    LL TOT = 0;
    for(int i = 1; i < nodes; i ++) {
      if(demond[i] > 0) TOT += demond[i], insert_Edge(SS, i, demond[i]);
      else if(demond[i] < 0) insert_Edge(i, TT, -demond[i]);
    }

    insert_Edge(T, S, 1e9);
    if(TOT != dinic_MaxFlow(SS, TT)) return -1;
    return dinic_MaxFlow(S, T);
  }
} Graph;


int main()
{
  int n,m;
  
  cin>>n>>m;
  Graph.init();
  Graph.nodes=n;
  for(int i=1;i<=m;i++)
    {
      int k1,k2,val;
      cin>>k1>>k2>>val;
      Graph.insert_Edge(k1,k2,val);
    }
  cout<<Graph.dinic_MaxFlow(0,n-1)<<endl;
  return 0;
}

Measured memory_bytes: 7032
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();
		Integer a[] = new Integer[M];
		long ans[] = new long[N + 1];
		Arrays.fill(ans, 0);
		for(int i = 0; i < M; i++) {
			a[i] = sc.nextInt();
			ans[a[i]] = -1;
		}
		ans[0] = (long)1;
		if(ans[1] != -1) {
			ans[1] = (long)1;
		} else {
			ans[1] = (long)0;
		}
		
		long p = 1000000007;
		for(int i = 2; i <= N; i++) {
			if(ans[i] != -1) {
				if(ans[i - 1] != -1) {
					ans[i] = ans[i - 1] % p;
				}
				if(ans[i - 2] != -1) {
					ans[i] = (ans[i] + ans[i - 2]) % p;
				}
			} else {
				ans[i] = (long)0;
			}
		}
		System.out.println(ans[N]);
	}
}


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

using namespace std;
typedef long long ll;

const int MOD=1e9+7;

ll n,k,vis[5005];
ll p[5005],c[5005],sum[5005],ans=-1e18;

int main()
{
    cin >> n >> k;
    for(int i=1; i<=n; i++) cin >> p[i];
    for(int i=1; i<=n; i++) cin >> c[i];
    for(int i=1; i<=n; i++)
	{
        ll s=c[i];
        vector<ll> t; 
		t.push_back(s);
        for(int j=p[i]; j!=i; j=p[j]) s+=c[j],t.push_back(s);
        int len=t.size();
        for(int j=0;j<len;j++)
		{
            ll rest=k-j-1;
            if(rest<0) break;
            ans=max(ans,t[j]+(rest/len)*max(s,0LL));
        }
    }
    cout << ans;
}

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

int main()
{
    ll X, A, B;
    cin >> X >> A >> B;
    if(A >= B) cout << "delicious" << endl;
    else if(X + A >= B) cout << "safe" << endl;
    else cout << "dangerous" << endl;
    return 0;
}

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

int main(){
  int N,Y,i,k;
  int itiooo,goooo,itioooo;
  cin >> N >> Y;
  int Yesno = 0;
  
  for(i=0; i<=N; i++){
    for(k=0; k<=N-i; k++){
      if(Y == (i*10000 + k*5000 + (N-i-k)*1000)){
        Yesno = 1;
        itioooo = i;
        goooo = k;
        itiooo = N-i-k;
        break;
      }
    }
  }
   if(Yesno == 0){
     cout << "-1 -1 -1" << endl;
   }else{
     cout << itioooo << " " << goooo << " " << itiooo << endl;
   }
}

Measured memory_bytes: 256
n,d=[int(i) for i in input().split()]
x=[[int(i) for i in input().split()] for _ in range(n)]
ans=0
for i in range(n):
    for j in range(n):
        if i>j:
            dis=0
            for h in range(d):
                dis+=(x[j][h]-x[i][h])**2
            if (dis**0.5).is_integer():
                ans+=1
print(ans)

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

typedef long long ll;
#define SZ(a) int((a).size())
#define _REP(_1,_2,_3,_4,name,...) name
#define _REP4(i,b,e,s) for(decltype(e) _b=(b),_e=(e),i=_b+(0<(s)?0:(s));(0<(s)?i<_e:_e<=i);i+=(s))
#define _REP3(i,b,e) for(decltype(e) _b=(b),_e=(e),i=(_b<_e?_b:_b-1);(_b<_e?i<_e:_e<=i);(_b<_e?i++:i--))
#define _REP2(i,n) for(decltype(n) i=0,_n=(n);i<_n;i++)
#define _REP1(n) for(decltype(n) _i=0,_n=(n);_i<_n;_i++)
#define REP(...) _REP(__VA_ARGS__,_REP4,_REP3,_REP2,_REP1)(__VA_ARGS__)
#define PB push_back
#define LL(n) ll n;assert(0<scanf("%lld", &n))

static const int MAXP = 1000000;
vector<int> ps, fs;
void init(){
  fs.reserve(1 + MAXP);
  for(int i = 0; i <= MAXP; i++){fs.push_back(i);}
  for(int i = 2; i <= MAXP; i++){
    if (fs[i] == i){
      ps.push_back(i);
      for (int j = i; j <= MAXP; j += i){
        fs[j] = min(fs[j], i);
      }
    }
  }
}
bool isprime(const long long& n){
  if (n <= MAXP){
    return (1 < n && fs[n] == n);
  } else {
    for(int p: ps){
      if (n % p == 0){return false;}
    }
    return true;
  }
}
vector<pair<long long, int>> factor(long long n){
  vector<pair<long long, int>> v;
  long long i = n;
  if (MAXP < i){
    for(int p: ps){
      int r = 0;
      while (i % p == 0){r++; i /= p;}
      if (0 < r){v.push_back(make_pair(p, r));}
      if (i <= MAXP){break;}
    }
    if (MAXP < i){
      v.push_back(make_pair(i, 1));
      i = 1;
    }
  }
  while(1 < i){
    if (v.empty() || (*v.rbegin()).first != fs[i]){
      v.push_back(make_pair(fs[i], 1));
    } else {
      (*v.rbegin()).second++;
    }
    i /= fs[i];
  }
  return v;
}

int main(){
  init();
  LL(n);
  auto f = factor(n);
  vector<int> v;
  int cnt = 0;
  REP(i, 1, 41){
    cnt += i; v.PB(cnt);
  }
  int ans = 0;
  for(auto p: factor(n)){
    ans += upper_bound(v.begin(), v.end(), p.second) - v.begin();
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 7640
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  int N, i, tmp, sum;
  vector<int> L;
  
  cin >> N;
  for(i=0;i<2*N;i++){
    cin >> tmp;
    L.push_back(tmp);
  }

  sort(L.begin(), L.end());

  sum = 0;
  for(i=0;i<2*N;i+=2){
     sum += L[i];
  }
  cout << sum << endl;
  
  return 0;
}


Measured memory_bytes: 256
///                ..:: In The Name Of God ::..
#include<bits/stdc++.h>

#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define error(x) cerr << #x << " = " << (x) << endl;
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define Size(x) (int)(x).size()
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef double ld;
int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    int a, b;
    cin >> a >> b;
    cout << max({a + a - 1, b + b - 1, a+b}) << endl;
return 0;    
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <stack>
#include <cstring>
using namespace std;

typedef long long ll;

int main() {
  int n;
  while (true) {
    cin >> n;
    if (n == 0) break;
    int tx[n], ty[n], bx[n], by[n];
    set <int> xy;
    for (int i = 0; i < n; i++) {
      cin >> tx[i] >> ty[i] >> bx[i] >> by[i];
      xy.insert(tx[i]);
      xy.insert(ty[i]);
      xy.insert(bx[i]);
      xy.insert(by[i]);
    }

    map <int, int> index;
    int cnt = 1;
    for (set <int>::iterator it = xy.begin(); it != xy.end(); it++, cnt++) {
      index[*it] = cnt;
    }
    ll field[cnt][cnt];
    memset(field, 0, sizeof(field));
    ll p = 1;
    for (int i = 0; i < n; i++) {
      for (int y = index[by[i]]; y < index[ty[i]]; y++) {
	for (int x = index[tx[i]]; x < index[bx[i]]; x++) {
	  field[x][y] |= p;
	}
      }
      p <<= 1;
    }

    int ans = 0;
    for (int i = 0; i < cnt; i++) {
      for (int j = 0; j < cnt; j++) {
	if (field[j][i] != -1) {
	  ans++;
	  ll ch = field[j][i];
	  int dx[] = {1, -1, 0, 0};
	  int dy[] = {0, 0, -1, 1};
	  stack <pair<int, int> > st;
	  st.push({j, i});
	  while (!st.empty()) {
	    pair<int, int> pos = st.top(); st.pop();
	    field[pos.first][pos.second] = -1;

	    for (int k = 0; k < 4; k++) {
	      pair<int, int> np = {pos.first+dx[k], pos.second+dy[k]};

	      if (np.first >= 0 && np.second >= 0 && np.first < cnt && np.second < cnt) {
		if (ch == field[np.first][np.second]) {
		  st.push(np);
		}
	      }
	    }
	  }
	}
      }
    }

    cout << ans << endl;
  }
}

Measured memory_bytes: 1632