akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict
import itertools

N = int(input())

P = defaultdict(int)
for i in range(N):
    s = input()
    if s[0] in "MARCH":
        P[s[0]] += 1

if len(P)<3:
    print(0)
else:
    ans = 0
    for a,b,c in itertools.combinations(P,3):
        ans += P[a]*P[b]*P[c]
    print(ans)

Measured memory_bytes: 3444
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  int h[N];
  for(int i=0;i<N;++i) cin>>h[i];
  bool now;
  int tmp;
  int ans = 0;
  for(int i=1;i<=100;++i) {
    tmp = 0;
    now = false;
    for(int j=0;j<N;++j) {
      if(h[j]>=i) {
        if(!now) {
          now = true;
          tmp++;
        }
      }
      else {
        if(now) now = false;
      }
    }
    ans += tmp;
  }
  cout<<ans<<endl;
}



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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];

    vector<ll> B(N+1, 0);
    REP(i, N) B[i+1] = B[i] + A[i];

    vector<ll> C;
    REP(i, N){
    	for(int j=i+1;j<N+1;j++){
    		C.push_back(B[j]-B[i]);
    	}
    }
    //cout << C << endl;
    ll res = 0;
    for(ll k=60;k>=0;k--){
    	ll tmp = (1ll << k);
    	ll kosu = 0;
    	REP(j, C.size()) if(C[j] >= tmp) kosu++;
    	if(kosu >= K){
    		res += tmp;
    		REP(j, C.size()){
    			C[j] -= tmp;
    		}
    	}else{
    		REP(j, C.size()){
    			if(C[j] >= tmp) C[j] -= tmp;
    		}
    	}
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 6384
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define INF 1000000000000
using namespace std;
using ll=long long;
using ld=long double;

int main() {
    ll n,m;
    cin>>n>>m;
    vector<ll> h(n);
    vector<ll> a(m);
    vector<ll> b(m);
    rep(i,n)cin>>h[i];
    rep(i,m)cin>>a[i]>>b[i];
    vector<ll> bet_flag(n,1);
    vector<ll> memo(n,0);
    ll ans=0;
    rep(i,m){
        if((h[a[i]-1]-h[b[i]-1])<0){
            if(bet_flag[b[i]-1]!=0){
            bet_flag[b[i]-1]=1;
            }
            bet_flag[a[i]-1]=0;
        }
        else if((h[a[i]-1]-h[b[i]-1])>0){
            if(bet_flag[a[i]-1]!=0){
            bet_flag[a[i]-1]=1;
            }
            bet_flag[b[i]-1]=0;            
        }
        else{
            bet_flag[a[i]-1]=0;
            bet_flag[b[i]-1]=0;
        }
    }
    rep(i,n){
        if(bet_flag[i]==1){
            ans++;
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 7188
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>

using namespace std;

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

const int INF = 1e9;
const ll LINF = 1e18;

struct edge{int to,cost;};

const int MOD=1e9+7;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n,m;
	cin >> n >> m;

	if(abs(n-m) < 2){
		long long ans=1;
		
		for(int i=n;i>=2;i--){
			ans=ans*i%MOD;
		}
		for(int i=m;i>=2;i--){
			ans=ans*i%MOD;
		}
		if(n==m){
			ans = ans*2%MOD;
		}
		cout << ans << "\n";
	}
	else cout << "0\n";
	return 0;
}

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

int main(){
  int n,m,c;
  cin >> n >> m >> c;
  int ans=0;
  vector<int> b(m);
  for (int j=0;j<m;++j) cin >> b[j];
  for(int i=0;i<n;++i){
    int tmp = c;
    for(int j=0; j<m; ++j){
      int a;
      cin >>a;
      tmp += b[j]*a;
    }
    if (tmp >0) ans ++;
  }
  cout << ans<< endl;
}

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

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var h = Console.ReadLine().Split().Select(int.Parse).ToArray();

            var maxH = new List<int>();
            maxH.Add(0);

            var count = 0;

            foreach(var x in h)
            {
                if(maxH.Last() <= x)
                {
                    maxH.Add(Max(maxH.Last(), x));
                    count++;
                }
            }
            Console.WriteLine(count);

        }
    }
}


Measured memory_bytes: 13396
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.lang.Math;

public class Main {
    public static void main(String[] args) {
        FS reader = new FS();
        // write reader
        int N = reader.nextInt();
        int[] A = new int[N];
        int[] B = new int[N];
        int[] C = new int[N-1];
        for (int i=0; i<N; i++) {
            A[i] = reader.nextInt()-1;
        }
        for (int i=0; i<N; i++) {
            B[i] = reader.nextInt();
        }
        for (int i=0; i<N-1; i++) {
            C[i] = reader.nextInt();
        }
        int ans = 0;
        for (int i=0; i<N; i++) {
            ans += B[A[i]];
            if (i > 0 && A[i-1]+1 == A[i]) {
                ans += C[A[i-1]];
            }
        }
        
        System.out.println(ans);
    }
    
    public static void solver() {
        // write logic
    }
    
    // Read Class
    static class FS {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
    
        private int readByte() { return hasNextByte() ? buffer[ptr++] : -1;}
        private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
        private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public int nextInt() {
            return (int)nextLong();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while(true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if(b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
    }
}



Measured memory_bytes: 22228
import java.util.Scanner;
class Main{
  public static void main(String[]args){
    Scanner scanner = new Scanner(System.in);
    while(true){
      int a = scanner.nextInt();
      int b = scanner.nextInt();
      int c = scanner.nextInt();
      if(a == -1 && b == -1 && c == -1){
        break;
      }else{
        if(a == -1 || b == -1){
          System.out.println("F");
        }else if(a + b >= 80 ){
          System.out.println("A");
        }else if(a + b >= 65){
          System.out.println("B");
        }else if(a + b >= 50){
          System.out.println("C");
        }else if(a + b >= 30){
          if(c >= 50){
            System.out.println("C");
          }else{
            System.out.println("D");
          }
        }else{
          System.out.println("F");
        }
      }
      
   }
    
    
  }
}


Measured memory_bytes: 26244
#include<vector>
#include<iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	vector<vector<int>>v(n);
	for (int i = 0; i < n; i++)
	{
		int u;
		cin >> u;
		v[i].push_back(u);
		int k;
		cin >> k;
		v[i].push_back(k);
		for (int j = 0; j < k; j++)
		{
			int number;
			cin >> number;
			v[i].push_back(number);
		}
	}
	vector <vector<int>>answer(n, vector<int>(n));
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			answer[i][j] = 0;
		}

	}
	
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < v[i].size()-2; j++)
		{
			answer[v[i][0]-1][v[i][2 + j]-1 ]= 1;
		}
	}
	
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n-1; j++)
		{
			cout << answer[i][j]<<" ";
		}
		cout << answer[i][n - 1] << endl;
		
	}
}
/*
1 2 2 4
2 1 4
3 0
4 1 3


*/


Measured memory_bytes: 3132
#include <bits/stdc++.h>
#include <boost/range.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/algorithm_ext.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>
#include <boost/math/constants/constants.hpp>
using namespace std;
namespace rng {
    using namespace boost;
    using namespace boost::range;
    using namespace boost::adaptors;
    template<class R, class P> auto partition_point(const R& r, P p) { return ::std::partition_point(begin(r), end(r), p); }
}

struct init_ { init_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } init_;

using boost::irange;
using boost::math::double_constants::pi;
using i64 = int64_t;
constexpr char nl = '\n';
auto yesno(bool b) { return b ? "Yes" : "No"; }

template<class T> istream& operator>>(istream& in, vector<T>& vs) { for (T& v :vs) in >> v; return in; }
template<class T> ostream& operator<<(ostream& out, const vector<T>& vs) { for (size_t i = 0; i < vs.size(); ++i) { if(i) { out << ' '; } out << vs[i]; } return out; }
template<size_t N, class T, class R> using when_last = typename enable_if<N == tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N, class T, class R> using when_init = typename enable_if<N != tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_last<N, T, istream&> { return in >> get<N>(t); }
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_init<N, T, istream&> { return operator>><N + 1>(in >> get<N>(t), forward<T>(t)); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_last<N, T, ostream&> { return out << get<N>(t); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_init<N, T, ostream&> { return operator<<<N + 1>(out << get<N>(t) << ' ', t); }

#ifdef LOCAL
template<class T> void trace_(const T& v) { cout << v; }
template<class T> void trace_(const vector<vector<T>>& m) { cout << nl; for (const auto& v : m) { trace_(v); cout << nl; } }
template<class T> void trace_(const char* s, const T& v) { cout << s << "="; trace_(v); cout << nl; }
template<class T, class... Ts> void trace_(const char* s, const T& v, const Ts&... vs) { for (; *s != ','; ++s) { cout << *s; } cout << "="; trace_(v); cout << ","; trace_(++s, vs...); }
#define TRACE(...) trace_(#__VA_ARGS__, __VA_ARGS__)
#else
#define TRACE(...)
#endif

int main() {
    int N;
    cin >> N;
    i64 sum = 0;
    for (int i : irange(1, N+1)) {
        if (i % 3 != 0 && i % 5 != 0) {
            sum += i;
        }
    }
    cout << sum << nl;
}


Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
using namespace std;
int n,a[301010],b[301010];
bool check(int x)
{
	for(int i=1;i<=n*2+1;i++)
	b[i]=(a[i]>x);
	b[0]=b[1];
	for(int i=n,j=n;i;i--,j++)
	if(b[i]==b[i-1]) return b[i];
	else if(b[j]==b[j+1]) return b[j];
}
	
int main() 
{
	scanf("%d",&n);
	for(int i=1;i<=n*2-1;i++)
	scanf("%d",&a[i]);
	int l=1,r=n*2-1,mid;
	while(l<r)
	{
		mid=(l+r)/2;
		if(!check(mid)) r=mid;
		else l=mid+1;
	}
	printf("%d\n",l);
	return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	public static void main(final String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		int h = sc.nextInt();
		int w = sc.nextInt();
		sc.close();
		// 出力
		prtln((H - h) * (W - w));
	}
	public static <T> void prtln(T t) { System.out.println(t); }
}

Measured memory_bytes: 23380
#include<bits/stdc++.h>
using namespace std;
int n,a[100010],k,ans=2e9; 
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a+1,a+1+n);
	for(int i=1;i+k-1<=n;i++){
		ans=min(ans,a[i+k-1]-a[i]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n;i++)
using namespace std;
int main(){
    int n; cin>>n;
    int array[100000+2]={0};
    rep(i,n){
        int l,r; cin>>l>>r;
        array[l]++;
        array[r+1]--;
    }
    int ans=0;
    for(int i=0; i<100000;i++)array[i+1]+=array[i];
    for(int i=1; i<=100000;i++)if(array[i])ans++;
    cout<<ans<<endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

long long dp[51][5005];
int x[50];

int main(){
	int N, A;
	cin >> N >> A;
	for(int i = 0 ; i < N; i++){
		cin >> x[i];
		x[i] -= A;
	}
	
	int gt = 2502;
	dp[0][gt] = 1;
	for(int i = 0 ; i < N ; i++){
		for(int j = 0 ; j < 5005 ; j++){
			dp[i+1][j] = dp[i][j];
		}
		for(int j = 0 ; j < 5005 ; j++){
			int t = j + x[i];
			if( t < 0 || t >= 5005 ) continue;
			dp[i+1][t] += dp[i][j];
		}
	}
	cout << dp[N][gt] - 1 << endl;
	
	
}


Measured memory_bytes: 2176
def main():
    N = int(input())
    edge = [[-1]*N for i in range(N)]
    for i in range(N):
        A = int(input())
        for a in range(A):
            x, y = (int(i) for i in input().split())
            edge[i][x-1] = y
    # print(*edge, sep="\n")
    ans = 0
    for bit in range(1 << N):
        cur = [0] * N
        flag = True  # 正直者が嘘をついたときだけFalse
        for i in range(N):
            if bit & (1 << i):
                cur[i] = 1
        for i in range(N):
            for j in range(N):
                if edge[i][j] == -1:
                    continue
                elif edge[i][j] == 1 and cur[i] and not(cur[j]):
                    flag = False
                elif edge[i][j] == 0 and cur[i] and cur[j]:
                    flag = False
        if flag:
            ans = max(ans, sum(cur))
    print(ans)


if __name__ == '__main__':
    main()


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

int main() {
    int n;
    cin >> n;
    int last;
    int cur, ans = 0;
    for (int i = 0; i < n; ++i) {
        cin >> cur;
        if (i == 0) {
            ++ans;
            last = cur;
        }
        else {
            if (cur < last) {
                continue;
            }
            ++ans;
            last = cur;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
import java.sql.Array;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int len = scanner.nextInt();
		List<Integer> nums = new ArrayList<Integer>() ;
		for (int i = 0; i < len; i++) {
			nums.add(scanner.nextInt());
		}
		
		int min = nums.get(0);
		int profit = -1000000000;
		for (int i = 1; i < len; i++) {
			if (profit<(nums.get(i)-min)) {
				profit = nums.get(i)-min;
			}
			if (nums.get(i)<min) {
				min = nums.get(i);
			}
		}
		
		System.out.println(profit);
	}

}


Measured memory_bytes: 105800
#include <iostream>

#define u unsigned
#define s short
#define ll long long
#define REP(i, a, b) for (auto i = (a); i < (b); i++)
#define REPR(i, a, b) for (auto i = (a-1); i >= (b); i--)

using namespace std;

int solve(int K) 
{
    const int MAX_INDEX = static_cast<int>(1.0e7);

    int total = 0;
    for (int i = 1; i <= MAX_INDEX; i++)
    {
        total = (total * 10 + 7) % K;

        if (total == 0)
            return i;
    }

    return -1;
}

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

    cout << solve(K) << "\n";

    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
int a[5005];
int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    sort(a,a+n,greater<int> ());
    int ans=-1;
    for(int i=0;i<n;i++)
    {
        long long s=0;
        for(int j=i;j<n;j++)
        {
            if(s+a[j]<m)
            {
                s+=a[j];
                continue;
            }
            ans=max(ans,j);
        }
    }
    printf("%d\n",n-ans-1);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <cstdio>
#include<string>
#include<math.h>
using namespace std;
//int ha(string);
//int saga(int);
int q,m,n=1000000,List[1000];
bool  slist[1000001];
bool  klist[1000001];

int main()
{	
	int i,j,k,b=0,s,a=2,f=0,c=0;
	for( i = 0; i <n;i++ ){
		slist[i]=true;
		klist[i]=false;
	}

	i=0;
	while(i<sqrt((double)n)){
		for(i=a+a;i<n;i=i+a){
			slist[i]=false;
		}
		for(i=a+1;i<sqrt((double)n);i++){
			if(slist[i]==true){
				a=i;
				break;
			}
		}
	}
	cin>>m>>n;
	while(m!=0||n!=0){
	for( i = 0; i <=n;i++ ){
		klist[i]=false;
	}
	for(i=0;i<m;i++){
		cin>>List[i];
		klist[List[i]]=true;
	}
		for(i=0;i<=n;i++){
			if(klist[i]){
			for(j=0;j<m;j++){
				if(i+List[j]<=n){
				klist[i+List[j]]=true;
				}
			}
		}
	}
		for(i=n;i>0;i--){
			if(klist[i]&&slist[i]){
			break;
		}
	}
		if(i==0){
			printf("NA\n");
		}
		else{
		printf("%d\n",i);
		}
		cin>>m>>n;
	}
	return 0;
}

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

typedef long long ll;
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define REP(i,n) for (int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
 
using namespace std;

int main(){
    
    ll n;
    cin >> n;
    ll s = 0;
    REP(i,n){
        ll a;
        cin >> a;
        s += a;
    }
    cout << s -n << endl;



}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(int (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
const ll MOD=1e9+7;
using namespace std;

int main(){
  string s;
  cin >> s;
  int max=0;
  for(int i=0;i<s.size();i++){
    for(int j=1;j<=s.size()-i;j++){
      string tmp = s.substr(i,j);
      bool flag=true;
      rep(k,tmp.size()){
        if(tmp[k]=='A' || tmp[k]=='T' || tmp[k]=='G' || tmp[k]=='C'){
        }else{
          flag=false;
          break;
        }
      }
      if(flag){
        if(max<tmp.size()){
          max = tmp.size();
        }
      }
    }
  }
  cout << max << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e18)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second > b.second;
    }
}

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

int main()
{
    ll N;
    cin >> N;
    vector<vector<P>> G(N);
    rep(i, N-1) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--;b--;
        G[a].push_back(P(b, c));
        G[b].push_back(P(a, c));
    }
    
    ll Q, K;
    cin >> Q >> K;
    K--;
    vector<ll> dist(N, INF);
    vector<bool> visited(N, false);
    dist[K] = 0;
    stack<ll> st;
    st.push(K);
    while(!st.empty()) {
        ll tmp = st.top();
        st.pop();
        visited[tmp] = true;
        for(P p : G[tmp]) {
            if (dist[p.first] > dist[tmp] + p.second) {
                dist[p.first] = dist[tmp] + p.second;
            }
            if (!visited[p.first])
                st.push(p.first);
        }
    }
    rep(i, Q) {
        ll x, y;
        cin >> x >> y;
        x--;y--;
        print(dist[x] + dist[y]);
    }
    return 0;
}

Measured memory_bytes: 9984
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define pb push_back
#define ub upper_bound
#define lb upper_bound
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define ve vector
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
 
using ll = long long;
const ll INF = LLONG_MAX - 100;
ll mod = 1e9 + 7;
int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1};
vector<ll> prime;

class fact {
public:
	int fmod = 1e9+7;
	vector<int> fac, inv;
	fact (int n, int Mod = 1e9+7) {
		fmod = Mod;
		fac = vector<int>(n,0);
		inv = vector<int>(n,0);
		fac[0] = 1; for (int i = 1; i < n; i++) fac[i] = fac[i-1] * i % fmod;
		for (int i = 0;i < n;i++) inv[i] = fact::POW(fac[i],fmod-2);
	}
	ll nCr(ll n, ll r) {return (fac[n] * inv[r] % fmod) * inv[n-r] % fmod;}
	ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%fmod;}a = a * a%fmod; b >>= 1;}return c;}
};
 
template <class T = ll> T in() {T x; cin >> x; return (x);}
void DEBUG(vector<int> a) {for(int i=0;i<a.size();i++)cout<<a[i]<<" ";cout<<endl;}
void EMP(int x) {cout<<"!!!"<<x<<"!!!"<<endl;}
ll GCD(ll a, ll b) {ll c; while (b != 0) {c = a % b; a = b; b = c;}return a;}
ll LCM(ll a, ll b) {return a * b / GCD(a, b);}
ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%mod;}a = a * a%mod; b >>= 1;}return c;}
void PRI(ll n) {bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) {a[i] = 1LL;}for (int i = 2; i < n + 1LL; i++) {if (a[i]) {prime.pb(i); ll b = i; while (b <= n) {a[b] = 0; b += i;}}}}
template <typename T> T chmin(T& a, T b) {if(a>b)a=b;return a;}
template <typename T> T chmax(T& a, T b) {if(a<b)a=b;return b;}
bool isSqrt(ll a) {return pow(sqrt(a),2) == a ? 1 : 0;}
void YesNo(bool a) {if (a) cout << "Yes"; else cout << "No"; cout << endl;}
void yesno(bool a) {if (a) cout << "yes"; else cout << "no"; cout << endl;}
void YESNO(bool a) {if (a) cout << "YES"; else cout << "NO"; cout << endl;}

bool solve() {	
	int n,z,w; cin >> n>> z >> w;
	int a[n]; REP (i,n) cin >> a[i];
	int ans = abs(w-a[n-1]);
	if (n > 1) chmax(ans,abs(a[n-2]-a[n-1]));
	cout << ans << endl;
}

signed main() {
	// cin.tie(0);
	// ios::sync_with_stdio(false);
	solve();
}


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

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#pragma GCC optimize("Ofast")
//1.0 * clock() / CLOCKS_PER_SEC

#define fi first
#define se second
#define ll long long
#define dl double long

using namespace std;

const ll NN = 1e10 + 7;
const int N = 1e5 + 7;
const int M = 11;
const ll mod = 1e9 + 7;
const ll inf = 1e18 + 7;
const dl rf = 1e-14;

void solve1()
{
	ll n, s = 0;
	cin >> n;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++)
			for(int q = 1; q <= n; q++)
				s += __gcd(i, __gcd(j, q));
	cout << s;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0); srand(time(0));
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );

    int cghf = 1;//cin >> cghf;
    while( cghf-- ){
        solve1();
    }
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define intput(i) cout << i << endl
#define ll long long
#define stringput(s) cout << (string)(s) << endl

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  string ans;
  if(a > b){
    if(c > b && a > c) ans = "Yes";
    else ans = "No";
  }
  else{
    if(c < b && a < c) ans = "Yes";
    else ans = "No";
  }
  cout << ans << endl;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

string s;

int main(){
    cin >> s;
    ll ans = 0;
    ll now = 0;
    char prev = '#';
    rep(i,s.size()){
        if(s[i] != prev && s[i] == 'S')ans = max(ans,now);
        prev = s[i];
        if(s[i] == 'S')now--;
        else now++;
    }
    cout << max((ll)0,ans*2) << endl;
}

Measured memory_bytes: 640
N, M = map(int, input().split())
H = list(map(int, input().split()))
ma = [0]*(N+1)
cnt = 0
for _ in range(M):
    a, b = map(int, input().split())
    ma[a] = max(ma[a], H[b-1])
    ma[b] = max(H[a-1], ma[b])
for i in range(1, N+1):
    if H[i-1] > ma[i]:
        cnt += 1
print(cnt)

Measured memory_bytes: 85016
import java.util.*;
	import java.util.Map.Entry;
	 
	 
	 class Main {
		 static int mod =  (int) (Math.pow(10,9)+7);
//		 static int mod =  (int) 998244353;
		 static List<ArrayList<Integer>> list= new ArrayList<ArrayList<Integer>>();
		 public static void main(String[] args) {
	    	
	        Scanner sc = new Scanner(System.in);
	        int N = sc.nextInt();
	        long maxwa = Long.MIN_VALUE;
	        long minwa = Long.MAX_VALUE;
	        long maxsa = Long.MIN_VALUE;
	        long minsa = Long.MAX_VALUE;
	        long[] a = new long[N];
	        for (int i=0 ; i<N; i++) {
	        	long x = Long.parseLong(sc.next());
	        	long y = Long.parseLong(sc.next());
	            maxwa= Math.max(maxwa, x+y);
	            minwa= Math.min(minwa, x+y);
	            maxsa= Math.max(maxsa, x-y);
	            minsa= Math.min(minsa, x-y);
	        }
	        long ans = Math.max(maxwa-minwa, maxsa-minsa);
	        ans=Math.max(ans, -minsa+maxsa);
	        ans=Math.max(ans, -minwa+maxwa);
	        
	        System.out.println(ans);
		 }
		 
	 
	}

Measured memory_bytes: 62544
@fact = [1]
def fact(n, mod)
  if n > @fact.size then
    f = @fact[-1]
    (@fact.size+1..n).each{|i|
      f = (f * i) % mod
      @fact << f
    }
  end
  @fact[n-1]
end

def inverse(x, mod)
  pow(x, mod-2, mod)
end

def pow(x, n, mod)
  ans = 1
  while n > 0
    ans = ans * x % mod if n.odd?
    x = x * x % mod
    n >>= 1
  end
  ans
end

X, Y = gets.chomp.split(" ").map(&:to_i)
MOD = 10 ** 9 + 7

xc = (X - 2 * Y) % -3
yc = (-2 * X + Y) % -3

if xc != 0 || yc != 0 then
  ans = 0
else
  x = (X - 2 * Y) / -3
  y = (-2 * X + Y) / -3
  if 0 > x || 0 > y then
    ans = 0
  elsif x == 0 || y == 0 then
    ans = 1
  else
    ans = fact(x + y, MOD) * inverse(fact(x, MOD) * fact(y, MOD) % MOD, MOD) % MOD
  end
end

puts ans


Measured memory_bytes: 7164
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
int main()
{
    string s;
    cin>>s;
    int a, z;
    int len = s.size();
    for(int i = 0; i < len; i++){
        if(s[i] == 'A'){
            a = i;
            break;
        }
    }
    for(int i = len-1; i >= 0; i--){
        if(s[i] == 'Z'){
            z = i;
            break;
        }
    }
    int ans = z-a+1;
    if(ans < 0)ans = 0;
    cout<<ans;


    return 0;
}


Measured memory_bytes: 832
import numpy as np
import math
N = int(input())
arr = [np.array(list(map(int,input().split()))) for _ in range(N)]
dist_arr = []
for i in range(N):
  for j in range(i+1,N):
    dist_arr.append(np.linalg.norm(arr[i]-arr[j]))

dist_arr = np.array(dist_arr)
dist_arr = dist_arr*(N-1)*2*(math.factorial(N-2))
print((dist_arr.sum())/math.factorial(N))

Measured memory_bytes: 12408
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vl vector<LL>
#define vii vector<vi>
#define vll vector<vl>



int prime[100002]={};//100000以下の素数:9592個
int Er_N=100001;
void Er(){//Eratosthenes  1:PRIME  0:NOT PRIME
	for(int i = 2; i < Er_N; i++){
		prime[i] = 1;
	}
	int limit_Er_roop=sqrt(Er_N);
	for(int i = 2; i < limit_Er_roop; i++){
		if(prime[i]){
			for(int j = 0; i * (j + 2) < Er_N; j++){
				prime[i *(j + 2)] = 0;
			}
		}
	}
}

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

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


const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	int n;
    cin>>n;
    n++;
    LL ans=0;
    FOR(i,1,n){
        FOR(j,1,n){
            LL a=gcd(i,j);
            FOR(k,1,n){
                ans+=gcd(a,k);
            }
        }
    }
    cout<<ans;
}


Measured memory_bytes: 3592
yen500,yen100,yen50,fee =  [int(input()) for i in range(4)]

counter=0
for a in range(yen500+1):
    for b in range(yen100+1):
        for c in range(yen50+1):
            total = 500 * a + 100 * b + 50 * c
            if total == fee:
                counter +=1
                break
print(counter)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,a,b;
int main()
{
    cin >> n >> a >> b;
    ll ans=n/(a+b)*a;
    if(n%(a+b)) ans+=(n%(a+b)>=a)?a:n%(a+b);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
abc = list(list(map(int,input().split()))for i in range(N))
DP = [[0,0,0]for i in range(N+1)]
for i in range(N):
    for j in range(3):
        DP[i+1][j] = max(DP[i][:j]+DP[i][j+1:])+abc[i][j]
print(max(DP[-1]))

Measured memory_bytes: 47324
#include<iostream>
using namespace std;
int main(){
  int N;
  cin >> N;
  int A[11];
  for(int i = 0; i < N; i++)
  {
    cin >> A[i];
    /* code */
  }
  int max = 0;
  for(int i = 0; i < N; i++)
  {
    if(max < A[i]){
      max = A[i];
    }
    /* code */
  }
  int sum = 0;
  for(int i = 0; i < N; i++)
  {
    sum += A[i];
    /* code */
  }
  sum = sum - max;

  if(max < sum){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }


}

Measured memory_bytes: 256
n,m = map(int,input().split())
conditions = [tuple(map(int,input().split())) for _ in range(m)]
P = tuple(map(int,input().split()))
ans = 0
impossible = False
for i in range(2 ** n):
  switches = []
  for j in range(n):
    if i >> j & 1:
      switches.append(1)
    else:
      switches.append(0)
  for l in range(m):
    s_cnt = 0
    for s_needed in range(conditions[l][0]):
      s = conditions[l][s_needed + 1]
      if switches[s - 1] == 1:
        s_cnt += 1
    if s_cnt % 2 != P[l]:
      impossible =True
      break
  if impossible:
    impossible = False
    continue
  ans += 1
print(ans)

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

using namespace std;

int main()
{
    int N=0,cnt=0;
    cin>>N;
    while(N!=0){
        if((N%10)==7){
            cnt++;
        }
        N=N/10;
    }
    if(cnt>0){
        cout<< "Yes";
    }
    else{
        cout<< "No";
    }
    return 0;
}


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

dict = {}
ans = []
for i in range(n):
  cmd, key = input().split(" ")
  if cmd == "insert":
    dict[key] = "yes"
    continue
  
  if cmd == "find":
    if dict.get(key) is None:
      ans.append("no")
    else:
      ans.append(dict[key])

for a in ans:
  print(a)



Measured memory_bytes: 37448
# Code for B - Nice Shopping
# Use input() to fetch data from STDIN
[A, B, M] = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

x = [0 for i in range(M)]
y = [0 for i in range(M)]
c = [0 for i in range(M)]
for i in range(M):
    [x[i], y[i], c[i]] = map(int, input().split())

min_plain = min(a) + min(b)
min_wari = min([a[x[i] - 1] + b[y[i] - 1] - c[i] for i in range(M)])
print(min(min_plain, min_wari))


Measured memory_bytes: 27364
def find(x):
  if x==Tree[x]:
      return x
  else:
      Tree[x]=find(Tree[x])
      return Tree[x]
def unite(x,y):
  s1=find(x)
  s2=find(y)
  if s1!=s2:
    Tree[s2]=s1
    size[s1][0]+=size[s2][0]
    size[s1][1]+=size[s2][1]
H,W=map(int,input().split())
Tree=[i for i in range(H*W)]
S=[]
size=[[0,0] for i in range(H*W)]
for i in range(H):
  S.append(input())
  for j in range(W):
    t=i*W+j
    if S[-1][j]==".":
      size[t][0]=1
    else:
      size[t][1]=1
for i in range(1,W):
  if S[0][i]!=S[0][i-1]:
    unite(i,i-1)
for i in range(1,H):
  if S[i][0]!=S[i-1][0]:
    unite(i*W,(i-1)*W)
for i in range(1,H):
  for j in range(1,W):
    if S[i][j]!=S[i][j-1]:
      t=i*W+j
      unite(t,t-1)
    if S[i][j]!=S[i-1][j]:
      t=i*W+j
      unite(t,t-W)
ans=0
for i in range(H*W):
  if i==Tree[i]:
    ans+=size[i][0]*size[i][1]
print(ans)

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

int main(void)
{
  int h,w,k;
  scanf("%d %d %d", &h, &w, &k);

  char c[h][w];
  for(int i=0;i<h;i++){
    scanf("%s", c[i]);
  }

  int d[h][w];
  for(int i=0;i<h+1;i++){
    for(int j=0;j<w+1;j++){
      if(c[i][j]=='#') d[i][j]=1;
      else d[i][j]=0;
    }
  }
  
  int count;
  int ans=0;
  for(int bith=0;bith<(1<<h);++bith){
    for(int bitw=0;bitw<(1<<w);++bitw){
      count = 0;
      for(int i=0;i<h;i++){
	if(bith & (1<<i)){
	  for(int j=0;j<w;j++){
	    if(bitw & (1<<j)){
	      count = count + d[i][j];
	    }
	  }
	}
      }
      if(count == k) ans++;
    }
  }

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

  return 0;
}


Measured memory_bytes: 1684
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


N = read_a_int()
D = read_ints()
ans = 0

from itertools import combinations

for x, y in combinations(D, 2):
    ans += x * y

print(ans)


Measured memory_bytes: 3064
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;

const int MAX = 100000;

string strSort(string str){
    string ret = "";
    int table[26] = {0};

    for(int i = 0;i < 10;i++){
        table[str[i] - 'a']++;
    }
    for(int i = 0;i < 26;i++){
        for(int j = 0;j < table[i];j++)ret.push_back(i + 'a');
    }

    return ret;
}
 
int main(){
    int N;
    string str[MAX];
    map<string,int> m;
    long long ans = 0;

    cin >> N;
    for(int i = 0;i < N;i++){
        string str;
        cin >> str;
        str = strSort(str);
        if(m.count(str))m[str]++;
        else m[str] = 1;
    }

    for(map<string,int>::iterator it = m.begin();it != m.end();it++){
        ans += ((long long)(*it).second * ((*it).second - 1)) / 2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 13568
a, b = gets.chomp.split(' ').map(&:to_i)
x1 = (1..a).to_a.inject('') { |c, _| c + b.to_s }
x2 = (1..b).to_a.inject('') { |c, _| c + a.to_s }
puts [x1, x2].sort.first

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

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define SORT(v) sort(ALL(v))
//#define scanf scanf_s
typedef pair<int, int> P;

int n, m;
string id[1000];

int main()
{
	cin >> n;
	REP(i, n) cin >> id[i];
	cin >> m;
	string s;
	bool rock = false;
	REP(i, m)
	{
		bool flag = false;
		cin >> s;
		REP(i, n) if (s == id[i]) flag = true;
		if (flag)
		{
			if (rock == false) cout << "Opened by ";
			else cout << "Closed by ";
			cout << s << endl;
			rock = !rock;
		}
		else cout << "Unknown " << s << endl;
	}

	return 0;
}

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

#include <math.h>
#include <stdlib.h>


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

template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true; } return false; }

//INT_MAX	2,147,483,647 = 2*1.0e9

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n; cin >> n;
    vector<vector<int>> a(n, vector<int>(n,0));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++)cin >> a[i][j];
    }

    vector<vector<bool>> cnt(n, vector<bool>(n, true));

    for(int k = 0; k < n; k++){
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                if(i == k || j == k) continue;
                int s = a[i][k] + a[k][j];
                if(s < a[i][j]){
                    cout << -1 << endl;
                    return 0;
                } 
                if(s == a[i][j]){
                    cnt[i][j] = false;
                    cnt[j][i] = false;
                }
            }
        }
    }

    ll ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            if(cnt[i][j]) ans += (ll)a[i][j];
        }
    }

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


Measured memory_bytes: 640
#include<stdio.h>
int main()
{
    char a;
    while(scanf("%c",&a)!=EOF)
    {
        getchar();
        if(a=='a'||a=='e'||a=='i'||a=='o'||a=='u')
        printf("vowel\n");
        else printf("consonant\n");
    }
    return 0;
}

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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int a, b;
  cin >> a >> b;
  if(a+b==15){
    cout << "+" << endl;
  }else if(a*b ==15){
    cout << "*" << endl;
  }else{
    cout << "x" << endl;
  }

  return 0;
}


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

// #define int long long // intで書いたけど心配なときにlong longに変換する
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << endl;}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {REP(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}


ll DP[2001][2001];

signed main() {
    //my-code
    int N; cin >> N;
    vector<pair<ll, ll>> A(N);
    ll a;
    REP(i, N) {
        cin >> a;
        A[i] = mp(a, i);
    }
    sort(ALL(A), greater<pair<ll,ll>>());

    REP(i, N) REP(j, N) DP[i][j] = 0;

    ll j;
    REPS(xpy, 1, N+1) REP(i, xpy+1) {
        j = xpy - i;
        if (i-1 >= 0) {
            DP[i][j] = max(DP[i][j], DP[i-1][j] + A[xpy-1].Fi*(A[xpy-1].Se - (i-1)));
        }
        if (j-1 >= 0) {
            DP[i][j] = max(DP[i][j], DP[i][j-1] + A[xpy-1].Fi*(N-1-(j-1) - A[xpy-1].Se));
        }
    }

    ll ans = 0;
    REP(i, N+1) chmax(ans, DP[i][N-i]);

    cout << ans << endl;

    return 0;
}

// https://github.com/kurokoji/.cpp-Template/wiki テンプレートについて
// http://www.creativ.xyz/dump-cpp-652 dump()について
// https://gist.github.com/rigibun/7905920 色々

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

#define llint long long int

using namespace std;

int main(){
    int N;

    cin >> N;

    map<string, int> mp;

    for(int i = 0; i < N; i ++){
        string s;

        cin >> s;

        mp[s] = 0;
    }
    cout << mp.size() << endl;
}

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

struct dp{
	ll xp; // x+1円払う場合の最小枚数
	ll x0; // x  円払う場合の最小枚数
};

int main(){
	string N;
	cin >> N;
	int len = N.size();
	dp c = {1,0};
	
	for ( int i = 0; i < len; i++ ){
		int x = N[i] - '0';
		
		dp d = c;
		c.x0 = min(d.x0+x  , d.xp+(10-x));
		c.xp = min(d.x0+x+1, d.xp+(10-x-1));
	}
	
	cout << c.x0 << endl;
	
	return 0;
}



Measured memory_bytes: 1412
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
    char a[11],b[11],c[11];
    cin>>a>>b>>c;
    printf("%c%c%c\n",a[0]-32,b[0]-32,c[0]-32);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
 
const double TL = 1.5 * CLOCKS_PER_SEC;
mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
#define clr(x, y) memset(x, y, sizeof(x))
#define forn(i, n) for (int i = 0; i < n; i++)
#define LL long long
const double pi = acos(-1.0);


int main() {
#ifdef LOCAL
  auto start_clock = clock();
  freopen("in", "r", stdin);
#endif
  LL a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << max(max(a * c, a * d), max(b * c, b * d)) << endl;


#ifdef LOCAL
 auto end_clock = clock();
 cout << "Time:" << (end_clock - start_clock) * 1.0 / CLOCKS_PER_SEC << endl;
#endif
  return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			String s = sc.next();

			for (char c : s.toCharArray()) {
				System.out.print(convert(c, n));
			}
			System.out.println();
		}
	}

	private static char convert(char c, int n) {
		int tmp = c - 'A';
		tmp += n;
		tmp %= 26;
		return (char) (tmp + 'A');
	}
}


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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

constexpr int INF = 1e9;
constexpr ll INFLL = 1e18;
constexpr int MOD = 1e9 + 7;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

int main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);
    //cout << fixed << setprecision(6);
    int n; cin >> n;
    vll t(n);
    rep(i, n) cin >> t[i];

    auto lcm = [](ll a, ll b) -> ll{
        function<ll(ll,ll)> gcd = [&gcd](ll a, ll b) -> ll{
            if(b == 0) return a;
            return gcd(b, a%b);
        };
        return a / gcd(a, b) * b;
    };

    ll ans = 1;
    rep(i, n) ans = lcm(ans, t[i]);

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

Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
#define SZ(a) ((int)(a).size())
int main(){
#ifdef LOCAL
  freopen(".a.in", "r", stdin);
#endif
  ios_base::sync_with_stdio(false),cout.tie(0),cin.tie(0);
  int n;cin>>n;
  string s;cin>>s;
  int R=0,res=0;
  for(auto c:s)R+=c=='R';
  for(int i=0;i<R;++i)res+=(s[i]!='R');
  cout<<res<<"\n";
  
  return 0;
}
//2020.08.02 20:27:02


Measured memory_bytes: 3768
import math
A, B = map(int, input().split())

#int(ans*0.08) = A
#int(ans*0.10) = B

ans = 1
for b in range(10*B, 10*B+10):
    if int(b*0.08) == A:
        print(b)
        ans = 0
        break

if ans:
    print(-1)

Measured memory_bytes: 3060