akhauriyash/Code-Regression huggingface dataset:
program main
Implicit None
	integer(8)::n,m,i,u,j
	integer(8),allocatable::a(:),b(:),c(:),t(:)
	
	read*,n,m
	allocate(a(n),b(m),c(m),t(n))
	
	read*,a
	call h1(a,n)
	
	do i =1,m
		read*,b(i),c(i)
	enddo
	
	call h2(c,b,m)
	u = m
	
	do i = 1,n
		if(a(i) < c(u))then
			a(i) = c(u)
			b(u) = b(u)-1
			if(b(u) == 0) u = u-1
			if(u == 0)exit
		endif
	enddo
	
	print"(i0)",sum(a)
end program main
 
subroutine schint(a,n,x,p)
implicit None
	integer(8)::n,s,e,x,p,t,i
	integer(8)::a(n)
	
	s =1;e =n
	do
		if(e-s < 3)then
			do i = s,e
				if(a(i) >= x)then
				p = i-1
				return
				endif
			enddo
		endif
		
		t = (s+e)/2
		if(a(t) > x)then
			e = t
			else
			s = t
		endif
	enddo
end subroutine schint

subroutine h2(a,b,n)
implicit None
	integer(8)::a(n),b(n),x,y
	integer(8)::n,i,ie,i0,i1,i2
	
	do i = n/2,1,-1
		x = a(i);y = b(i);ie = n + 1; i0 = i; i1 = i0 * 2
		do while(i1 < ie)
			i2 = i1 + 1
			if(i2 < ie .and. a(i1) < a(i2)) i1 = i2
			if(a(i1) > x)then
				a(i0) = a(i1);a(i1) = x
				b(i0) = b(i1);b(i1) = y
				else
				exit
			endif
			i0 = i1;i1 = i0 *2
		enddo
	enddo
	do ie = n,2,-1
		x = a(ie);y = b(ie)
		a(ie) = a(1);b(ie) = b(1)
		a(1) = x;b(1) = y
		i0 =1;i1 =2
		do while(i1 <ie)
			i2 = i1 +1
			if(i2 < ie .and. a(i1) < a(i2)) i1 = i2
			if(a(i1) > x)then
				a(i0) = a(i1);a(i1) = x
				b(i0) = b(i1);b(i1) = y
				else
				exit
			endif
			i0 = i1;i1 = i0 *2
		enddo
	enddo
end subroutine h2

 
subroutine h1(a,n)
implicit None
	integer(8)::a(n),x
	integer(8)::n,i,ie,i0,i1,i2
	
	do i = n/2,1,-1
		x = a(i);ie = n + 1; i0 = i; i1 = i0 * 2
		do while(i1 < ie)
			i2 = i1 + 1
			if(i2 < ie .and. a(i1) < a(i2)) i1 = i2
			if(a(i1) > x)then
				a(i0) = a(i1);a(i1) = x
				else
				exit
			endif
			i0 = i1;i1 = i0 *2
		enddo
	enddo
	do ie = n,2,-1
		x = a(ie)
		a(ie) = a(1)
		a(1) = x
		i0 =1;i1 =2
		do while(i1 <ie)
			i2 = i1 +1
			if(i2 < ie .and. a(i1) < a(i2)) i1 = i2
			if(a(i1) > x)then
				a(i0) = a(i1);a(i1) = x
				else
				exit
			endif
			i0 = i1;i1 = i0 *2
		enddo
	enddo
end subroutine h1


Measured memory_bytes: 3200
void main() {
	auto O = rs, E = rs;
	foreach(i; 0..O.length) {
		O[i].write;
		if(!(i > E.length-1)) E[i].write;
	}
	writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 380
s = str(input())
k = int(input())

for i in range(min(len(s),k)):
#「Sの長さ」と「K」の少ない方の回数分ループを回す
    if s[i] != '1':#Kまで１が続かなかったら
        print(s[i])#最初に出てきた１以外の数が出力される
        exit()#ループを抜けて終了

print('1')#Kまで１が続けば、１が出力される


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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;


int main(){
  
  int  n , a , b ;
  cin >> n >> a >> b;
  string s; 
  cin >> s ;
  int sum=0;
  int abroad=0;
  rep(i,n){
    if(sum>=a+b){
      cout<<"No"<<endl;
      continue;
    }
    if(s[i]=='a'){
      if(sum<a+b){
        cout<<"Yes"<<endl;
        sum++;
      }
      else cout<<"No"<<endl;
    }
    if(s[i]=='b'){
      if(sum<a+b && abroad<b){
        cout<<"Yes"<<endl;
        sum++;
        abroad++;
      }
      else cout<<"No"<<endl;
    }
    if(s[i]=='c') cout<<"No"<<endl;
  }
}
  



Measured memory_bytes: 896
// -*- mode:c++; coding:utf-8; c-basic-offset:2; -*-
// ALDS1_6-C: Quick Sort

#include <algorithm>
#include <cstring>
#include <iostream>

using uint = unsigned int;

// Card
struct Card {
  char suit;
  uint rank;
  uint index; // for stable check
};

std::ostream& operator<<(std::ostream& os, const Card& card)
{
  return os << card.suit << " " << card.rank;
}

std::istream& operator>>(std::istream& is, Card& card)
{
  return is >> card.suit >> card.rank;
}

static void print_cards(const Card cards[], const uint n)
{
  for (auto i = 0u; i < n; ++i) {
    std::cout << cards[i] << std::endl;
  }
}

static bool is_stable(const Card cards[], const uint n)
{
  for (auto i = 0u; i< n-1; ++i) {
    if (cards[i].rank == cards[i+1].rank &&
        cards[i].index > cards[i+1].index) {
      return false;
    }
  }
  return true;
}

// quick_sort
static uint partition(Card cards[], uint begin, uint end) {
  auto last = end-1;
  auto lt = begin;
  for (auto i = begin; i < last; ++i) {
    if (cards[i].rank <= cards[last].rank) {
      std::swap(cards[lt], cards[i]);
      ++lt;
    }
  }
  std::swap(cards[lt], cards[last]);
  return lt;
}

void quick_sort(Card cards[], uint begin, uint end) {
  if (end - begin > 1) {
    auto middle = partition(cards, begin, end);
    quick_sort(cards, begin, middle);
    quick_sort(cards, middle, end);
  }
}

// main
int main(void) {
  uint n;
  std::cin >> n;
  Card cards[n];
  for (uint i = 0; i < n; ++i) {
    cards[i].index = i;
    std::cin >> cards[i];
  }

  quick_sort(cards, 0u, n);

  if (is_stable(cards, n)) {
    std::cout << "Stable" << std::endl;
  } else {
    std::cout << "Not stable" << std::endl;
  }
  print_cards(cards, n);

  return 0;
}

// eof

Measured memory_bytes: 4252
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
typedef pair<int, int> P;
int dp[3010][3010];


signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, T;
    cin >> N >> T;
    P p[3010];
    rep(i, N) {
        cin >> p[i].first >> p[i].second;
    }
    sort(p, p + N);
    rep(i, N) {
        REP(j, 0, T) dp[i + 1][j] = dp[i][j];
        REP(j, 0, T - 1) {
            int c = min(T, j + p[i].first);
            dp[i + 1][c] = max(dp[i + 1][c], dp[i][j] + p[i].second);
        }
    }
    cout << dp[N][T] << endl;


    return 0;
}


Measured memory_bytes: 74252
#include <iostream>

using namespace std;

int main()
{
    int A,B;
    cin>>A>>B;
    if(A==1)
    {
        if(B==1)
            cout<<"Draw";
        else cout<<"Alice";
    }
    else if(B==1)
    {
        if(A==1)
            cout<<"Draw";
        else cout<<"Bob";
    }
    else {
        if(A>B)
            cout<<"Alice";
        else if(B>A)
            cout<<"Bob";
        else cout<<"Draw";
    }
    return 0;
}


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

#define rep(i, x, y) for (register int i = (x); i <= (y); ++i)
#define Rep(i, x, y) for (register int i = (x); i >= (y); --i)
#define int long long

const int _ = 1 << 21;
struct I {
	char fin[_], *p1 = fin, *p2 = fin;
	inline char gc() {
		return (p1 == p2) && (p2 = (p1 = fin) + fread(fin, 1, _, stdin), p1 == p2) ? EOF : *p1++;
	}
	inline I& operator>>(int& x) {
		bool sign = 1;
		char c = 0;
		while (c < 48) ((c = gc()) == 45) && (sign = 0);
		x = (c & 15);
		while ((c = gc()) > 47) x = (x << 1) + (x << 3) + (c & 15);
		x = sign ? x : -x;
		return *this;
	}
	inline I& operator>>(double& x) {
		bool sign = 1;
		char c = 0;
		while (c < 48) ((c = gc()) == 45) && (sign = 0);
		x = (c - 48);
		while ((c = gc()) > 47) x = x * 10 + (c - 48);
		if (c == '.') {
			double d = 1.0;
			while ((c = gc()) > 47) d = d * 0.1, x = x + (d * (c - 48));
		}
		x = sign ? x : -x;
		return *this;
	}
	inline I& operator>>(char& x) {
		do
			x = gc();
		while (isspace(x));
		return *this;
	}
	inline I& operator>>(string& s) {
		s = "";
		char c = gc();
		while (isspace(c)) c = gc();
		while (!isspace(c) && c != EOF) s += c, c = gc();
		return *this;
	}
} in;
struct O {
	char st[100], fout[_];
	signed stk = 0, top = 0;
	inline void flush() {
		fwrite(fout, 1, top, stdout), fflush(stdout), top = 0;
	}
	inline O& operator<<(int x) {
		if (top > (1 << 20)) flush();
		if (x < 0) fout[top++] = 45, x = -x;
		do
			st[++stk] = x % 10 ^ 48, x /= 10;
		while (x);
		while (stk) fout[top++] = st[stk--];
		return *this;
	}
	inline O& operator<<(char x) {
		fout[top++] = x;
		return *this;
	}
	inline O& operator<<(string s) {
		if (top > (1 << 20)) flush();
		for (char x : s) fout[top++] = x;
		return *this;
	}
} out;
#define pb emplace_back
#define fir first
#define sec second

template < class T > inline void cmax(T & x , const T & y) {
	(x < y) && (x = y) ;
}
template < class T > inline void cmin(T & x , const T & y) {
	(x > y) && (x = y) ;
}
int n , k ;
const int N = 1e5 + 10 ;
int a[N] ;
int fac[N] ;
const int mod = 1e9 + 7 ;
int ans1 = 0 , ans2 = 0 ;
int qpow(int x , int y) {
	int ans = 1 ;
	for( ; y ; y >>= 1 , x = x * x % mod) 
		if(y & 1) ans = ans * x % mod ;
	return ans ;
}
int inv(int x) {
	return qpow(x , mod - 2) ;
}
int C(int n , int m) {
	return fac[n] * (inv(fac[n - m]) * inv(fac[m]) % mod) % mod ;
}
signed main() {
#ifdef _WIN64
	freopen("testdata.in" , "r" , stdin) ;
#endif
	in >> n >> k ;
	rep(i , 1 , n) in >> a[i] ;
	sort(a + 1 , a + n + 1) ;
	fac[0] = 1 ;
	rep(i , 1 , n) fac[i] = fac[i - 1] * i % mod ;
	rep(i , 1 , n - k + 1) {
		ans1 = ((ans1 + C(n - i , k - 1) * a[i]) % mod + mod) % mod ;
	}
	reverse(a + 1 , a + n + 1) ;
	rep(i , 1 , n - k + 1) {
		ans2 = ((ans2 + C(n - i , k - 1) * a[i]) % mod + mod) % mod ;
	}
	out << (ans2 - ans1 + mod) % mod << '\n' ;
	return out.flush(), 0;
}

Measured memory_bytes: 4352
#include <stdio.h>
#include <stdlib.h>

//qsort
int asc(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}
int desc(const void *a, const void *b) {
  return *(int *)b - *(int *)a;
}

int main(void){
    int n;
    scanf("%d",&n);
    double sum=0;
    int list[n];
    for(int i=0;i<n;i++){
        scanf("%d",&list[i]);
    }
    qsort(list, n, sizeof(int), asc);
    sum=list[0];
    for(int i=1;i<n;i++){
        sum=(sum+list[i])/2;
    }
    printf("%f\n",sum);
    return 0;
}


Measured memory_bytes: 128
n,m=map(int,input().split())
sc = [tuple(map(int,input().split())) for _ in range(m)]

for i in range(10**n):
    if len(str(i))!=n:
        continue
    if all([str(i)[s-1] == str(c) for s,c in sc]):
        print(i)
        exit()
print(-1)


Measured memory_bytes: 3060
N, M = [int(x) for x in input().split()]

P = []
C = []

for i in range(N):
    P += [[int(x) for x in input().split()]]
    
for i in range(M):
    C += [[int(x) for x in input().split()]]

for i in range(N):
    d_min = abs(P[i][0] - C[0][0]) + abs(P[i][1] - C[0][1])
    c_min = 1
    for j in range(M):
        d = abs(P[i][0] - C[j][0]) + abs(P[i][1] - C[j][1])
        if d < d_min:
            d_min = d
            c_min = j+1
    print(c_min)

Measured memory_bytes: 3064
// TEMPLATE {{{
#include <bits/stdc++.h>
using namespace std;
#ifndef LOCAL
#define OJ 1
#else
#define OJ 0
#endif
 
#define endl '\n'
#define TIMESTAMP merr << "Execution time: " << (double)clock()/CLOCKS_PER_SEC << " s.\n"
class C_ {}; template <typename T> C_& operator <<(C_& __m, const T& __s) { if (!OJ) cerr << "\E[91m" << __s << "\E[0m"; return __m; }
C_ merr;
 
struct __s { __s() { if (OJ) { ios_base::Init i; cin.sync_with_stdio(0); cin.tie(0); } } ~__s(){ TIMESTAMP; } } __S;
/// END OF TEMPLATE }}}

#define size_t unsigned long long
#define double long double

std::random_device rd;
std::mt19937 mt(rd());

double brute(size_t n, size_t k, size_t iters = 100000000) {
    size_t wins = 0, loses = 0;
    std::uniform_int_distribution<int> distDice(1, (int)n);
    std::uniform_int_distribution<int> distCoin(0, 1);
    for (size_t tt = 0; tt < iters; tt++) {
        size_t x = distDice(mt);
        if (x >= k) {
            wins++;
            continue;
        }
        while (1 <= x && x < k) {
            bool coin = distCoin(mt);
            if (coin) {
                x *= 2;
            } else {
                x = 0;
            }
        }
        if (x >= k) {
            wins++;
        } else {
            loses++;
        }
    }
    return (double)wins*1.0/(double)(wins+loses);
}

double clever(size_t n, size_t k) {
    double ans = (n >= k) ? (double)(n-k+1)/(double)n : 0.0;
    double add = 0.0;
    for (size_t i = 1; i <= min(n, k-1); i++) {
        size_t cnt = 0;
        size_t x = i;
        while (x < k) {
            x *= 2;
            cnt++;
        }
        add += pow(0.5, cnt);
    }
    merr << "ans = " << ans << '\n';
    merr << "add = " << add << '\n';
    return ans + add/(double)n;
}

int main(void) {
    size_t n, k;
    cin >> n >> k;
    // cout << fixed << setprecision(10) << brute(n, k) << endl;
    cout << fixed << setprecision(10) << clever(n, k) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define ll int64_t
#define _GLIBCXX_DEBUG
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int main(){
  int n;
  cin >> n;
  vector<ll> a(n),l(n),f(n),e(n);
  vector<pair<ll,ll>> p(n);
  rep(i,n){
    cin >> a[i] >> l[i];
    f[i]=a[i]-l[i];
    e[i]=a[i]+l[i];
    p[i]=make_pair(e[i],f[i]);
  }
  sort (all(p));
  ll t=-1000000000000;
  int ans;
  rep(i,n){
    if(t<=p[i].second){
      t=p[i].first;
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 5120
# include <bits/stdc++.h>
# define INF 1e9
using namespace std;

int main(){

  int N;
  cin >> N;
  set<char> cset = {'M', 'A', 'R', 'C', 'H'};
  map<char, long int> m;
  for(int i=0; i<N; ++i){
    string s;
    cin >> s;
    if(cset.find(s[0]) != cset.end()){
      if(m.find(s[0]) == m.end()) m[s[0]] = 1;
      else m[s[0]]++;
    }
  }

  vector<long int> v;
  for(auto x: m){
    v.push_back(x.second);
    // cout << x.first << " " << x.second << endl;
  }
  long int ans = 0;
  for(int i=0; i<v.size(); ++i){
    for(int j=i+1; j<v.size(); ++j){
      for(int k=j+1; k<v.size(); ++k){
        ans += v[i] * v[j] * v[k];
      }
    }
  }
  cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    while(1)
    {
        ll n,x,i,j,k,sum=0;
        cin>>n>>x;
        if(n==0 && x==0) break;
        else
        {
            for(i=1; i<=n-2; i++)
            {
                for(j=i+1; j<=n-1; j++)
                {
                    for(k=j+1; k<=n; k++)
                    {
                        if(i+j+k==x) sum++;
                    }
                }
            }
            cout<<sum<<endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3100
import sys
input=sys.stdin.readline
q=int(input())

primes=[True]*100001
primes[0]=False
primes[1]=False

for i in range(2,100001):
    if primes[i]:
        for j in range(2,100000//i+1):primes[i*j]=False

sim2017=[0]*100001
for i in range(3,100001,2):
    sim2017[i]=sim2017[i-2]+(1 if primes[i] and primes[(i+1)//2] else 0)

for i in range(q):
    l,r=map(int,input().split())
    print(sim2017[r]-sim2017[l-2])
    



Measured memory_bytes: 11768
data = []
data.append(list(map(int, input().split())))
data.append(list(map(int, input().split())))
data.append(list(map(int, input().split())))

bingo = {
    data[0][0]: False, data[0][1]: False, data[0][2]: False,
    data[1][0]: False, data[1][1]: False, data[1][2]: False,
    data[2][0]: False, data[2][1]: False, data[2][2]: False,
}
n = int(input())

for i in range(0, n):
    number = int(input())
    if number in bingo:
        bingo[number] = True

result = False;
for i in range(0, 3):
    if bingo[data[i][0]] and bingo[data[i][1]] and bingo[data[i][2]]:
        result = True
    if bingo[data[0][i]] and bingo[data[1][i]] and bingo[data[2][i]]:
        result = True

if bingo[data[0][0]] and bingo[data[1][1]] and bingo[data[2][2]]:
    result = True

if bingo[data[0][2]] and bingo[data[1][1]] and bingo[data[2][0]]:
    result = True

if result:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::f64::consts::PI;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}


fn main() {
    let line: Vec<usize> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = line[0];
    let m = line[1];
    let mut a = Vec::with_capacity(n);
    for i in 0..(n-1)/2 {
        if i%2 == 0 {
            a.push(n-(i+1));
        } else {
            a.push(i+1);
        }
    }
    a.sort();
    a.reverse();
    for i in 0..m {
        println!("{} {}", i+1, i + 1 + a[i]);
    }
}


Measured memory_bytes: 2968
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long a,b,c,d;
	scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
	printf("%lld",max(max(a*c,a*d),max(b*c,b*d)));
	return 0;
 } 

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

// function implementing greedy approach
void smallest_string(string s , int m)
{
    int  n = s.size();   // size of the given string
    int a[n];        // declaring an array a 
    
    // for each i , a[i] contain number of operations to update s[i] to 'a' 
    for(int i = 0; i < n ; i++)
    {
        int distance = s[i]-'a';
        if(distance == 0)
        {
            a[i]=0;
        }
        else
        {
            a[i] = 26 - distance;
        }
    }
    
    for(int i = 0 ; i < n ; i++)
    {
        // if m >= ar[i] , then update s[i] to 'a' decrement k by a[i]
        if(m >= a[i])
        {
            s[i] = 'a';
            m = m - a[i];
        }
        
    }
    
    //cycle of 26 
    m = m % 26;
    
    // update last element of string with the s[i] + (k % 26) 
    s[n-1] = s[n-1] + m;
    
    cout<<s<<endl;
    
}

//driever code
int main()
{
    //string str = "bazzzx";
    //int m = 10;
    string str;
    cin>>str;
    int m;
    cin>>m;
    smallest_string(str , m);
    return 0;
}


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

int main() {
	int N, Y;
	cin >> N >> Y;
	for(int i = 0; i <= N; i++) {
		for(int j = 0; j <= N - i; j++) {
			int k = N - i - j;
			int mny = i*10000 + j*5000 + k*1000;
			if(mny == Y) {
				printf("%d %d %d\n", i, j, k);
				return 0;
			}
		}
	}
	puts("-1 -1 -1");
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
  char C;
  cin >> C;
  cout << (char)(C + 1) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define PI acos(-1)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}

int main(){
   int n;
   cin>>n;
   
   deque<int> a;

   rep(i,n){
      int x;
      cin>>x;
      if(i%2==0){
         a.push_front(x);
      }
      else{
         a.push_back(x);
      }
   }
   if(n%2==0){
      reverse(a.begin(),a.end());

   }
   rep(i,n){
      cout<<a[i]<<" ";
   }

   

   return 0;
}


Measured memory_bytes: 4440
#include <stdio.h>
#include <string.h>

int main(){
  char S[20];
  scanf("%s", S);
  int ans, c, i;
  ans = abs(100*(S[0]-'0')+10*(S[1]-'0')+(S[2]-'0')-753);
  for(i=1; i<strlen(S)-2; i++){
  c = abs(100*(S[i]-'0')+10*(S[i+1]-'0')+(S[i+2]-'0')-753);
    if(c<ans) ans=c;
  }
  printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
import numpy as np
H, W = map(int, input().split())

lst = [list(map(int, input().split())) for _ in range(H)]
dp = np.array(lst)


def check(i, j):
    if dp[i][j] % 2 == 0:
        return True
    else:
        return False

flag = True #True: 右向き探索、False: 左向き探索
h = 0 #縦
w = 0 #横
ans = [] #操作を残しておくリスト
count = 0 #操作の回数
for i in range(H*W): #最大回数試す
    # print (i-1, '(h, w) =', h, w)
    # print (dp)
    if check(h, w): #既に偶数
        if flag == True and w == W - 1:
            flag = not flag
            h += 1
        elif flag == False and w == 0:
            flag = not flag
            h += 1
        elif flag == True:
            w += 1
        elif flag == False:
            w -= 1
        continue
    else: #奇数の時、1つ次にずらす
        if i == (H*W-1): #最後の一回は奇数だとしても動かすところがない
        # if h == H - 1 and w == W - 1 and flag == True: #右下のマスで右に行け = 全探索終了
            continue
        else:
            count += 1
            if flag: #flag == True: 右向き探索
                if w == W - 1: #右向き探索で既に一番右の時
                    #下に移す
                    dp[h][w] -= 1
                    dp[h + 1][w] += 1
                    ans += [[h+1, w+1, h+2, w+1]]
                    flag = not flag #探索の向きを変える
                    h += 1 #下段に移る
                else: #右に移す場所がある時
                    dp[h][w] -= 1
                    dp[h][w + 1] += 1
                    ans += [[h+1, w+1, h+1, w+2]]
                    w += 1
            else: #左向き探索
                if w == 0: #左向き探索で既に一番左の時
                    #下に移す
                    dp[h][w] -= 1
                    dp[h+1][w] += 1
                    ans += [[h+1, w+1, h+2, w+1]]
                    flag = not flag
                    h += 1
                else: #左に移す場所がある時
                    dp[h][w] -= 1
                    dp[h][w - 1] += 1
                    ans += [[h+1, w+1, h+1, w]]
                    w -= 1

# print (count)
# print ('ans', np.array(ans))
# print ('dp', dp)

# 以下答えの出力部分
print (count) #操作回数の出力
for i in ans: #ansのリストを全走査
    print (i[0], i[1], i[2], i[3])
    # for j in i:
    #     print (j, end = ' ')
    # print ()



Measured memory_bytes: 41152
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
	int64_t a, b, k;	cin >> a >> b >> k;
	if((a+b) <= k) cout << 0 << " " << 0 << endl;
  	else{
    	if(a <= k) cout << 0 << " " << (a+b-k) << endl;
      	else cout << (a - k) << " " << b << endl;
    }
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B, C, K = MAP()

if K <= A:
    print(1 * K)
elif A < K <= A + B:
    print(A * 1)
elif A + B < K <= A + B + C:
    print(A * 1 + (-1) * (K - (A + B)))

Measured memory_bytes: 10048
package main

import "fmt"

func main() {
	var A, B int
	var r string
	fmt.Scan(&A, &B)
	if Max(A, B) > 8 {
		r = ":("
	} else {
		r = "Yay!"
	}
	fmt.Println(r)

}
func Max(a, b int) int {
	if b > a {
		return b
	}
	return a
}


Measured memory_bytes: 512
from functools import lru_cache
import sys

sys.setrecursionlimit(10**8)

K, X = map(int, input().split())

@lru_cache(maxsize=None)
def dp(k,x):
    if k*500 < x:
        result = 'No'
    else:
        result = 'Yes'
    return result
print(dp(K,X))



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

using namespace std;
typedef long long int64;
typedef pair<int,int> pii;
typedef pair<int64,int> pii32;
typedef pair<int64,int64> pii64;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

const int maxn = 1e5+10;
const int64 MO = 1e9+7;
const int64 IN = 1e9;

int n, k;

int main () {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> k;
	if (k == 1)
		return cout << 0 << "\n", 0;
	cout << n - k << "\n";
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		String q = scan.nextLine();
		String s = scan.nextLine();
		String ans = "";
		String data = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		for (int i = 0; i < s.length(); i++ ) {
			int index = data.indexOf(String.valueOf(s.charAt(i)));
			index += x;
			if(index > 25) {
				index -= 26;
			}
			ans += String.valueOf(data.charAt(index));
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 149444
#include<stdio.h>
int main()
{
    int n,a[3][3],b[11],c[3][3]={0},i,j,k,f=0;
    for(i=0;i<3;i++){
        for(j=0;j<3;j++){
            scanf("%d",&a[i][j]);
        }
    }
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&b[i]);
    }
    for(i=0;i<3;i++){
        for(j=0;j<3;j++){
            for(k=0;k<n;k++){
                if(b[k]==a[i][j]) c[i][j]=1;;
            }
        }
    }
    for(i=0;i<3;i++){
        if(c[i][0]==1 && c[i][1]==1 && c[i][2]==1) f++;
    }
    for(j=0;j<3;j++){
        if(c[0][j]==1 && c[1][j]==1 && c[2][j]==1) f++;
    }
    if(c[0][0]==1 && c[1][1]==1 && c[2][2]==1) f++;
    if(c[0][2]==1 && c[1][1]==1 && c[2][0]==1) f++;
    if(f==0){
        printf("No\n");
    }else{
        printf("Yes\n");
    }
    return 0;
}

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int N,K;
    Scd2(N,K);
    vi h(N);

    Rep(i,N){
        Scd(h[i]);
    }

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

    ll ans = 0;
    Rep(i,N-K){
        ans += h[i];
    }

    printf ("%lld\n", ans );

    return 0;
}



Measured memory_bytes: 1024
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    a,b,q = LI()
    s = IR(a)
    t = IR(b)
    X = IR(q)
    for x in X:
        i = bisect.bisect_right(s,x)-1
        j = bisect.bisect_right(t,x)-1
        res = float("inf")
        if i >= 0:
            si = s[i]
            if j >= 0:
                tj = t[j]
                res = x-min(si,tj)
            if j+1 < b:
                tj = t[j+1]
                m = min(abs(si-x),abs(tj-x))+abs(tj-si)
                if m < res:
                    res = m
        if i+1 < a:
            si = s[i+1]
            if j >= 0:
                tj = t[j]
                m = min(abs(si-x),abs(tj-x))+abs(si-tj)
                if m < res:
                    res = m
            if j+1 < b:
                tj = t[j+1]
                res = min(res,max(si,tj)-x)
        print(res)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 149724
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N; cin >> N;
	vector<int> A(N, 0);
	rep (i, N){
		cin >> A[i];
	} // end rep

	sort(ALL(A));
	set<int> cnt; cnt.clear();
	rep (i, N){
		cnt.insert(A[i]);
	} // end rep

	int k = (int)cnt.size();
	cout << (k % 2 != 0 ? k : k - 1) << endl;

	return 0;
}

Measured memory_bytes: 5376
#include<iostream>
#include<map>
#include<algorithm>

using namespace std;

int main(){
  int N; cin >> N;
  map<int,int>mp;
  
  for(auto p:mp){
    p.second = 0;}
  
  for(int i = 0; i < N; i++){ int a; cin >> a;
           if(mp[a] > 0){ mp[a] = 0;}
           else if( mp[a] == 0){ mp[a]++;}}
  int cnt = 0;
  for(auto p:mp){
    int s = p.first;
    if(mp[s] == 1){ cnt++;}}
  
  cout << cnt  << endl; return 0;}

Measured memory_bytes: 4864
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		// 入力は，次の形式で与えられる．
		//
		// N T H L
		// t1 h1
		// t2 h2
		// ...
		// tN hN
		// Nは2DRespectersの人数であり，1 <= N <= 100である． TとHはそれぞれ，
		// 10円玉ストレージと100円玉ストレージに最初に保存されている硬貨の枚数であり，0 <= T, H <= 100である．
		// Lは10円玉ストレージの保存可能枚数の上限であり，T <= L <= 100である． 1 <= i <= Nのとき，tiは，
		// 2DRespectersのメンバーiの10円玉の所持枚数を表し，hiは100円玉の所持枚数を表す．0 <= ti, hi <=
		// 100である．
		int N = sc.nextInt();
		int T = sc.nextInt();
		int H = sc.nextInt();
		int L = sc.nextInt();
		int[] ts = new int[N + 1];
		int[] hs = new int[N + 1];
		for (int i = 1; i <= N; i++) {
			ts[i] = sc.nextInt();
			hs[i] = sc.nextInt();
		}
		int rest = 0;
		int ans = 0;
		while (true) {
			for (int i = 1; i <= N; i++) {
				// ． 自販機には，硬貨を一度に一枚しか投入できず，投入された硬貨は，硬貨に対応する内部のストレージに保存される．
				// 自販機の残金表示は，始め0円になっており，硬貨を投入すると，投入した硬貨の金額分，自販機の残金が増加する．
				// 硬貨を投入した結果，自販機の残金が，90円以上になったならば，1本の缶ジュースがジュースの取り出し口に出てくると同時に，自販機の残金から90円を引いた額とちょうど同じ額の硬貨が釣銭として釣銭の取り出し口に出てくる．
				// このときの釣銭は，内部のストレージにある硬貨で払える範囲で，できるだけ多くの10円玉を用いて支払われる．
				// 釣銭が支払われた後，自販機の残金は0円に戻る．
				// // 硬貨の投入は，10円玉を持っている場合は必ず10円玉を投入し，
				// 10円玉を持っていない場合は100円玉を投入するものとする． メンバーiが硬貨を投入したとき，
				// 釣銭の取り出し口に釣銭が出てきた場合は，その全ての釣銭をメンバーiが受け取り，
				// 取り出し口に何もない状態にしてから，次のメンバーのターンに移る．
				if (ts[i] != 0) {
					ts[i]--;
					rest += 10;
					T++;
					if (T > L) {
						ans = i;
						break;
					}
				} else if (hs[i] != 0) {
					hs[i]--;
					rest += 100;
					H++;
				} else {
					ans = i;
					break;
				}
				if (rest >= 90) {
					rest -= 90;
					if (rest != 0 && T == 0 && H == 0) {
						ans = i;
						break;
					}
					if (T != 0) {
						int t = Math.min(rest / 10, T);
						T -= t;
						ts[i] += t;
						rest -= 10 * t;
					}
					if (H != 0) {
						int h = Math.min(rest / 100, H);
						H -= h;
						hs[i] += h;
						rest -= 10 * h;
						if (rest != 0) {
							ans = i;
							break;
						}
					}
				}
			}
			if (ans != 0)
				break;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#ifdef DEBUG
#include "_debug.cpp"
#include "callable.hpp/callable.hpp"
#endif
#define endl '\n'
using namespace std;
using ll = long long;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    set<int> s;
    for(int i = 0; i < n; i++) {
        int x;
        cin >> x;
        s.insert(x);
    }
    cout << s.size() << endl;
    return 0;
}


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

double factorial(double x){
	if(x<0){
		return 0;
	}
	double result=1;
	for(int i = 1; i<=x; i++){
		result*=i;
	}
	return result;
}

double combination(double x, double y){
	if(y>x){
		return 0;
	}
	double x_res = factorial(x);
	int y_res = factorial(y);
	double xy_res = factorial(x -y);
	//cout<<x_res<<" "<<y_res<<" "<<xy_res<<endl;
	double result = x_res/(y_res*xy_res);
	//cout<<result<<endl;
	return result;
}

int main(){
	int n, m;
	cin>>n>>m;
	
	double n_result = combination(n, 2);
	double m_result = combination(m,2);
	cout<<n_result+m_result<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int G[103][103];
int n,time,top;
int S[103];
char color[103];
int d[103];
int f[103];

void dfs(void);
void initialize(void);
int isEmpty(void);
int isFull(void);
void push(int);
void pop(void);
int next(int);
void visit(int);

int main()
{
  int i,u,k,j;
  int *U;

  /* 初期化 */
  for(i = 0;i < 103;i++){
    for(j = 0;j < 103;j++){
      G[i][j] = 0;
    }
  }

  /* 発見時刻の初期化 */
  for(i = 0;i < n;i++){
    d[i] = 0;
  }

  /* stackの初期化 */
  initialize();

  /* グラフG */
  scanf("%d",&n);

  for(i = 0;i < n;i++){
    scanf("%d",&u);
    scanf("%d",&k);

    U = (int *)malloc(sizeof(int) * k);
    if(U == NULL) exit(0);

    for(j = 0;j < k;j++){
      scanf("%d",&U[j]);
      G[u][U[j]] = 1;
    }
  }

  dfs();

  /* 出力 */
  for(i = 1;i <= n;i++){
    printf("%d %d %d\n",i,d[i],f[i]);
  }

  return 0;
 }

void dfs(void)
{
  int u;
  
  for(u = 1;u <= n;u++){
    color[u] = 'W'; // WHITE
  }
  time = 0;
  for(u = 1;u <=n; u++){
    if(color[u] == 'W') visit(u);
  }
}

void initialize(void)
{
  top = 0;
}

int isEmpty(void)
{
  /* top == 0なら1を返す */
  if(top == 0) return 1;
  return 0;
}

int isFull(void)
{
  /* top >= MAX(103) - 1なら1を返す */
  if(top >= 103 - 1) return 1;
  return 0;
}

void push(int x)
{
  if(isFull() == 1){
    fprintf(stderr,"オーバーフロー\n");
    exit(1);
  }

  top++;
  S[top] = x;
}

void pop(void)
{
  if(isEmpty() == 1){
    fprintf(stderr,"アンダーフロー\n");
    exit(1);
  }

  top--;
}

void visit(int r)
{
  int u,v;

  push(r); // stack S にrを入れる

  color[r] = 'G'; // GRAY 発見済み
  d[r] = ++time;

  while(isEmpty() != 1){
    u = S[top];
    v = next(u); // 次の探索場所を返す

    if(v != -1){
      if(color[v] == 'W'){
	push(v);
	color[v] = 'G';
	d[v] = ++time;
      }
    }

    else{
      pop();
      color[u] = 'B'; // BLACK 探索済み
      f[u] = ++time;
    }
  }
}

int next(int u)
{
  int i;

  for(i = 1; i <= n;i++){
    if(G[u][i] == 1){
      if(d[i] == 0) return i;
    }
  }

  return -1;
}

Measured memory_bytes: 640
n=int(input(""))
a=[]
ans=[1]
ain=input("").split(" ")
for i in range(n):
    a+=[int(ain[i])]
s=a[1]
for i in range(n-2):
    s^=a[i+2]
ans[0]=s
for i in range(n-1):
    s=s^a[i]
    s^=a[i+1]
    ans+=[s]
b=[]
for i in range(n):
    b+=[str(ans[i])]
print(" ".join(b))


    


Measured memory_bytes: 57456
using System;
using System.Collections.Generic;
using System.Linq;
using static AtCoder.Io;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var xy = ReadLongArray();
            var x = xy[0];
            var y = xy[1];

            var winner = Math.Abs(x - y) <= 1 ? "Brown" : "Alice";
            Console.WriteLine(winner);
        }
    }

    public static class Io
    {
        public static string ReadString() => Console.ReadLine();
        public static string[] ReadStringArray() => ReadString().Split(' ');
        public static int ReadInt() => int.Parse(ReadString());
        public static long ReadLong() => long.Parse(ReadString());
        public static int[] ReadIntArray() => ReadStringArray().ParseInt().ToArray();
        public static long[] ReadLongArray() => ReadStringArray().ParseLong().ToArray();
        public static IEnumerable<int> ParseInt(this IEnumerable<string> source) => source.Select(int.Parse);
        public static IEnumerable<long> ParseLong(this IEnumerable<string> source) => source.Select(long.Parse);
    }
}


Measured memory_bytes: 13396
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    int n;
    cin>>n;
    vector<pair<int,int>> pii;
    rep(i,n){
        int x;
        cin>>x;
        pii.push_back({x,i});
    }
    sort(pii.begin(),pii.end());
    set<int> si1;
    for(int i=0;i<=(n-2)/2;i++){
        si1.insert(pii[i].second);
    }
    vector<int> v(n,0);
    for(auto u : si1){
        v[u]=1;
    }
    int left=pii[n/2].first, right=pii[n/2-1].first;
    for(int i=0;i<n;i++){
        if(v[i]==1) cout<<left<<endl;
        else cout<<right<<endl;
    }
    return 0;
}

Measured memory_bytes: 9712
n,k=map(int,input().split())
d=[]
a=[]

c=[]

for i in range(k):

    d.append(input())

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

    for o in range(len(a)):

        c.append(a[o])

b=list(set(c))

print(n-len(b))


Measured memory_bytes: 9200
import java.util.Scanner;

	public class Main {

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			
			int n = sc.nextInt();
			int[] t = new int[n];
			int[] x = new int[n];
			int[] y = new int[n];
			
			for(int i=0;i<n;i++) {
				t[i]=sc.nextInt();
				x[i]=sc.nextInt();
				y[i]=sc.nextInt();
			}
			
			int dt = 0;
			int dL = 0;
			
			if(t[0]<(x[0]+y[0])) {
				System.out.println("No");
				return;
			}else if((t[0]-(x[0]+y[0]))%2==1) {
				System.out.println("No");
				return;
			}
			
			
			for(int i=0;i<n-1;i++) {
				dt = Math.abs(t[i]-t[i+1]);
				dL = Math.abs(x[i]-x[i+1]) + Math.abs(y[i]-y[i+1]);
				
				if(dt<dL) {
					System.out.println("No");
					return;
				}else if((dt-dL)%2==1) {
					System.out.println("No");
					return;
				}
				
			}
			
			System.out.println("Yes");			
		}
	}

Measured memory_bytes: 90972
#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;

int main() {
    ll N; cin >> N;
    for (ll i = 1; i < 3501; i++){
        for (ll j = 1; j < 3501; j++){
            ll ue = N * i * j;
            ll shita = 4 * i * j - N * i - N * j;
            if(shita < 1)continue;
            if(ue % shita == 0){
                ll k = ue / shita;
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }
    }

    return 0;
}

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

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
	cin.sync_with_stdio(false); cin.tie(0);
	cin.exceptions(cin.failbit);

	for (;;) {
		int n, m, s, g1, g2; cin >> n >> m >> s >> g1 >> g2;
		if (!n) break;

		vector<vector<ll>> dist(n + 1, vector<ll>(n + 1, 0x3f3f3f3f));

		rep(i, 1, n + 1) dist[i][i] = 0;

		rep(i, 0, m) {
			int b1, b2, c; cin >> b1 >> b2 >> c;
			dist[b1][b2] = c;
		}

		rep(i, 1, n + 1) rep(j, 1, n + 1) rep(k, 1, n + 1) {
			dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
		}

		ll ans = 0x3f3f3f3f;
		rep(i, 1, n + 1) {
			ans = min(ans, dist[s][i] + dist[i][g1] + dist[i][g2]);
		}
		cout << ans << endl;
	}
}



Measured memory_bytes: 3168
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.*;
import java.lang.Math.*;
public class Main {
    static HashMap<String,Integer> mem = new HashMap<>();
    static int[][] vertice;
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        int n = in.nextInt();
        int m = in.nextInt();
        int mx = (int)1e9;
        int ans = 0;
        vertice = new int[n+1][n+1];
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                vertice[i][j]=mx;
            }
            vertice[i][i]=0;
        }
        for(int i=0;i<m;i++){
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();
            vertice[a][b] = c;
            vertice[b][a] = c;
            String t = Integer.toString(a)+"-"+Integer.toString(b);
            String t2 = Integer.toString(b)+"-"+Integer.toString(a);
            mem.put(t,c);
            mem.put(t2,c);
        }
        for(int k =1;k<=n;k++){
            for(int i=1;i<=n;i++){
                for(int j=1;j<=n;j++){
                    vertice[i][j] = Math.min(vertice[i][j],vertice[i][k]+vertice[k][j]);
                }
            }
        }

        for(int i=1;i<n;i++) {
            for (int j = i+1; j <= n; j++) {
                String t = Integer.toString(i)+"-"+Integer.toString(j);
                if(mem.containsKey(t)){
                    if(mem.get(t)!=vertice[i][j]){
                        ans++;
                    }
                }
            }
        }
        System.out.println(ans);

    }
}


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

int main() {
    ll N;
    cin >> N;

    ll cnt = 0;
    ll last = 0;
    ll pre = 1;
    while (last + pre * 26 <= N)
    {
        cnt++;
        last = last + pre * 26;
        pre *= 26;
    }

    ll x = N - last;
    if (x == 0)
    {
        cnt--;
    }
    
    vector<ll> A(cnt + 1, -1);
    if (x == 0)
    {
        A[0] = 26;
    }
    
    int i = 0;
    while (x > 0)
    {
        ll y = x / pre;
        A[i] = y;
        x -= y * pre;
        pre /= 26;
        i++;
    }
    

    vector<char> ans(A.size(), 'z');
    for (int i = 0; i < A.size(); i++)
    {

        if (i < A.size() - 1 && A[i + 1] == -1)
        {
            A[i]--;
            ans[i] = 'a' + A[i];
            break;
        }
        if (i == A.size() - 1)
        {
            A[i]--;
        }
        
        ans[i] = 'a' + A[i];
    }
    
    for (int i = 0; i < ans.size(); i++)
    {
        cout << ans[i];
    }
    cout << endl;

  return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>
int main(void) {
  char s[10], t[10], u[10];
  int a, b;
  scanf("%s %s", s, t);
  scanf("%d %d", &a, &b);
  scanf("%s", u);
  if (s[0] == u[0])
    a--;
  else
    b--;
  printf("%d %d\n", a, b);
  return 0;
}


Measured memory_bytes: 128
def main():
    examB()

def examA():
    N = I()
    ans = 1^N
    print(ans)
    return

def examB():
    a, b, c, d = LI()
    ans = max(a*c,a*d,b*c,b*d)
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

def test():
    i = I()
    li = LI()
    lsi = LSI()
    si = LS()
    print(i)
    print(li)
    print(lsi)
    print(si)
    return

from decimal import getcontext,Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,alphabet_convert,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 1<<31
_ep = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}

getcontext().prec = 28

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    main()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Measured memory_bytes: 10560
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(long long i=0;i<(n);i++)
#define REP1(i,n) for(long long i=1;i<=(n);i++)
#define REP2D(i,j,h,w) for(long long i=0;i<(h);i++) for(long long j=0;j<(w);j++)
#define REP2D1(i,j,h,w) for(long long i=1;i<=(h);i++) for(long long j=1;j<=(w);j++)
#define PER(i,n) for(long long i=((n)-1);i>=0;i--)
#define PER1(i,n) for(long long i=(n);i>0;i--)
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define FORE(i,a,b) for(long long i=(a);i<=(b);i++)
#define ITE(arr) for(auto ite=(arr).begin();ite!=(arr).end();++ite)
#define ALL(a) ((a).begin()),((a).end())
#define RANGE(a) (a),((a)+sizeof(a))
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define YNPRT(b) cout<<((b)?"Yes":"No")<<endl
#define ENTER printf("\n")
#define REV(arr) reverse(ALL(arr))
#define PRT(a) cout<<(a)<<endl

#ifdef DEBUG
#define DBPRT(a) cout << "[Debug] - " << #a << " : " << (a) << endl
#define DBSTART if(1){
#define DBEND }
#define PRTLST(arr,num) REP(_i,num) cout<<_i<<" - "<<arr[_i]<<endl;
#define PRTLST2(arr2,d1,d2) REP(_i,d1) REP(_j,d2) cout<<_i<<","<<_j<<" : "<<arr2[_i][_j]<<endl;
#define PRTLST2D(arr2,d1,d2) do{cout<<"L\t";REP(_i,d2) cout<<_i<<"\t"; cout<<endl; REP(_i,d1){cout<<_i<<"\t";REP(_j,d2){cout<<arr2[_i][_j]<<"\t";}cout<<endl;}}while(0);
#else
#define DBPRT(a) if(0){}
#define DBSTART if(0){
#define DBEND }
#define PRTLST(arr,num) if(0){}
#define PRTLST2(arr2,d1,d2) if(0){}
#define PRTLST2D(arr2,d1,d2) if(0){}
#endif

#define TOSUM(arr,sum,n) {sum[0]=arr[0];REP1(i,n-1) sum[i]=sum[i-1]+arr[i];}

#define MIN(target,v1) (target)=min(target,v1)
#define MAX(target,v1) (target)=max(target,v1) 
#define P1 first
#define P2 second
#define PB push_back
#define UB upper_bound
#define LB lower_bound
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INF_INT = 2147483647;
const ll INF_LL = 9223372036854775807LL;
const ull INF_ULL = 18446744073709551615Ull;
const ll P = 92540646808111039LL;
const int Move[4][2] = {-1,0,0,1,1,0,0,-1};
const int Move_[8][2] = {-1,0,-1,-1,0,1,1,1,1,0,1,-1,0,-1,-1,-1};
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p) {os<<"( "<<p.P1<<" , "<<p.P2<<" )";return os;}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {ITE(v) os << (ite-v.begin()) << " : " << *ite <<endl;return os;}
template<typename T>
ostream& operator<<(ostream& os,const set<T>& v) {os<<" { ";ITE(v) {os<<*ite;if(ite!=--v.end()){os<<" , ";}} os<<" } ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const map<T1,T2>& m) {ITE(m) {os<<ite->P1<<"\t\t|->\t\t"<<ite->P2<<endl;} return os;}

//---------------------
#define MAXN 100000
//---------------------

ll n , k;

int main(){
	cin >> n >> k;
	ll ct = 0;
	while(n>0){
		n /= k;
		ct ++ ;
	}
	PRT(ct);
	return 0;
}









Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))
b = list(set(a))
flag = False
if len(b) == 3:
    if b[0] ^ b[1] == b[2]:
        if a.count(b[0]) == N/3 and a.count(b[1]) == N/3 and a.count(b[2]) == N/3:
            flag = True
if len(b) == 1:
    if b[0] == 0:
        flag = True
if len(b) == 2:
    if 0 in b and a.count(0) == N / 3:
            flag = True


if flag:
    print('Yes')
else:
    print('No')


    

Measured memory_bytes: 14116