akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

// // char s[125252];
// string s;
// unordered_map<string,bool> memo;
// bool dfs(string &s){
//   if(memo.count(s))return memo[s];
//   int n = s.size();
//   bool ret = false;
//   FOR(i,1,n-1){
//     if(s[i-1]!=s[i+1]){
//       string t = 
//     }
//   }
// }

int main(){
  string s;
  cin>>s;
  int n = s.size();
  if(s[0]==s[n-1]){
    puts(n%2==1?"Second":"First");
  }else{
    puts(n%2==0?"Second":"First");
  }
  return 0;
}


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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    REP(i, n-2){
        if(s.substr(i, 3) == "ABC") ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
function Main(input) {
    input = input.split("\n");
    for (i=0; i < input.length; i++) {
        tmp = input[i].split("")
        if (input[i] === '0') {
            break
        }
        var sum = 0
        for (j=0; j < tmp.length; j++) {
            var x = parseInt(tmp[j])
            sum += x
        }
        console.log(sum)
    }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));



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

struct T {
    int id, score;
    const int opCmp(const ref T o) const {
        if (score == o.score) return o.id - id;
        else return score - o.score;
    }
}

class SegTree {
    int size;
    int size2;
    T[] v;
    this(int size) {
        this.size = size;
        size2 = 1;
        while (size2 < size) {
            size2 *= 2;
        }
        v = new T[size2 * 2 + 1];
        foreach (i; 1 .. size2) {
            v[i].id = int.max;
        }
        foreach (int i; 0 .. size) {
            int j = i + size2;
            v[j].id = i;
        }
    }
    final void add(int i, int x) {
        int j = i + size2;
        v[j].score += x;
        j /= 2;
        while (j >= 1) {
            v[j] = max(v[j * 2], v[j * 2 + 1]);
            j /= 2;
        }
    }
    final T maxElement() {
        return v[1];
    }
}

void main() {
    int N, R, L; scanf("%d %d %d\n", &N, &R, &L);
    SegTree segtree = new SegTree(N);
    int u = 0;
    int m = 0;
    int[] tot = new int[N];
    foreach (_; 0 .. R) {
        int d, t, x; scanf("%d %d %d\n", &d, &t, &x);
        d--;
        tot[m] += t - u;
        segtree.add(d, x);
        m = segtree.maxElement.id;
        //writeln([t, m + 1]);
        u = t;
    }
    tot[m] += L - u;
    int ans = 1;
    int ansT = 0;
    foreach (int i, t; tot) {
        if (t > ansT) {
            ansT = t;
            ans = i + 1;
        }
    }
    ans.writeln;
}

Measured memory_bytes: 3804
use std::io::*;
use std::str::FromStr;

//https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n :usize= read();

    let ans = match n%10 {
        2 => "hon",
        4 => "hon",
        5 => "hon",
        7 => "hon",
        9 => "hon",
        0 => "pon",
        1 => "pon",
        6 => "pon",
        8 => "pon",
        3 => "bon",
        _ => "",
    };

    println!("{}",ans);
}

Measured memory_bytes: 2160
//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <vector>

using i8 = ::std::int_least8_t;
using i32 = ::std::int_least32_t;
using i64 = ::std::int_least64_t;
using u8 = ::std::uint_least8_t;
using u32 = ::std::uint_least32_t;
using u64 = ::std::uint_least64_t;
using isize = ::std::ptrdiff_t;
using usize = ::std::size_t;

template <class T = usize> class rep {
	const T f, l;

public:
	class itr {
		friend rep;
		T i;
		constexpr itr(T x) noexcept : i(x) {}

	public:
		void operator++() noexcept { ++i; }
		constexpr T operator*() const noexcept { return i; }
		constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	constexpr rep(const T first, const T last) noexcept : f(first), l(last) {}
	constexpr itr begin() const noexcept { return itr(f); }
	constexpr itr end() const noexcept { return itr(l); }
};
template <class T = usize> class revrep {
	const T f, l;

public:
	class itr {
		friend revrep;
		T i;
		constexpr itr(T x) noexcept : i(x) {}

	public:
		void operator++() noexcept { --i; }
		constexpr T operator*() const noexcept { return i; }
		constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	constexpr revrep(const T first, const T last) noexcept : f(first), l(last) {}
	constexpr itr begin() const noexcept { return itr(l - 1); }
	constexpr itr end() const noexcept { return itr(f - 1); }
};
template <class T> bool amax(T &a, const T &b) {
	return a <= b ? (a = b, 1) : 0;
}
template <class T> bool amin(T &a, const T &b) {
	return b <= a ? (a = b, 1) : 0;
}
template <class T> bool samax(T &a, const T &b) {
	return b <= a ? 0 : (a = b, 1);
}
template <class T> bool samin(T &a, const T &b) {
	return a <= b ? 0 : (a = b, 1);
}
template <class T> using vec_alias = ::std::vector<T>;
template <class T> auto md_vec(usize n, const T &value) {
	return ::std::vector<T>(n, value);
}
template <class... Args> auto md_vec(usize n, Args... args) {
	return ::std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> const T &as_const(const T &v) noexcept { return v; }
template <class T> constexpr T difference(const T &a, const T &b) {
	return a <= b ? b - a : a - b;
}

#include <algorithm>
#include <iostream>
#include <utility>
#include <tuple>

int main() {
	u32 h, w;
	::std::cin >> h >> w;
	usize n;
	::std::cin >> n;
	::std::vector<::std::pair<u32, u32>> p(n);
	for (auto &e : p) {
		::std::cin >> e.first >> e.second;
	}
	::std::sort(p.begin(), p.end());
	u32 cnt{ 0 };
	for (const auto &e : p) {
		u32 x, y;
		::std::tie(x, y) = e;
		if (x < y + cnt)
			continue;
		if (x == y + cnt) {
			++cnt;
			continue;
		}
		::std::cout << x - 1 << ::std::endl;
		return 0;
	}
	::std::cout << h << ::std::endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
using ld=long double;
using VI=vector<ll>;
using VD=vector<ld>;
using VVI=vector<VI>;
using VC=vector<char>;
using VVC=vector<VC>;
using VS=vector<string>;
using PLL =pair<ll,ll>;
using PLD=pair<ld,ld>;
using VPLL=vector<PLL>;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element((x).begin(),(x).end())
#define MIN(x) *min_element((x).begin(),(x).end())
#define SORTR(x) sort((x).rbegin(),(x).rend())
#define SORT(x) sort((x).begin(),(x).end())
#define SUM(x) accumulate((x).begin(),(x).end(), 0)
#define FILL(x,a) fill(x.begin(),x.end(),a)
#define EACH(i,x) for(typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)

const int INF  = 1<<30;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;
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; }
template <class BidirectionalIterator>
bool next_partial_permutation(BidirectionalIterator first, BidirectionalIterator middle,BidirectionalIterator last){reverse(middle, last); return next_permutation(first , last);}
#define COUT(x) cout<<x<<"\n"

void Main()
{
	ll N;
	ll result=0;
	string S;
	cin>>N;
	ll maxi=sqrt(N);
	REP(i,9){
		REP(j,maxi+1){
			ll tmp=pow(j,i);
			if(tmp<=N){
				result=max(result,tmp);
			}
		}
	}
	cout << result << "\n";
	return;
}

int main()
{
	std::cin.tie(0);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}


Measured memory_bytes: 256
fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    let a:u32 = sc.read();
    let b:u32 = sc.read();
    let c:u32 = sc.read();
    if a < b  && b < c {
        println!("Yes");
    }else {
        println!("No");
    }
}

use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
 
struct Scanner<'a> {
    cin: StdinLock<'a>,
}
 
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }
 
    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }
 
    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}


Measured memory_bytes: 5012
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <climits>
#include <cmath>
#include <cstring>
#include <cassert>
#include <chrono>
#include <random>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
using namespace std;

#define pb push_back
#define fst first
#define snd second

#ifdef QLEG_DEBUG
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { os << '{'; string sep; for (const auto& x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream& os, const pair<A, B>& p) { return os << '(' << p.first << ", " << p.second << ')'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll, ll>;
template<typename T> using min_queue=priority_queue<T,vector<T>,greater<T>>;

int main(){
  ios::sync_with_stdio(0);cin.tie(0);

  int N, d[111][2];
  cin>>N;
  for (int i=0;i < N;i++) {
    cin>>d[i][0]>>d[i][1];
  }
  for (int i=0;i+2<N;i++) {
    if (d[i][0] == d[i][1] && 
        d[i+1][0] == d[i+1][1] && 
        d[i+2][0] == d[i+2][1]) {
      cout << "Yes\n";
      return 0;
    }
  }
  cout << "No\n";
}


Measured memory_bytes: 3632
// Template {{{
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;

#ifdef LOCAL
#include "contest.h"
#else
#define error(args...) 
#endif

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(12);
}
//}}}

LL calc(int s, const vector<LL>& A, const vector<vector<LL>>& BS) {
    const int N = BS.size();
    const int M = BS[0].size();

    LL sum = 0;
    REP(i, M) sum += BS[s][i];
    LL ans = sum;

    LL cost = 0;
    vector<LL> B(M);
    REP(i, M) B[i] = BS[s][i];

    for(int i = s+1; i < N; i++) {
        cost += A[i-1];

        REP(j, M) {
            LL x = BS[i][j];
            if(B[j] < x) {
                sum += x - B[j];
                B[j] = x;
            }
        }

        ans = max(ans, sum - cost);
    }

    return ans;
}
int main(){
    iostream_init();
    int N, M;
    cin >> N >> M;

    vector<LL> A(N-1);
    REP(i, N-1) cin >> A[i];

    vector<vector<LL>> BS(N, vector<LL>(M));

    REP(i, N) REP(j, M) cin >> BS[i][j];

    LL ans = LLONG_MIN;

    vector<int> eval(N, INT_MAX);

    REP(j, M) {
        vector<pair<int, int>> ps;
        REP(i, N) {
            ps.push_back(make_pair(-BS[i][j], i));
        }
        sort(ps.begin(), ps.end());
        REP(i, N) {
            eval[ps[i].second] = min(eval[ps[i].second], i);
        }
    }

    vector<pair<LL, int>> ps;
    REP(i, N) {
        ps.push_back(make_pair(eval[i], i));
    }
    sort(ps.begin(), ps.end());

    clock_t start = clock();
    int index = -1;
    REP(i, ps.size()) {
        clock_t end = clock();
        if((end - start) > 1.8 * CLOCKS_PER_SEC) {
            break;
        }
        
        auto c = calc(ps[i].second, A, BS);
        if(ans < c) {
            ans = c;
            index = ps[i].second;
        }
    }
    for(int i = index - 10; i <= index + 10; i++) {
        if(i >= 0 && i < N) {
            ans = max(ans, calc(i, A, BS));
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 8576
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
LIN=lambda : list(IN())
mod=1000000007

#+++++

def main():
	#n = int(input())
	n, k = IN()
	#s = input()
	al = LIN()
	cl=[mod]*n
	cl[0]=0
	for i, c in enumerate(al):
		#pa(cl)
		for j, nv in enumerate(al[i:i+k+1]):
			cl[i+j]=min(cl[i+j], cl[i]+abs(nv-c))
	
	print(cl[-1])
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 52832
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
using namespace std;

//素数判定
inline bool IsPrime(int p) {
	if (p == 1) return false;
	for (int i = 2; i <= sqrt(p); i++) {
		if (p%i == 0) return false;
	}
	return true;
}

//10進数の自然数の桁数を返す
inline int GetDigit(int num) {
	return (int)log10(num) + 1;
}

//各位の和を返す
int GetDigitsSum(int num) {
	int N = 0;
	while (num > 0) {
		N += num % 10;
		num /= 10;
	}
	return N;
}

int main() {
	string s;
	vector<int> v;
	vector<int> a;
	vector<int> b;

	cin >> s;
	for (int i = 0; i < (int)s.length(); i++)
	{
		v.push_back(s[i] - '0');
	}

	int N = (int)s.length();
	int x = 3;

	for (int i = 0; i <= N-x; i++)
	{
		a.push_back(v[i] * 100 + v[i + 1] * 10 + v[i + 2]);
		//cout << "i" << i << endl;
	}


	for (int i = 0; i < (int)a.size(); i++)
	{
		b.push_back(abs(753 - a[i]));
	}
	
	cout << *min_element(b.begin(), b.end()) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define N 100
#define INF 99999999

int min(int,int); 

int main(){

  int i,n,A[N+1],j,k,l,q,p;
  int r[N+1],c[N+1],m[N+1][N+1];
  scanf("%d",&n);

  for(i = 0; i<n ; i++){
    scanf("%d",&r[i]);
    scanf("%d",&c[i]);
  }

  for(i = 0; i<n ; i++){
    A[i] = r[i]; 
  }
  A[n] = c[n-1];

   for(i = 1;i<=n;i++){
    m[i][i] = 0;
   }
  
  for( l = 2; l<= n;l++){
    for (i = 1;i<= n-l+1;i++){
      j = i+l-1;
      m[i][j] = INF;
      for (k = i;k<=j-1;k++){
	  q = m[i][k] + m[k+1][j] + A[i-1]*A[k]*A[j];	 
          m[i][j] = min(m[i][j], q); 
    }
  }
}
  printf("%d\n",m[1][n]);
   return 0;
}

int min(int m,int q){
  if(m >= q)
    return q;
  if(m < q)
    return m;
}



Measured memory_bytes: 2048
N, M=(int(i) for i in input().split())
P=[]
for i in range(M):
    P.append([int(i) for i in input().split()])


ans=0
q=[]
s=1

def func(s,Q,r):
    global ans
    for q ,P in Q:
        if r==N-1:
            ans+=1
        n_s=[i for i in q if i!=s][0]
        n_q=[]
        for p in P:
            if n_s in p:
                n_q.append([p, [_p for _p in P if n_s not in _p]])
        if len(n_q)==0:
            continue
        else:
            func(n_s, n_q, r+1)


for p in P:
    if s in p:
        q.append([p, [_p for _p in P if s not in _p]])
func(s,q,1)
print(ans)

Measured memory_bytes: 48732
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

n,a,b,c=parseMap(split(readline()))
l=[parseInt(readline()) for i in 1:n]
ans=10^9

function dfs(cnt,one,two,three,mp)
    global ans
    if cnt==n+1
        if 0 in [one,two,three]
            return 0
        end
        ans=min(ans,mp+abs(one-a)+abs(two-b)+abs(three-c)-30)
    else
        dfs(cnt+1,one+l[cnt],two,three,mp+10)
        dfs(cnt+1,one,two+l[cnt],three,mp+10)
        dfs(cnt+1,one,two,three+l[cnt],mp+10)
        dfs(cnt+1,one,two,three,mp)
    end
end

function main()
    global ans
    dfs(1,0,0,0,0)
    println(ans)
end
main()

Measured memory_bytes: 171076
#include <bits/stdc++.h>
using namespace std;
//関数
const long INF=1000000000000000;

int main(void){
    long N;
    cin>>N;
    vector<string> W(N);
    for(int i=0;i<N;i++) cin>>W.at(i);
    
    for(int i=1;i<N;i++){
        for(int j=0;j<i;j++){
            if(W.at(i)==W.at(j)){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    
    for(int i=0;i<N-1;i++){
        if(W.at(i).at(W.at(i).size()-1) != W.at(i+1).at(0)){
            cout<<"No"<<endl;
            return 0;
        }
    }
    
    cout<<"Yes"<<endl;
}


Measured memory_bytes: 768
#include <stdio.h>
 
int main() {
  char str[101];
  scanf("%s", str);
  int n, i, cnt;
  cnt = 0;
  for(n = 0; n < 101; n++) if(str[n] == '\0') break;
  for(i = 0; i < n-i; i++) if(str[i] != str[n-1-i]) cnt++;
 
  printf("%d", cnt);
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())

ll N, M, R;
vector<ll> r;
ll road[201][201];

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> N >> M >> R;
  rep(i,R){ll inp; cin >> inp; inp--; r.pb(inp);}

  rep(i,201)rep(j,201)
    road[i][j]=1e9;

  rep(i,M){
    ll a,b,c; cin >> a >> b >> c;
    a--;b--;
    road[a][b]=c;
    road[b][a]=c;
  }

  rep(k,N)rep(i,N)rep(j,N)
    road[i][j]=min(road[i][j], road[i][k]+road[k][j]);

  ll ans = 1e9;
  sort(all(r));
  
  //ll times = 1;FOR(i,1,R+1)times*=i;
  do{
    ll sum=0;
    rep(j,r.size()-1){
      sum+=road[r[j]][r[j+1]];
    }
    ans = min(ans,sum);
  }while( next_permutation(all(r)) );
  

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


Measured memory_bytes: 640
import sys
sys.setrecursionlimit(10**7)

N, M = map(int, input().split())
edge = [[] for _ in range(N)]
for _ in range(M):
    x, y = map(int, input().split())
    edge[x-1].append(y-1)
dp = [-1]*N

def calc(x):
    if dp[x]!=-1:
        return dp[x]
    if not len(edge[x]):
        dp[x] = 0
        return 0
    dp[x] = max([calc(i) for i in edge[x]])+1
    return dp[x]

ans = 0
for i in range(N):
    if dp[i] != -1: continue
    ans = max(ans, calc(i))
print(ans)


Measured memory_bytes: 115580
#include <stdio.h>

int main(){
  int i,j,k,x,n,count;
  
  while(1){
    count =0;
  scanf("%d %d\n",&n,&x);
    
    if(n+x == 0) break;
    
  for(i=1;i<=n;i++){
  	for(j=1+i;j<=n;j++){
    	for(k=1+j;k<=n;k++){
		if(i+j+k == x) count++;
        }
    }
  }
  printf("%d\n",count);
  
  }
}


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


int main(){
  int N, K;
  cin >> N >> K;
  vector<int> V(N);
  for(auto& v : V){
    cin >> v;
  }

  int ans = 0;
  int max_pop_num = min(N, K);
  for(int gr=0; gr<=max_pop_num; gr++){
    for(int gl=0; gl<=max_pop_num-gr; gl++){
      vector<int> tmp(gr+gl);
      for(int ii=0; ii<gr; ii++){
        tmp[ii] = V[ii];
      }
      for(int ii=0; ii<gl; ii++){
        tmp[gr+ii] = V[N-ii-1];
      }
      sort(tmp.begin(), tmp.end());
      int jj=0;
      int max_push_num = min(K-gr-gl, gr+gl);
      for(; jj<max_push_num; jj++){
        if(tmp[jj]>=0) break;
        tmp[jj] = 0;
      }
      int sum = 0;
      for(; jj<gr+gl; jj++){
        sum += tmp[jj];
      }
      ans = max(ans, sum);
    }
  }
  cout << ans << endl;
  return 0;
}

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

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;
#pragma endregion

#pragma region const
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#pragma endregion

#pragma region util
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }
template<typename T = i64>
void OUT(T& x) { cout << x << endl; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}
#pragma endregion

#pragma region init
struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

#ifdef _DEBUG
signed Main()
#else
signed main()
#endif
{
	auto N = IN();
	double ans = 0.0;
	REP(i, N)
	{
		double a;
		cin >> a;
		ans += 1 / a;
	}
	cout << (1 / ans) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); }
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
#define forxr(i,n) for(int i = (n)-1; i >= 0; --i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll,ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second
#define all(c) c.begin(),c.end()

const int N = 1e5+5;
vector<int> adj[N];
int deg[N];
int len[N];
int n, m;

int main() { // Emily <3
  atexit([](){ cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout << fixed << setprecision(12);
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int u, v; cin >> u >> v;
    adj[u].push_back(v);
    deg[v]++;
  }
  queue<int> wk;
  for (int i = 1; i <= n; ++i) {
    if (deg[i] == 0) {
      wk.push(i);
    }
  }
  int ans = 0;
  while(wk.size()) {
    const int u = wk.front(); wk.pop();
    for (int v : adj[u]) {
      deg[v]--;
      len[v] = max(len[v], len[u]+1);
      ans = max(ans, len[v]);
      if (deg[v] == 0) {
        wk.push(v);
      }
    }
  }
  cout << ans << nl;

  return 0;
}



Measured memory_bytes: 6528
N = int(input())
A = [0] + list(map(int,input().split())) + [0]
Cost = sum([abs(A[i+1]-A[i]) for i in range(N+1)])
for i in range(1,N+1):
    if (A[i]-A[i-1])*(A[i]-A[i+1]) < 0:
        print(Cost)
    else:
        print(Cost+abs(A[i+1]-A[i-1])-abs(A[i]-A[i-1])-abs(A[i]-A[i+1]))

Measured memory_bytes: 14044
#!python3.4.3

k, s = map(int, input().split(' '))
count = 0
for i in range(0, k+1):
    x = i
    for j in range(0, k+1):
        y = j
        z = s - (x + y)
        if 0 <= z <= k:
            count+=1
print(count)

Measured memory_bytes: 2940
//最長共通部分列 http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_C
//要は何枚のコインで支払えますか問題。

// lcmとかはg++ -std=c++17 default.cppみたいなかんじで
//vector<vector<ll>> piyo(tate,vector<ll> (yoko));

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1000000019
#define ll long long
#define ln cout<<endl;
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define double long double
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
int dp[2000][2000];
vector<int> w(2000);
vector<int> v(2000);

int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    //double mini=INF;
    int maxi=0,f=0,sum=0;
    int i;
    double h;
    int n,x,m;
    int a,b,d,c;
    //int e,weight;
    int target;
    //targetが目的値、nが個数
    cin>>n;

    vector<int> v(n);
    rep(i,n) cin>>v[i];
    rep(i,n) sum+=v[i];
    cin>>m;

    rep(i,m){
        cin>>a>>b;
        cout<<sum-v[a-1]+b<<endl;
    }


    return 0;
}


Measured memory_bytes: 256
import sys
from itertools import combinations_with_replacement, product
import numpy as np
def input(): return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    task=[]
    for _ in range(N):
        A,B=map(int, input().split())
        task.append([A,B])
    task.sort(key=lambda x: x[1])
    task=np.array(task)
    task[:,0]=task[:,0].cumsum()
    if all(task[:,0] <= task[:,1]):
        print('Yes')
    else:
        print('No') 

if __name__ == '__main__':
    main()

Measured memory_bytes: 58504
#include <iostream>
#include <cstring>

using namespace std;

int main() {
  int n;
  int ans = 0;
  cin >> n;
  string s;
  cin >> s;
  int l = 0, r = 1;
  while(r <= s.length()) {
    string tmp = s.substr(l,r-l);
    //  cout << tmp << endl;
    if(s.find(tmp,r) < s.length()) {
      ans = max(ans,(int)tmp.length());
      r++;
    }
    else l++,r++;
  }
  cout << ans << endl;
}

    


Measured memory_bytes: 256
inputs = list(map(lambda n: int(n), input().split()))
N, Y = inputs[0], inputs[1]
truth = False

for a in range(N+1):
    if truth:
        break
    for b in range(N+1-a):
        if truth:
            break
        c = N-(a+b)
        if (10000*a + 5000*b + 1000*c) == Y:
            print(a, b, c)
            truth = True

if not truth:
    print('-1 -1 -1')

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

int main()
{
	int n;
	cin >> n;
	std::vector<int> a(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	std::vector<int> s = a;
	sort(s.rbegin(), s.rend());//降べき
	
	for (int i = 0; i < n; ++i)
	{
		int ans = s[0];
		if (s[0] == a[i])
		{
			ans = s[1];
		}
		cout << ans << endl;
	}
	

}

Measured memory_bytes: 3200
read args1
read args2

args1_arr=(${args1// / })

declare -i calc_result
echo ${args1_arr[0]} > calc_result
echo $args2 >> calc_result

calc_result=$(cat calc_result | tr "\n" " " | sed "s/ $//" | sed "s/ /-/g")

[[ ${calc_result} -le 0 ]] && echo "Yes" || echo "No"


Measured memory_bytes: 15608
import numpy as np
n,k=map(int,input().split())
n_lis=[int(i) for i in range(1,n+1)]

p=float(1/n)
p_lis=[]

for i in range(n):
    count=0
    if n_lis[i]<k:
        atai=float(k/n_lis[i])

        for j in range(10000):
            atai=float(atai/2)
            count+=1

            if atai<=1:
                break
        
        p_lis.append((1/2)**(count))
    
    else:
        p_lis.append(1)

print(p*sum(p_lis))

    

Measured memory_bytes: 21384
#pragma warning(disable:4996)
#include <bits/stdc++.h>
#define endl '\n'
#define FIO ios_base::sync_with_stdio(0); cin.tie(NULL)
#define pb push_back
#define pii pair<int,int>
#define ll long long int 
#define ui unsigned int
#define pll pair<ll,ll>
#define vi vector<int>
#define vll vector<ll>  
#define mp make_pair
#define F first
#define S second
#define sz size()
#define all(x) (x).begin(),(x).end() 
#define SORT(v) sort(all(v))
#define SORTD(v) sort(all(v),greater<int>())
#define SET(a,b) for(ui i=0;i<size(a);++i){a[i]=b;} 
#define test() int t; cin>>t ; while(t--)
#define FOR(i,a,b) for(int i=a;i<b;++i)  
#define cerr if(0)cerr
#define watch(x) cerr<<#x<<" is "<<x<<endl;
#define print(x) cout<<x<<endl
#define readv(v) FOR(i,0,n){cin>>v[i];}
#define printv(v) for(auto i : v){cout<<i<<" ";}cout<<endl;
const ll MOD=1e9+7;
ll powmod(ll a,ll b) {ll res=1;a%=MOD; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    vector<int> chars[26];
	
	for(int i=0;i<s.sz;++i)
	{
		chars[s[i]-'a'].pb(i);
	}
	
	ll res=0;
	int last=-1;
	for(int i=0;i<t.sz;++i)
	{
		int x=t[i]-'a';
		int pos=upper_bound(chars[x].begin(),chars[x].end(),last) - chars[x].begin();
		
		if(chars[x].sz==0)
		{
			cout<<-1;
			return 0;
		}
		
		if(pos==chars[x].sz)
		{
			res+=s.sz;
			last=chars[x].front();
		}
		else
		{
			last=chars[x][pos];
		}
	}
	
	res+=last+1;
	
	cout<<res<<endl;	
	

	
    return 0;
}


Measured memory_bytes: 1216
#include <bits/stdc++.h>
#define rep(i, n) for(ll i=0; i<(n); ++i)
#define rep1(i,n) for(ll i=1; i<=(n); ++i)
#define repi(i,a,b) for(ll i=a; i<=(b); ++i)
#define rrep(i,n) for(ll i=(n-1); i>=0; --i)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define print(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
using Edge = pair<ll,ll>;
using Graph = vector<vector<Edge>>;
typedef pair<ll,ll> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
ll MOD = 1e9 + 7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll devc(ll x, ll y){return 1 + (x-1)/y;}
ll modpow(ll x, ll y, ll m) {
    if (y == 0) return 1;
    ll res = modpow(x, y / 2, m);
    return res * res % m * (y & 1 ? x : 1) % m;
}
ll modinv(ll x) { return modpow(x, MOD - 2, MOD); }

int main(){
    ll N; cin >> N;
    vector<ll> X(N); rep(i,N) cin >> X[i];
    ll ans = 1e18;
    
    for(ll i = 1; i <=100; ++i){
        ll sum = 0;
        rep(j,N) sum += (X[j] - i)*(X[j] - i);
        ans = min(sum,ans);
    }
    print(ans);
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string l,w;
int dp[100005][30];
int tot,pos;
int main() {
	cin>>l>>w;
	for(int i=1;i<=26;i++) dp[l.length()+1][i]=-1;
	for(int i=l.length();i>0;i--) {
		for(int j=1;j<=26;j++) dp[i][j]=dp[i+1][j];
		dp[i][int(l[i-1])-96]=i;
	}
	/*
	for(int j=1;j<=26;j++) {
		for(int i=1;i<=l.length();i++) cout<<dp[i][j]<<" ";
		cout<<endl;
	}
	*/
	for(int i=0;i<w.length();i++) {
		if(dp[pos+1][int(w[i])-96]!=-1) pos=dp[pos+1][int(w[i])-96];
		else if(dp[1][int(w[i])-96]!=-1) pos=dp[1][int(w[i])-96],tot++;
		else {cout<<-1;return 0;}
	}
	cout<<tot*l.length()+pos;
	return 0;
}

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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
//const int mod = 1000000007;
const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


int main(){
  int n; cin >> n;
  int d[n];
  rep(i, n) d[i] = 0;
  rep(i, n){
    int x; cin >> x;
    if(i == 0 && x != 0){
      cout << 0 << endl;
      return 0;
    }
    d[x]++;
  }
  if(d[0] != 1){
    cout << 0 << endl;
    return 0;
  }
  bool hz = false;
  int end = n;
  rep(i, n){
    if(d[i] == 0){
      if(!hz) end = i;
      hz = true;
    }
    if(hz && d[i] != 0){
      cout << 0 << endl;
      return 0;
    }
  }

  mint ans = 1;
  rep(i, end - 1){
    mint now = d[i];
    int next = d[i + 1];
    ans *= now.pow(next);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3952
#include<bits/stdc++.h>
using namespace std;
int n;
int a[10]={0,1,2,3,4,5,6,7,8},p[10],q[10],tp,tq;
int main() {
	cin>>n;int cnt=0;
	for(int i=1;i<=n;i++)
		scanf("%d",&p[i]);
	for(int i=1;i<=n;i++)
		scanf("%d",&q[i]);
	do {
		cnt++;
		bool cp=true,cq=1;
		for(int i=1;i<=n;i++)
			if(a[i]!=p[i]) cp=0;
		for(int i=1;i<=n;i++)
			if(a[i]!=q[i]) cq=0;
		if(cp) tp=cnt;
		if(cq) tq=cnt;
	}while(next_permutation(a+1,a+1+n));
	cout<<abs(tp-tq);
	return 0;
} 

Measured memory_bytes: 256
#include<stdio.h>
#include<stdbool.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#define rep(i,n) for(int i=0; i <(n); i++)
int main(){
  int a[5];
  rep(i,5){
    scanf("%d",&a[i]);
    if(a[i]==0){
      printf("%d\n",i+1);
    }
  }
  return 0;
}


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

int main() {
    int Oneday = 24;

    int a;
    cin >> a;
    if (a < 1)
    {
        return -1;
    }
    if (a > 23)
    {
        return -1;
    }

    int b;
    b = Oneday - a;
    cout << Oneday + b << endl;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
fl = False
for i in range(n - m + 1):
    if b[0] in a[i]:
        tmp = a[i].find(b[0])
        if m == 1:
            fl = True
        for j in range(1,m):
            if a[i+j][tmp:tmp+m] != b[j]:
                fl = False
                break
            fl = True
    if fl:
        break
if fl:
    print("Yes")
else:
    print("No")

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

int main() {
  int d, n;
  cin >> d >> n;
  int handred = 1;
  for (int k = 0; k < d; k++) {
    handred *= 100;
  }
  int ans = handred * n;
  if (n == 100 && d == 0) cout << ans + 1 << endl;
  else if (n == 100 && d == 1) cout << ans + 100 << endl;
  else if (n == 100 && d == 2) cout << ans + 10000 << endl;
  else cout << ans << endl;
}

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

using namespace std;

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }

int main(int argc, char *argv[]) {
	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	
	int left[n+1] = {0};
	for (int i = 0; i < n; i++) {
		left[i+1]  = GCD(left[i], a[i]);
	}
	int right[n+1] = {0};
	for (int i = n-1; i >= 0; i--) {
		right[i] = GCD(right[i+1], a[i]);
	}
	
	int ans = INT_MIN;
	for (int i = 0; i < n; i++) {
		int l = left[i];
		int r = right[i+1];
		
		int gcd = GCD(l, r);
		if (gcd > ans) {
			ans = gcd;
		}
	}
	
	cout << ans << endl;
}

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

int main(){
  int A, B,C,X,Y,large,abc,ac,bc;
  cin>>A>>B>>C>>X>>Y;
  
  large=max(X,Y);  
  vector<int> cost;
  
  for(int i=0;i<=large;i++){
    if(i==0)
      abc=1;
    else
      abc=i*2;
    ac=X-abc/2;
    if(ac<0)
      ac=0;
    bc=Y-abc/2;
    if(bc<0)
      bc=0;
    if(i==0)
      abc=0;
    cost.push_back(ac*A+bc*B+abc*C);
  }
  sort(cost.begin(),cost.end());
  cout <<cost.at(0)<<endl;
  
}


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

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

    vector<int> b(n-1);
    for(int i;i<n-1;i++)
        cin >> b.at(i);
    
    int res=b.at(0);
    for(int i=1;i<n-1;i++){
        res+=min(b.at(i-1), b.at(i));
      // cout << min(b.at(i-1), b.at(i))<<endl;
    }
    cout << res+b.at(n-2);
    return 0;
}

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

#define int long long
#define counter(m)     for(int i=0;i<m;i++)
#define gcd            __gcd
#define endl           "\n"
#define pb             emplace_back
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x, y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI             3.141592653589793238
using namespace std;

int32_t main() {
    nitin;
    int n,c,k;
    cin>>n>>c>>k;
    int dp[n];
    int times[n];
    for(int i=0;i<n;i++)
    {
        cin>>times[i];
        dp[i]=INT_MAX;
    }
    dp[0]=1;
    sort(times,times+n);
    for(int i=1;i<n;i++)
    {
        dp[i]=dp[i-1]+1;
        int time=times[i]-k-1;
        int idx=upper_bound(times,times+n,time)-times;
        int cidx=i-c+1;
        int realidx=max(idx,cidx);
        if(realidx!=0)
        dp[i]=dp[realidx-1]+1;
        else
            dp[i]=1;
    }
    cout<<dp[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 5220
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#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(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };
bool msb[300000];
int main() {
	vector<int> msi;
	for (int i = 2; i < 300000; i++){
		if (i % 7 == 6 && !msb[i]){
			msi.push_back(i);
			for (int j = i; j < 300000; j += i)msb[j] = true;
		}

		if (i % 7 == 1 && !msb[i]){
			msi.push_back(i);
			for (int j = i; j < 300000; j += i)msb[j] = true;
		}
	}

	int n;
	while (cin >> n, n != 1){
		int nc = n;
		vector<int> ans;

		for (int i = 0; i < msi.size(); i++){
			if (nc%msi[i]==0)ans.push_back(msi[i]);
	}
		
		cout << n << ":";
		REP(i,ans.size())
		cout << " " <<ans[i];
		cout << endl;
	}
}

Measured memory_bytes: 3532
/**
 * @Author:      H S-J
 * @DateTime:    2017-11-04 20:31:20
 * @Description: 
 */
#include <bits/stdc++.h>
using namespace std;
#define MST(a, b) memset(a, b, sizeof(a));
#define CLR(a) MST(a, 0);
#define DBG(x) cout << '#' << " = " << (x) << endl;
#define ALL(x) x.begin(), x.end()
#define INS(x) inserter(x, x.begin())
#define lson(x) (x) << 1
#define rson(x) (x) << 1|1
#define pb push_back
#define rep(x, y, z) for (int x = y; x < z; ++x)
#define ech(x, y, z) for (auto x = z.begin(), y = z.end(); x != y; ++x)
#define lowbit(x) (x & (-x))
#define opr operator
#define _st first
#define _nd second
#define prior_q1(x) priority_queue<x>
#define prior_q2(x) priority_queue<x, vector<x>, greater<x> >
typedef long long LL;
typedef stringstream strstm;
struct FastIO {
    static const int S = 1310720;
    int wpos;
    char wbuf[S];
    FastIO() : wpos(0) {}
    inline int xchar() {
        static char buf[S];
        static int len = 0, pos = 0;
        if (pos == len)
            pos = 0, len = fread(buf, 1, S, stdin);
        if (pos == len) return -1;
        return buf[pos ++];
    }
    inline int xuint() {
        int c = xchar(), x = 0;
        while (c <= 32) c = xchar();
        for (; '0' <= c && c <= '9'; c = xchar()) x = x * 10 + c - '0';
        return x;
    }
    inline int xint() {
        int s = 1, c = xchar(), x = 0;
        while (c <= 32) c = xchar();
        if (c == '-') s = -1, c = xchar();
        for (; '0' <= c && c <= '9'; c = xchar()) x = x * 10 + c - '0';
        return x * s;
    }
    inline LL xlongint() {
        LL s = 1, c = xchar(), x = 0;
        while (c <= 32) c = xchar();
        if (c == '-') s = -1, c = xchar();
        for (; '0' <= c && c <= '9'; c = xchar()) x = x * 10 + c - '0';
        return x * s;
    }
    inline void xstring(char *s) {
        int c = xchar();
        while (c <= 32) c = xchar();
        for (; c> 32; c = xchar()) * s++ = c;
        *s = 0;
    }
    inline void wchar(int x) {
        if (wpos == S) fwrite(wbuf, 1, S, stdout), wpos = 0;
        wbuf[wpos ++] = x;
    }
    inline void wint(LL x) {
        if (x < 0) wchar('-'), x = -x;
        char s[24];
        int n = 0;
        while (x || !n) s[n ++] = '0' + x % 10, x /= 10;
        while (n--) wchar(s[n]);
    }
    inline void wstring(const char *s) {
        while (*s) wchar(*s++);
    }
    ~FastIO() {
        if (wpos) fwrite(wbuf, 1, wpos, stdout), wpos = 0;
    }
} io;
const int maxn = (int)1e5+11;
long long cnt[maxn], n;
void init() {
	rep(i, 0, maxn) cnt[i] = (i+1)*(i+1);
	// rep(i, 0, 11) cout << cnt[i] << endl;
}
int main(int argc, char const *argv[]) {
	ios::sync_with_stdio(0);cin.tie(0);
	init(); while(cin >> n) {
        int m = (int)sqrt(n) + 1;
        int ans = upper_bound(cnt, cnt + m, n) - cnt;
        cout << cnt[ans-1] << endl;
        // cout << ans << endl;
    }
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define REP(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define INF 10000000
#define ll long long

using namespace std;

typedef pair<int, int> P;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

int a, b, c, x, y;
int d;
ll int ans;

int main(){
	scanf("%d%d%d%d%d", &a, &b, &c, &x, &y);

	int l = min(a + b, c * 2);

	if(x > y){
		d = x - y;
		int m = min(a, c * 2);
		ans = l * y + m * d;
		printf("%d\n", ans);
	} else if (x < y){
		d = y - x;
		int m = min(b, c * 2);
		ans = l * x + m * d;
		printf("%d\n", ans);
	} else {
		ans = l * x;
		printf("%d\n", ans);
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
#ifndef ONLINE_JUDGE
#define dbg(x...) do{cout << "\033[32;1m" << #x << "->" ; err(x);} while(0)
void err(){cout << "\033[39;0m" << endl;}
template<template<typename...> class T,typename t,typename... A>
void err(T<t> a,A... x){for (auto v:a) cout << v << ' '; err(x...);}
template<typename T,typename... A>
void err(T a,A... x){cout << a << ' '; err(x...);}
#else
#define dbg(...)
#endif
const int mod=998244353;
const int INF=0x3f3f3f3f;
ll quick(ll a,ll b)
{
	ll ret=1;
	while(b)
	{
		if(b&1)
			ret=ret*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ret;
}
ll inv(ll a){return quick(a,mod-2);}
string s;
ll ans=0;
void dfs(int p,ll val,ll cur=0)
{
	if(p==s.length())
	{
		ans+=cur+val;
		return;
	}
	dfs(p+1,s[p]-'0',cur+val);
	dfs(p+1,val*10+s[p]-'0',cur);
}
int main()
{
	cin>>s;
	dfs(0,0);
	cout<<ans/2<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
int p[100100],c[100100],e[100100];
int dp[2][100100];//dp[i+1][j]:=i番目までの箱を使ってj個の饅頭
int main()
{
	int n,m;
	cin >> n >> m;
	int sum=0;
	for(int i=0;i<n;i++)cin >> p[i];
	for(int i=0;i<m;i++)cin >> c[i] >> e[i];
	sort(p,p+n,greater<int>());
	for(int i=0;i<n;i++)p[i+1]+=p[i];
	for(int i=0;i<2;i++)
	{
		for(int j=0;j<=n;j++)
		{
			dp[i][j]=INF;
		}
	}
	dp[0][0]=0;
	for(int i=0;i<m;i++)
	{
		for(int j=0;j<=n;j++)
		{
			dp[(i+1)%2][j]=min(dp[i%2][j],dp[i%2][max(j-c[i],0)]+e[i]);
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		ans=max(ans,p[i-1]-dp[m%2][i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1320
def main():
    N=int(input())
    a=[int(x) for x in input().split()]

    for i in range(N):
        if a[i]%2==0:
            if a[i]%3!=0 and a[i]%5!=0:
                print("DENIED")
                return
    print("APPROVED")


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384