akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>

int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i+1;
}

void maxHeapify(int *A,int H,int i){
  int l,r,largest,ex;

  l=left(i);
  r=right(i);
  if(l<=H && A[l]>A[i])
    largest=l;
  else largest=i;
  
  if(r<=H && A[r]>A[largest])
    largest=r;
  if(largest!=i){
    ex=A[largest];
    A[largest]=A[i];
    A[i]=ex;
    maxHeapify(A,H,largest);
  }
}

void buildMaxHeap(int *A,int H){
  int i;
  for(i=H/2;i>=1;i--)
    maxHeapify(A,H,i);
}

void print(int *A,int H){
  int i;
  for(i=1;i<=H;i++)
    printf(" %d",A[i]);
}

int main(){
  int H,i,*A;
  scanf("%d",&H);
  A=malloc(sizeof(int*)*(H+1));
  for(i=1;i<=H;i++)
    scanf("%d",&A[i]);
  buildMaxHeap(A,H);
  print(A,H);
  printf("\n");
  return 0;
}



Measured memory_bytes: 3664
#include "stdio.h"

int main()
{
	int a, b, c, n;

	scanf("%d", &n);

	for (int i = 0; i < n; i++){
		scanf("%d %d %d", &a, &b, &c);

		a *= a;
		b *= b;
		c *= c;

		if(c == a+b || b == a+c || a == b+c) printf("YES\n");
		else printf("NO\n");
	}

	return 0;
}

Measured memory_bytes: 1008
#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;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl; 有効桁数指定
// *min_element(c + l, c + r) *max_element(c + l, c + r) 配列の中のmin-max
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// ~ は、-1の時だけfalse
// struct Edge {
//   int to, id;
//   Edge(int a, int b): to(a), id(b) {}
// };

int a[25][25];


int main(int argc, char const *argv[])
{
	int n;cin>>n;

	rep(i,n) {
		rep(j,n) {
			cin>>a[i][j];
		}
	}

	vector<ll> dp(1<<n,0);
	dp[0]=1;

	rep(s,1<<n) {
		rep(i,n) {
			if (s>>i&1) {
				dp[s]+=dp[s^(1<<i)]*a[__builtin_popcount(s)-1][i];
				dp[s]%=MOD;
			}
		}
	}

	cout<<dp[(1<<n)-1]<<endl;


	return 0;
}

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

int main(){
  int i,j,cnt;
  int n;
  cin>>n;
  int a[n];
  for(i=0;i<n;i++)cin>>a[i];
  sort(a,a+n);
  int p[a[n-1]+1];
  for(i=0;i<=a[n-1];i++)p[i]=0;
  for(i=0;i<n;i++){
    p[a[i]]++;
    if(a[i]-1>=0)p[a[i]-1]++;
    if(a[i]+1<=a[n-1])p[a[i]+1]++;
  }
  int ma=0;
  for(i=0;i<=a[n-1];i++){
    ma=max(ma,p[i]);
  }
  cout<<ma;
}

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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)


int main()
{
  ll k, a, b;
  cin >> k >> a >> b;
  if (b - a > 2){
	k -= (a-1);
	cout << a + (b - a) * (k / 2) + k % 2 << endl;
  }
  else
	cout << 1 + k << endl;
}


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

a = list(map(int, input().split()))

nums = {}
for i in a:
  if i in nums:
    nums[i] += 1
  else:
    nums[i] = 1
    
nums_list_sorted = sorted(nums.items(), reverse=True)

a = 0
b = 0
# 最大のが4つ以上とかを考慮するのが抜けてた
for i in range(len(nums_list_sorted)):
  if nums_list_sorted[i][1] >= 2:
    if a == 0:
      a = nums_list_sorted[i][0]
      if nums_list_sorted[i][1] >= 4:
        b = a
        break
      #del nums_list_sorted[i]
    else:
      b = nums_list_sorted[i][0]
      break

print(a*b)

Measured memory_bytes: 21128
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <array>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <utility>
#include <iomanip>
#include <numeric>
#include <climits>
#include <algorithm>
#include <cstdint>
using namespace std;

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

    if (x < a)
        cout << "0";
    else cout << "10";
}

Measured memory_bytes: 3612
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<vector>

using namespace std;

int main(void) {
	int N = 0,p = 0;
	int min = INT_MAX;
	int CENTER = 0;
	scanf("%d", &N);
	vector<int> list(N);
	for (int i = 0; i < N; i++) {
		int j = 0;
		scanf("%d", &j);
		list[i] = j;
	}

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

	CENTER = list[N - 1] / 2 + ((list[N - 1] % 2) == 0 ? 0 : 1);

	for (int i = 0; i < N; i++) {
		if (abs(CENTER  - list[i]) < min) {
			min = abs(CENTER - list[i]);
			p = list[i];
		}
	}

	printf("%d %d\n", list[N - 1], p);

	return 0;
}

Measured memory_bytes: 1272
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main()
{
	double x, h;
	while (cin >> x >> h)
	{
		if (x == 0.0 && h == 0.0) break;
		printf("%.6f\n", (x*x + 4.0*(x*sqrt(h*h+(x*x)/4.0))/2.0));
	}
}

Measured memory_bytes: 0
//#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

using namespace std;
using ll=long long;

void solve(){
  int num,k;
  cin >> num >> k;
  cout << (int)(num%k>0) << endl;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){

  int a[6];
  REP(i,6){
    cin>>a[i];
  }
  int kazu[4];
  REP(i,4){
    kazu[i] = 0;
  }
  REP(i,6){
    kazu[a[i]-1]++;
  }
  REP(i,4){
    if(kazu[i]>=3){
      cout<<"NO"<<endl;
      return 0;
    }
  }
  cout<<"YES"<<endl;
  return 0;


  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
typedef long long int ll;
int main() 
{ 
	ll a,b,c,k;
	ll sum=0;
	cin>>a>>b>>c>>k;
	if(k>=a)
	{
		sum=sum+a*1;
		k=k-a;
	}
	else{
		sum=sum+k*1;
		k=0;
	}
	if(k>=b)
	{
		k=k-b;
	}
	else
		k=0;
	if(k>c)
	{
		sum=sum-c*-1;
		k=k-c;
	}
	else
		sum=sum-k*1;
	cout<<sum;
} 


Measured memory_bytes: 3636
#include <stdio.h>
#include <string.h>
#define LEN 100005

typedef struct pp {
    char name[100];
    int t;
} P;

P Q[LEN];
int tail, head, n;

void enqueue(P x)
{
    Q[tail] = x;
    tail = (tail + 1) % LEN;
}

P dequeue()
{
    P x = Q[head];
    head = (head + 1) % LEN;
    return x;
}

int min(int a, int b)
{
    return a < b ? a : b;
}

int main(int argc, char const *argv[])
{
    int elaps = 0, c;
    int i, q;
    P u;
    scanf("%d %d", &n, &q);

    for (i = 1; i <= n; i++) {
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].t);
    }
    head = 1; tail = n + 1;


    while (head != tail) {
        u = dequeue();
        c = min(u.t, q);
        u.t -= c;
        elaps += c;
        if (u.t > 0) {
            enqueue(u);
        } else {
            printf("%s %d\n", u.name, elaps);
        }
    }

    return 0;
}



Measured memory_bytes: 11892
#include<stdio.h>
#define N 10000
#define Q 500

int search(int);
int S[N];
int n;
main(){
  
  int q,T[N],i,j,x,count=0;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
  }
  for(i=0;i<q;i++){
    x= search(T[i]);
  if(x>=0 && x<n){
    count++;
  }
  }
  
  printf("%d\n",count);
  return 0;
}

int search(int key){
  int i=0;
  S[n]=key;
  while(S[i]!=key){
    i++;
    if(i==n){
      return n;
    }
  }
  return i;
}

Measured memory_bytes: 644
n=int(input())
A=[int(i) for i in input().split()]
ans=0
l,r=0,0
x,s=A[0],A[0]
while l!=n-1 or r!=n-1:
  if x==s:
    ans+=r-l+1
    if r<n-1:
      r+=1
      x^=A[r]
      s+=A[r]
    else:
      break
  else:
    l+=1
    x^=A[l-1]
    s-=A[l-1]
if l==n-1 and r==n-1:
  ans+=1
print(ans)

Measured memory_bytes: 23560
#include <iostream>
using namespace std;
typedef long long ll;
#define MOD1 1000000007
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
#define nHr(n,r) COM((n)+(r)-1,(r))
int main(){
  COMinit();
  ll n,k,i,j,result=1;
  cin >> n >> k;
  for(i=1;i<=k;i++){
    result = COM(n-k+1,i);
    result *= COM(k-1,i-1);
    result %= MOD1;
    cout << result << endl;
  }
  return 0;
}

Measured memory_bytes: 15592
# Kは最大で５なので、1~５文字の部分文字列を全列挙して重複省いてソートすれば終わり
s = input()
K = int(input())

sub = set()
for i in range(K):
    for j in range(len(s) - i):
        sub.add(s[j:j + i + 1])

sub = list(sub)
sub.sort()

print(sub[K - 1])

Measured memory_bytes: 10356
#include <bits/stdc++.h>
#define fin ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define w(t) while(t--)
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
#define what_is(x) cerr << #x << " is " << x << '\n'
#define FL freopen("in", "r", stdin),freopen("out", "w", stdout);
#define time cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
const int N = 3 * 1e5 + 5;
const ll mod = 998244353;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
const double E = 1e-9;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b)  
int pre[N], suf[N];
int main(){
    //FL;
    fin;
    int n;
    string str;
    cin >> n >> str;
    fore(i, 0, sz(str))
        pre[i] = (str[i] == 'W');
    fore(i, 1, sz(str))
        pre[i] += pre[i - 1];
    for(int i = sz(str) - 1; i >= 0; i--)
        suf[i] = (str[i] == 'E');
    for(int i = sz(str) - 2; i >= 0; i--)
        suf[i] += suf[i + 1];
    int ans = 1e9;
    fore(i, 0, n){
        int aux_1 = 0;
        if(i)
            aux_1 = pre[i - 1];
        int aux_2 = 0;
        if(i + 1 < n)
            aux_2 = suf[i + 1];
        ans = min(ans,aux_2 + aux_1);
    }
    cout << ans << '\n';
    time;
    return 0;
}   

Measured memory_bytes: 2964
#include <stdio.h>
int main(void){
    // Your code here!
    int a,b,c,count,i;
    scanf("%d %d %d",&a,&b,&c);
    for(i=a,count=0;i<=b;count+=!(c%i++));
    printf("%d\n",count);
    return 0;
}



Measured memory_bytes: 2104
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}

macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let s: String = sc.cin();
    put!(if s.chars().zip(s.chars().skip(1)).any(|(c,d)| c==d) {
        "Bad"
    } else {
        "Good"
    });
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n)-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(b)-1;i>=(a);--i)
#define ALL(a) a.begin(),a.end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
    if (a < b) { a = b; return true; }
    return false;
}
template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
    if (a > b) { a = b; return true; }
    return false;
}
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
    os << "{";
    int a = 0;
    for (auto &tp : mp) {
        if (a) os << ", "; a = 1;
        os << tp;
    }
    return os << "}";
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    os << p.first << ":" << p.second;
    return os;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    for (;;) {
        int n; cin >> n;
        if (n == 0) break;
        vector<string> names(n);
        REP(j, n) {
            string s; cin >> s;
            names[j] += s[0];
            FOR(i, 1, s.size()) {
                if (s[i-1] == 'a' or s[i-1] == 'i' or s[i-1] == 'u' or
                    s[i-1] == 'e' or s[i-1] == 'o') {
                    names[j] += s[i];
                }
            }
        }

        int ans = -1;
        FOR(k, 1, 51) {
            map<string,bool> mp;
            for (string s : names) {
                mp[s.substr(0, k)] = 1;
            }
            if (mp.size() == n) {
                ans = k;
                break;
            }
        }
        cout << ans << endl;
    }


    return 0;
}



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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "{";
    rep(i, (int)v.size()) {
        if (i)
            os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
    for (auto val : array)
        std::cout << val << ", ";
    std::cout << "\n";
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::setprecision(10);

   int a, p; std::cin >> a >> p;
   p += a * 3;
   std::cout <<  p / 2 << "\n";
}


Measured memory_bytes: 256
program main
implicit none
integer(8) :: w, h, x, y
integer(8) :: i
real(8) :: s

read(*,*) w, h, x, y
s = dble(w)*dble(h)/2.
if( 2*x == w.and. 2*y == h ) then
   i = 1
else
   i = 0
end if
write(*,'(f0.10, a1,i0)') s, ' ', i


end program main


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main()
{
  string S;
  cin >> S;
  int N = S.length();
  for (int i = 1; i < N; i++)
  {
    for (int j = i; j < N; j++)
    {
      string T = S.substr(0, i) + S.substr(j, N - j);
      if (T == "keyence")
      {
        cout << "YES" << endl;
        return 0;
      }
    }
  }
  cout << "NO" << endl;
  return 0;
}

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

#define MOD 1000000007

int main() {
	ll n, m, ans;
	cin >> n >> m;
	if (abs(n - m) > 1) {
		cout << 0 << endl;
		return 0;
	}

	ll n1 = n;
	ll m1 = m;
	for (ll i = n-1; i >= 1; i--)
		n1 = (n1 * i) % MOD;
	for (ll i = m-1; i >= 1; i--)
		m1 = (m1 * i) % MOD;

	if (n == m) {
		ans = (n1 * m1 * 2) % MOD;
	} else {
		ans = (n1 * m1) % MOD;
	}

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


Measured memory_bytes: 256
#include <stdio.h>

#define INF 1000

int D,N;
int a[100];
int e[100];
int r[100];

int memo[101][101];

int search(int tkrk,int kkt) {
	int ret=INF;
	int i;
	if(tkrk<=0)return 0;
	if(memo[tkrk][kkt]>0)return memo[tkrk][kkt]-1;
	memo[tkrk][kkt]=INF+1;
	for(i=0;i<N;i++) {
		if(kkt>=r[i]) {
			int next_kkt=kkt+e[i];
			int candidate;
			if(next_kkt>100)next_kkt=100;
			candidate=search(tkrk-a[i],next_kkt)+1;
			if(candidate<ret)ret=candidate;
		}
	}
	memo[tkrk][kkt]=ret+1;
	return ret;
}

int main(void) {
	while(scanf("%d%d",&D,&N)==2 && (D!=0 || N!=0)) {
		int i,j;
		int ret;
		for(i=0;i<N;i++) {
			if(scanf("%d%d%d",&a[i],&e[i],&r[i])!=3)return 1;
		}
		for(i=0;i<=100;i++) {
			for(j=0;j<=100;j++)memo[i][j]=0;
		}
		ret=search(D,0);
		if(ret==INF)puts("NA"); else printf("%d\n",ret);
	}
	return 0;
}

Measured memory_bytes: 664
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		char[][] field = new char[h][];
		int[][] costs = new int[h * w][h * w];
		for (int i = 0; i < h * w; i++) {
		    Arrays.fill(costs[i], Integer.MAX_VALUE / 10);
		    costs[i][i] = 0;
		}
		for (int i = 0; i < h; i++) {
		    field[i] = sc.next().toCharArray();
		    for (int j = 0; j < w; j++) {
		        if (i > 0 && field[i - 1][j] == '.' && field[i][j] == '.') {
		            costs[i * w + j][(i - 1) * w + j] = 1;
		            costs[(i - 1) * w + j][i * w + j] = 1;
		        }
		        if (j > 0 && field[i][j - 1] == '.' && field[i][j] == '.') {
		            costs[i * w + j][i * w + j - 1] = 1;
		            costs[i * w + j - 1][i * w + j] = 1;
		        }
		    }
		}
		for (int i = 0; i < h * w; i++) {
		    for (int j = 0; j < h * w; j++) {
		        for (int k = 0; k < h * w; k++) {
		            costs[j][k] = Math.min(costs[j][k], costs[j][i] + costs[i][k]);
		        }
		    }
		}
		int max = -1;
		for (int i = 0; i < h; i++) {
		    for (int j = 0; j < w; j++) {
		        for (int k = 0; k < h; k++) {
		            for (int l = 0; l < w; l++) {
        		        if (field[i][j] == '.' && field[k][l] == '.') {
        		            max = Math.max(max, costs[i * w + j][k * w + l]);
        		        }
		            }
		        }
		    }
		}
		System.out.println(max);
	}
	
}


Measured memory_bytes: 37796
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int N;
string s, t;

int main(void)
{
	cin >> N;
	cin >> s >> t;
	
	int ans = 0;
	for(int i = 1; i <= N; i++){
		if(s.substr(N-i, i) == t.substr(0, i)) ans = max(ans, i);
	}
	
	cout << 2*N - ans << endl;
	return 0;
}

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

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

    for(int i=0;i<S.length();i++){
        if(S.at(i)+N>'Z'){
            S.at(i)=S.at(i)-(26-N);
        }else{
            S.at(i)=S.at(i)+N;
        }
    }
    cout<<S<<endl;
}

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

int main(){
  int n, i;
  cin >> n;
  float x; string u;
  float sum = 0;
  for(i = 0; i < n; i++){
    cin >> x >> u;
    if(u == "JPY") sum += x;
    else sum += x*380000;
  }
  printf("%f\n", sum);
  return 0;
}


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

using namespace std;
using namespace __gnu_pbds;

#define sz(x) (int)(x).size()
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

struct int_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

struct pair_hash {
    size_t operator()(pii x) const {
        return int_hash{}(x.first) ^ (int_hash{}(x.second) << 16);
    }
};

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<cd> vcd;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
typedef vector<vector<pii>> vvpii;
typedef vector<vector<pll>> vvpll;
typedef unordered_map<int, int, int_hash> umpii;
typedef unordered_map<ll, ll, int_hash> umpll;
typedef unordered_set<int, int_hash> usi;
typedef unordered_set<ll, int_hash> usll;
typedef unordered_set<pii, pair_hash> uspii;
typedef queue<int> qi;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = numeric_limits<int>::max();
const int MX = 100001; //check the limits, dummy

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n; cin >> n;
    vi v(n, 0);
    vi d(13, 0);
    for(int i = 0; i < n; i++) {
        cin >> v[i];
        if(++d[v[i]] == 3) {
            cout << 0 << endl;
            return 0;
        }
    }

    sort(begin(v), end(v));
    int ans = 12;
    for(int i = 1, b = 1; i < n; i++, b ^= 1) {
        v[i] = b ? 24 - v[i] : v[i];
        int diff = abs(v[i] - v[i - 1]);
        ans = min(ans, min(24 - diff, diff));
        if(i >= 2) ans = min(ans, abs(v[i] - v[i - 2]));
    }    
    
    cout << min(ans, v[0]) << endl;
}

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

using namespace std;

/* * * *   Knacks   * * * */
typedef long long ll;
const int oo = 1e9;
const ll mod = 100000000;
/* * * *   * * *   	* * * */

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n, w; cin>>n>>w;
	int m=0;
	vector<int> W(n+1, 0), v(n+1, 0);
	for (int i=1;i<=n; ++i) {
		cin>>W[i]>>v[i];
		m+=v[i];
	}
	vector<bool> p(1e6); vector<ll> c(1e6, 1e10);
	p[0] = 1;
	c[0] = 0;
	for (int i=1; i<=n; ++i){
		for(int j = m; j>=0; --j){
			if (p[j]) {
				p[j+v[i]] = 1;
				c[j+v[i]] = min(c[j + v[i]], c[j] + W[i]);
			}
		}
	}
	for (int i=m; i>=0; --i){
		if (p[i] && c[i] <= w){
			cout<<i<<"\n";
			return 0;
		}
	}
	return 0;
}



Measured memory_bytes: 8192
n,k=gets.split.map(&:to_i)
r,s,p=gets.split.map(&:to_i)
t=gets.chomp.split("")
words = []
t.each do |word|
  case word
    when "r"; words << ["p",p]
    when "s"; words << ["r",r]
    when "p"; words << ["s",s]
  end
end
(n-k).times do |index|
  next_value = words[index+k][0]
  if words[index][0] == next_value
    array = ["r","s","p"]
    array.delete(next_value)
    next_value = array[0]
    if index+2*k < n
    	next_value = array[1] if next_value == words[index+2*k][0]
    end
    words[index+k] = [next_value,0]
  end 
end
puts words.map{|pattern,value|value}.inject(:+)

Measured memory_bytes: 26108
import math
from collections import deque
S = input()
L_kyoukai = []
R_kyoukai = [0]
flag = False
for i in range(1, len(S)):
    if flag is False and S[i] == "L":
        L_kyoukai.append(i)
        R_kyoukai.append(i - 1)
        flag = True
    if flag is True and S[i] == "R":
        L_kyoukai.append(i - 1)
        R_kyoukai.append(i)
        flag = False
ans = []
L_kyoukai.append(len(S) - 1)
r_diff = [R_kyoukai[i + 1] - R_kyoukai[i] + 1 for i in range(0, len(R_kyoukai), 2)]
l_diff = [L_kyoukai[i + 1] - L_kyoukai[i] + 1 for i in range(0, len(L_kyoukai), 2)]
for r, l in zip(r_diff, l_diff):
    tmp_1 = math.ceil(r / 2)
    tmp_2 = math.ceil(l / 2)
    ans.append(tmp_1 + l - tmp_2)
    ans.append(r - tmp_1 + tmp_2)
q = deque(ans)    
answer = ""

for i in range(len(S)):
    if 1 <= i <= len(S) - 2:
        if (S[i] == "L" and S[i - 1] == "R") or (S[i] == "R" and S[ i + 1] == "L"):
            answer += str(q.popleft())
            answer += " "
        else:
            answer += "0 "
    elif i == 0:
        if S[i + 1] == "L":
            answer += str(q.popleft())
            answer += " "
        else:
            answer += "0 "
    elif i == len(S) - 1:
        if S[i - 1] == "R":
            answer += str(q.popleft())
            answer += " "
        else:
            answer += "0 "

print(answer)        

Measured memory_bytes: 14036
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

input_list = [a, b, c, d, e]

moda = a % 10
modb = b % 10
modc = c % 10
modd = d % 10
mode = e % 10

mod_list = [moda, modb, modc, modd, mode]

min = 124
flag = -1
for cnt, i in enumerate(mod_list):
    if i != 0 and i < min:
        min = i
        flag = cnt

cnt = 0
for i in range(0, 5):
    if i == flag:
        cnt = cnt + input_list[i]
    elif mod_list[i] == 0:
        cnt = cnt + input_list[i]
    else:
        cnt = cnt + input_list[i] + (10 - mod_list[i])

print(cnt)


Measured memory_bytes: 3064
#include<stdio.h>
int main(){
  int n,m,min,max,i,j,s[30],r;
  while(scanf("%d %d",&n,&m),n||m){
    for(r=0;r<21;r++){
      s[r]=n;//printf("%d:%d\n",r,n);
      int b[10]={0};
      for(i=0;i<m;i++){
	b[n%10]++;
	n/=10;
      }
      for(i=min=max=0;i<10;i++){
	for(j=0;j<b[i];j++)min=min*10+i;
      }
      for(i=9;i>-1;i--){
	for(j=0;j<b[i];j++)max=max*10+i;
      }//printf("%d %d\n",max,min);
      max-=min;
      for(i=0;i<=r;i++){
	if(max==s[i])break;
      }
      if(i<=r)break;
      s[r+1]=n=max;
    }
    printf("%d %d %d\n",i,max,r-i+1);
  }
  return 0;
}

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

int main() {
  string s;
  long long k;
  cin >> s >> k;
  long long after_days = 500000000000;
  int i;
  for (i = 0; i < s.length(); i++) {
    if (s.at(i) != '1' || k == 1) {
      cout << s.at(i) << endl;
      break;
    } else {
      k--;
    }
    if (i == s.length() - 1) {
      cout << s.at(i) << endl;
    }
  }
  return 0;
}


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

struct P{
  int a,b,idx;
  P(){a=b=idx=0;}
  P(int a,int b,int idx):a(a),b(b),idx(idx){};
  bool operator < (const P &A) const{
    if(a!=A.a) return a<A.a;
    return b<A.b;
  }
};

char ch[N];
P r[N];
int n;

vector<int> Sort(){
    vector <int> R(n+1),res(n+1);
  
  for(int i=0;i<=n;i++) R[i]=ch[i];
  
  for(int i=1;i<=n;i*=2){
    for(int j=0;j<=n;j++)r[j]=P(R[j],(j+i<=n)? R[j+i]:0,j);
    sort(r,r+n+1);
    R[r[0].idx]=0;
    for(int j=1,C=0;j<=n;j++){
      if(r[j-1]<r[j]) C++;
      R[r[j].idx]=C;
    }
  }
  for(int i=0;i<=n;i++) res[R[i]]=i;
  return res;
}

int check(vector <int> &a,char *x){
  int L=0,M,R=n,m=strlen(x);
  while(L<R){
    M=(L+R)/2;
    if(strncmp(ch+a[M],x,m)<0)L=M+1;
    else R=M;
  }
  return strncmp(ch+a[L],x,m)==0;
}

int main(){
  scanf("%s",ch);
  n=strlen(ch);
  int q;
  cin>>q;
  vector <int> Rank=Sort();
  char a[1001];

  while(q--){
    scanf("%s",a);
    printf("%d\n",check(Rank,a));
  }
  return 0;
}

Measured memory_bytes: 22176
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	
	static class State implements Comparable<State>{
		int num, fish;
		State(int num, int fish){
			this.num=num;
			this.fish=fish;
		}
		public boolean equals(Object s) {
			return this.num==((State)s).num;
		}
		public int compareTo(State s) {
			if(this.fish==s.fish) return this.num-s.num;
			else return s.fish-this.fish;
		}
	}
	
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			int n=sc.nextInt();
			int q=sc.nextInt();
			int[] a=new int[n+1];
			PriorityQueue<State> pq=new PriorityQueue<>();
			while(q-->0) {
				int b=sc.nextInt();
				int c=sc.nextInt();
				a[b]+=c;
				pq.add(new State(b, a[b]));
				while(!pq.isEmpty()) {
					State top=pq.element();
					if(top.fish==a[top.num]) {
						System.out.println(top.num+" "+top.fish);
						break;
					}
					pq.poll();
				}
			}

		}

	}
}


Measured memory_bytes: 110516
#include <iostream>
using namespace std;
int main(void){
    int H, W;
    char X;
    cin >> H >> W;
    for(int i=0;i<W+2;i++){
        cout << "#";
    }
    cout << endl;
    for(int i=0;i<H;i++){
        cout << "#";
        for(int i=0;i<W;i++){
            cin >> X;
            cout << X; 
        }
        cout << "#" << endl;
    }
     for(int i=0;i<W+2;i++){
        cout << "#";
    }
}

Measured memory_bytes: 3644
W,a,b = map(int, input().split())
a1 = a
a2 = a+W
b1 = b
b2 = b+W
if b1 <= a <= b2 or b1 <= a2 <= b2:
  print(0)
else:
  if a2 < b1:
    print(b1 - a2)
  else:
    print(a1 - b2)


Measured memory_bytes: 38384
import re
A = list()
B = list()
stack = 0
N,H,W = map(int,input().split())

for i in range(N):
  a,b = map(int,input().split())
  A.append(a)
  B.append(b)

for j in range(N):
  #print(A[j],B[j])
  if A[j] >= H and B[j] >= W:
    stack = stack + 1
    #print("stack!")
#print(N,H,W)
print(stack)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    string S,T;
    cin >> S >> T;
    cout << T << S << endl;
}



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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int n,count=0,temp;
	cin>>n;
	for (int i = 0; i < n; ++i)
	{
		cin>>temp;
		if((i+1)%2==1 && temp%2==1)
			count++;
	}
	cout<<count<<endl;

	return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
#include <numeric>
#include <sstream>
#include <queue>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()
#define print(s) cout << (s) << endl

void solve105(int H, int W) {
    vector<vector<int>> visited(H, vector<int>(W,0));
    vector<vector<char>> floor(H, vector<char>(W,0));
    string s;
    REP(i,H) {
        cin >> s;
        REP(j,W) {
            floor[i][j] = s[j];
        }
    }
    int x = 0; int y = 0;
    while (floor[y][x] != '.') {
        if (visited[y][x]) {
            cout << "LOOP" << endl;
            return;
        }
        visited[y][x] = 1;
        if (floor[y][x] == '>') {
            x++;
        }else if (floor[y][x] == '<') {
            x--;
        }else if (floor[y][x] == 'v') {
            y++;
        }else {
            y--;
        }
    }
    cout << x << " " << y << endl;
}

int main() {
    int H, W;
    while (cin >> H >> W, H + W) {
        solve105(H, W);
    }
}

Measured memory_bytes: 3068
#include<iostream>
#include<cstring>
#include<algorithm>
#include<math.h>
#include<queue>
#include<cstdio> 
using namespace std;
int A[10],B[11],C[11];
bool dfs(int a,int b,int c){
	if(a==10){
		return true;
	}
	bool flag=false;
	if(A[a]>B[b-1]){
		B[b]=A[a];
		flag |=dfs(a+1,b+1,c);
	}	
	if(A[a]>C[c-1]){
		C[c]=A[a];
		flag |=dfs(a+1,b,c+1);
	}
	return flag;
}
int main(){
	int n;
	scanf("%d",&n);
	while(n--){
		for(int i=0;i<10;i++){
			scanf("%d",&A[i]);
		}
		if(dfs(0,1,1)){
				printf("YES\n");
			}
			else{
				printf("NO\n");
			}
	}
	return 0;
}


Measured memory_bytes: 3052
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
int SIZE(string s){return (int)s.size();}
const long long INF = 1LL << 60;

int main(){
    cout << fixed << setprecision(20);
    string s; cin >> s;
    if(s[0] != 'A'){
        cout << "WA" << endl;
        return 0;
    }
    int si = SIZE(s);
    int cnt = 0;
    rng(i,1,si){
        if(isupper(s[i])){
            if(!(i != 1 && i != si-1 && s[i] == 'C')){
                cout << "WA" << endl;
                return 0;
            }
            cnt++;
        }
    }
    if(cnt == 1) cout << "AC" << endl;
    else cout << "WA" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{

    char x;
    cin >> x;
    if(x == 'a')
    {
        cout << " vowel " ;
    }
    else if(x == 'e')
    {
        cout << " vowel " ;
    }
    else if(x == 'i')
    {
        cout << " vowel " ;
    }
    else if(x == 'o')
    {
        cout << " vowel " ;
    }
    else if(x == 'u')
    {
        cout << " vowel " ;
    }
    else
    {
        cout << " consonant " ;
    }
    return 0;
}


Measured memory_bytes: 256
#設定
import sys
input = sys.stdin.buffer.readline

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, C = getlist()
	left1sum = [0]
	right1sum = [0]
	left2sum = [0]
	right2sum = [0]
	X = []
	V = []
	for i in range(N):
		x, v = getlist()
		X.append(x)
		V.append(v)
	for i in range(N):
		left1sum.append(left1sum[-1] + V[-1 - i])
		left2sum.append(left2sum[-1] + V[-1 - i])
		right1sum.append(right1sum[-1] + V[i])
		right2sum.append(right2sum[-1] + V[i])
	# print(right1sum)
	# print(right2sum)
	# print(left1sum)
	# print(left2sum)
	for i in range(N):
		right1sum[i + 1] -= X[i]
		right2sum[i + 1] -= 2 * X[i]
		left1sum[i + 1] -= C - X[-1 - i]
		left2sum[i + 1] -= 2 * (C - X[-1 - i])

	for i in range(N):
		right1sum[i + 1] = max(right1sum[i + 1], right1sum[i])
		right2sum[i + 1] = max(right2sum[i + 1], right2sum[i])
		left1sum[i + 1] = max(left1sum[i + 1], left1sum[i])
		left2sum[i + 1] = max(left2sum[i + 1], left2sum[i])
	# print(right1sum)
	# print(right2sum)
	# print(left1sum)
	# print(left2sum)
	ans = 0
	for i in range(N + 1):
		ans = max(ans, right1sum[i] + left2sum[N - i])
		ans = max(ans, right2sum[i] + left1sum[N - i])
	print(ans)

if __name__ == '__main__':
	main()

Measured memory_bytes: 30084
#include<bits/stdc++.h>
using namespace std;
#define N 110
#define LL long long
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define MP make_pair
int n,c,d;

int a[2][N];
int s1[N],s2[N];
int main(){
	//jfreopen("in.txt","r",stdin);
	cin>>n;

	for(int i=1;i<=n;++i){
		scanf("%d",&a[0][i]);
		s1[i]+=s1[i-1]+a[0][i];
	}
	for(int i=1;i<=n;++i){
		scanf("%d",&a[1][i]);

	}
	for(int i=n;i>=1;--i){
		s2[i]+=s2[i+1]+a[1][i];
	}
	int ans=0;
	for(int i=1;i<=100;++i){
		ans=max(ans,s1[i]+s2[i]);
	}
	cout<<ans<<endl;


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vec;
typedef vector<vec> mat;

int V,E,K;
const int INF = (1<<29);
mat G;

mat g[30];
mat u[30];

int add(int a,int b){
  if(a==-INF||b==-INF)return -INF;
  return min(a+b,INF);
}

pair<mat,mat> merge(mat A,mat B, bool flag=false){
  mat X( V, vec(V, -INF) );
  mat Y( V, vec(V, -INF) );
  
  for(int from=0;from<V;from++){
    for(int to=0;to<V;to++){
      for(int ex=0;ex<V;ex++){
        int cost=add(A[from][ex],B[ex][to]);
        if(X[from][to]<cost){
          X[from][to]=cost;
          Y[from][to]=ex;
        }
      }
    }
  }
  return make_pair(X,Y);
}


int calc(int m,int &si,int &ti){
  mat t;
  for(int i=0;i<30;i++){
    if(m>>i&1){
      if(t.empty()){
        t=g[i];
      }else{
        t=merge(t,g[i]).first;
      }
    }
  }
  
  int res=-INF;
  for(int i=0;i<V;i++){
    for(int j=0;j<V;j++){
      if(res<t[i][j]){
        si=i;
        ti=j;
        res=t[i][j];
      }
    }
  }
  return res;
}

void Dfs(vec& s,int from,int to,int len){
  if(len<=1)return;
  if(len==(len&-len)){

    for(int i=0;i<30;i++){
      if(len>>i&1){
        int ex=u[i][from][to];
        Dfs(s,from,ex,len/2);
        s.push_back(ex);
        Dfs(s,ex,to,len/2);
        return;
      }
    }
  }
  
  mat t;
  
  int ex=-1;
  int sub=-1;
  
  for(int i=0;i<30;i++){
    if(~len>>i&1)continue;
    if(t.empty()){
      t=g[i];
      continue;
    }
    pair<mat,mat> tmp=merge(t, g[i]);
    t=tmp.first;
    ex=tmp.second[from][to];
    sub=(1<<i);
  }

  Dfs(s,from,ex,len-sub);
  s.push_back(ex);
  Dfs(s,ex,to,sub);
}

int main(){
  cin>>V>>E>>K;
  G=mat( V, vec(V, -INF) );
  g[0]=u[0]=G;
  for(int i=0;i<V;i++)g[0][i][i]=0;
  for(int i=0;i<E;i++){
    int a,b,c;
    cin>>a>>b>>c;
    G[a][b]=max(G[a][b],c);
    if(g[0][a][b]<c){
      g[0][a][b]=c;
      u[0][a][b]=b;
    }
  }
  
  for(int i=1;i<30;i++){
    pair<mat,mat> temp=merge(g[i-1],g[i-1]);
    g[i]=temp.first;
    u[i]=temp.second;
  }
  int left=1,right=K+1,mid,si,ti;
  while( left < right ){
    mid=(left+right)/2;
    if( calc(mid,si,ti) >= K ){
      right=mid;
    }else{
      left=mid+1;
    }
  }
  
  for(int i=0;i<V;i++)g[0][i][i]=-INF;
  for(int i=1;i<30;i++){
    pair<mat,mat> temp=merge(g[i-1],g[i-1]);
    g[i]=temp.first;
    u[i]=temp.second;
  }
  calc(left,si,ti);
  
  if(left==K+1){
    cout<<-1<<endl;
  }else{
    cout<<left<<endl;
    if(left<=100){
      vec tab;
      tab.push_back(si);
      Dfs(tab,si,ti,left);
      tab.push_back(ti);

      int sum=0;
      for(int i=0;i<(int)tab.size();i++){

        
        if(i>0){
          int cost=G[ tab[i-1] ][ tab[i] ];
          if(cost == -INF ){
            assert(0);
          }else{
            sum=add(sum,cost);
          }
        }
        
        if(i)cout<<' ';
        cout<<tab[i];
      }
      cout<<endl;
      //cout<<sum<<' '<<calc(left,si,ti)<<endl;
      assert( sum == calc(left,si,ti) );
    }
  }
  return 0;
}

  



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

int main()
{
	int n,i;
	long long int min, max, sum;
	int a[10000];

	cin >> n;

	i = 0;
	while (i < n) {
		cin >> a[i];
		i++;
	}

	i = 0;
	sum = 0;
	min = 1000000;
	max = -1000000;
	while (i < n) {
		if (a[i] < min) {
			min = a[i];
		}
		if (max < a[i]) {
			max = a[i];
		}
		sum += a[i];
		i++;
	}

	cout << min << " " << max << " " << sum << endl;

    return 0;
}




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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

const ll INF = 1e18;
const ld EPS = 1e-8;

int main(){
  ll N, x;
  cin >> N >> x;
  vector<ll> a(N);
  REP(i,N) cin >> a[i];

  vector<vector<ll>> b(N, vector<ll> (N, INF));
  REP(i,N)REP(j,N) {
    b[i][j] = min(b[i][(j - 1 + N) % N], a[(i - j + N) % N]);
  }
  ll res = INF;
  REP(i,N) {
    ll tmp = i * x;
    REP(j,N) tmp += b[j][i];
    res = min(res, tmp);
  }
  cout << res << endl;
  return 0;
}



Measured memory_bytes: 31616
monster_num,k = map(int,input().split(" "))
hp = list(map(int,input().split(" ")))
hp = sorted(hp, reverse = True)

total = 0
for i in hp:
    total += i
    
s = 0
for i in range(k):
    if s <= len(hp) - 1:
        total -= hp[s]
        s += 1

print(total)
    

Measured memory_bytes: 26024
Q = int(input())
def f(a, b, s, i):
    if i == b or i<= 0 or i>s+1:
        return 0
    if s<a:#?
        if i<b:
            return (s-i+1)*i
        else:
            return (s-i+2)*i
    elif s-a<b-1:
        if i<=s-a:
            return i*(s-i+1)
        elif i<b:
            return i*(s-i)
        else:
            return i*(s-i+1)
    else:
        if i<b:
            return i*(s-i+1)
        elif i<=s-a+1:
            return i*(s-i+2)
        else:
            return i*(s-i+1)  
def C(a, b, x):
    if x >= a:
        x+=1
    #print((f(a, b, x, x//2), f(a, b, x, x//2-1), f(a, b, x, x//2+1), f(a, b, x, x//2-2), f(a, b, x, x//2+2)))
    if max(f(a, b, x, x//2), f(a, b, x, x//2-1), f(a, b, x, x//2+1), f(a, b, x, x//2-2), f(a, b, x, x//2+2), f(a, b, x, x//2-3), f(a, b, x, x//2+3))<a*b:
        return True
    return False
for _ in range(Q):
    a, b = map(int, input().split())
    if a<b:a, b = b, a
    ok = b-1
    ng = 10**20
    while ng-ok>1:
        mid = (ok+ng)//2
        if C(a, b, mid):ok = mid
        else:ng = mid
    print(ok)


    

Measured memory_bytes: 53100
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define  rep(i,a,b) for(i=a;i<b;i++)
#define ll long long int
#define ld long double
using namespace std;
int main()
{
IOS;
ld n;
cin>>n;
ll b=(ll)(n);
if(b%2==0)
cout<<setprecision(10)<<fixed<<1.0/2.0;
else
{
  ll a=(ll)(n-1);
  cout<<setprecision(10)<<fixed<<(1-(((n-1)/2)/n));
}
return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    string s;

    int ans = 1000;
    cin >> s;
    rep(i, s.size() - 2)
    {
        ans = min(ans, abs(753 - stoi(s.substr(i, 3))));
    }
    OP(ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS                      \
   ios_base::sync_with_stdio(0); \
   cin.tie(0);
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x, y) memset(x, y, sizeof(x))
#define pb push_back
#define mk make_pair
#define pi pair<int, int>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = a; i >= (b); --i)
using namespace std;
int dt[][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}, {0, 0}};
//typedef pair<int, int> P;
//priority_queue<int, vector<int>, greater<int> > q;

const int N = 2e5 + 5;
vector<int> e[N];
int fa[N];

void bfs()
{
   queue<int> que;
   que.push(1);
   fa[1] = 1;
   while (!que.empty()) {
      int u = que.front();
      que.pop();
      for (auto v : e[u])
      {
         if (fa[v] == 0)
         {
            que.push(v);
            fa[v] = u;
         }
      }
   }
}
int main()
{
   IOS;
   int n, m;
   cin >> n >> m;
   rep(i, 0, m-1)
   {
      int u, v;
      cin >> u >> v;
      e[u].push_back(v);
      e[v].push_back(u);
   }
   bfs();
   rep(i, 2, n)
   {
      if (fa[i] == 0)
      {
         cout << "No";
         return 0;
      }
   }
   cout << "Yes" << endl;
   rep(i, 2, n)
   {
      cout << fa[i] << endl;
   }
}


Measured memory_bytes: 12872
N = int(input())
S = [int(i) for i in input()]
bef = [set() for _ in range(10)]
aft = [set() for _ in range(10)]

beflis = [ set([S[0]]) ]
aflis = [ set([S[-1]]) ]
for i in range(1,N):
    beflis.append(beflis[-1] | {S[i]})
    aflis.append(aflis[-1] | {S[-1-i]})

for i in range(1,N-1):
    bef[S[i]] = bef[S[i]] | beflis[i-1]
    aft[S[i]] = aft[S[i]] | aflis[N-i-2]

ans =set()
for i in range(1,N-1):
    s = S[i]
    for j in list(beflis[i-1]):
        for k in list(aflis[N-i-2]):
            ans.add(100*j +10*s+k)
print(len(ans))

Measured memory_bytes: 48064
import itertools
N, A, B, C = map(int, raw_input().split())
banboos = [int(raw_input()) for _ in range(N)]

INF = 10**9
#saw banboos from 0 to k-1 and the length is a, b, c
#see the k'th banboo and return the smallest cost
def dfs(k, a, b, c):
  if k == N:
    return abs(a-A)+abs(b-B)+abs(c-C) - 30 if min(a, b, c) > 0 else INF
  ret0 = dfs(k+1, a, b, c)
  ret1 = dfs(k+1, a+banboos[k], b, c)+10
  ret2 = dfs(k+1, a, b+banboos[k],  c)+10
  ret3 = dfs(k+1, a, b, c+banboos[k])+10
  return min(ret0, ret1, ret2, ret3)
print dfs(0, 0, 0, 0)



Measured memory_bytes: 2692
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


void solve(int n){
    string s[n];
    rep(i,n)cin>>s[i];
    vector<int> v[26];
    vector<int> cnt(26);
    rep(i,n-1){
        int m=min(s[i].size(),s[i+1].size());
        bool used=0;
        rep(j,m){
            if(s[i][j]!=s[i+1][j]){
                v[s[i][j]-'a'].push_back(s[i+1][j]-'a');
                cnt[s[i+1][j]-'a']++;
                used=true;
                break;
            }
        }
        if(!used&&s[i].size()>m){
            cout<<"no"<<endl;
            return;
        }
    }
    queue<int> q;
    int ans=0;
    rep(i,26){
        if(!cnt[i])++ans,q.push(i);
    }
    while(q.size()){
        int x=q.front();q.pop();
        for(auto to : v[x]){
            if(--cnt[to]==0)++ans,q.push(to);
        }
    }
    if(ans==26)cout<<"yes"<<endl;
    else cout<<"no"<<endl;
}
int main(){
    int n;
    while(cin>>n,n)solve(n);
    return 0;
}


Measured memory_bytes: 3108
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
using ll=long long int;

int main() {
    int a[5];
    for (auto &e: a) cin >> e;
    int k;
    cin >> k;

    if (a[4] - a[0] <= k) {
        cout << "Yay!" << endl;
    } else {
        cout << ":(" << endl;
    }

    return 0;
}


Measured memory_bytes: 256