akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      StrSplitToInt str;
      int n = Integer.parseInt(br.readLine());
      int[] seqA = new int[n];
      str = new StrSplitToInt(br.readLine(), " ");
      for(int i=0; i<n; i++) {
        seqA[i] = str.nextInt();
      }

      int q = Integer.parseInt(br.readLine());
      str = new StrSplitToInt(br.readLine(), " ");
      for(int i=0; i<q; i++) {
        if( solve(n, seqA, 0, str.nextInt()) )
          System.out.println("yes");
        else
          System.out.println("no");
      }
    }
  }

  private static boolean solve(int n, int[] a, int i, int m) {
    if( m == 0 ) return true;
    if( i >= n ) return false;

    boolean res = solve(n, a, i+1, m) || solve(n, a, i+1, m-a[i]);

    return res;
  }
}
 
class StrSplitToInt {
  final String s;
  final String split;
  final int endPos;
  final int splitLen;
  int currentPos;
  int nextPos;
 
  public StrSplitToInt(String s,String split) {
    this.s = s;
    this.split = split;
    currentPos = 0;
    nextPos = s.indexOf(split, currentPos);
    endPos = s.length();
    splitLen = split.length();
  }
 
  public int nextInt() {
    if( currentPos < endPos ) {
      int ret = Integer.parseInt( s.substring(currentPos, nextPos) );
      currentPos = nextPos + splitLen;
      nextPos = s.indexOf(split, currentPos);
      if(nextPos == -1) nextPos = endPos;
 
      return ret;
    }
    else
      return -1;
  }
}


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

int main() {
  char a,b;
  cin >> a >> b;
  if ((a-'A') > (b-'A')) cout << ">" << endl;
  else if ((a-'A') == (b-'A')) cout << "=" << endl;
  else cout << "<" << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	string w[102];
	int n,i,j,a=0,s1;
	cin >>n;
	for(i=1;i<=n;i++){
		cin >>w[i];
		for(j=1;j<i;j++){
			if(w[j]==w[i]){
				a=1;
			}
		}
		if(a!=1){
			if(i>=2){
				s1=w[i-1].size() ;
				if(w[i-1][s1-1]!=w[i][0]){
					a=1;
				}
			}
		}
	}
	if(a==1){
		cout <<"No";
	}else{
		cout <<"Yes";
	}
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define PB push_back
#define MP make_pair
#define all(x) x.begin(),x.end()
/*
int N,M;
LL c[100005] = {};
int main(){
	cin >> N >> M;
	for(int i=0; i<M; i++){
		int A,B;
		cin >> A >> B;
		A--; B--;
		c[A]++;
		c[B]++;
	}

	LL f = 0;
	for(int i=0; i<N; i++){
		if(c[i] > 0 && c[i]%2 == 0){
			f += c[i]/2-1;
		}
		else{
			cout << "No" << endl;
			return 0;
		}
	}
	if(f < 2){
		cout << "No" << endl;
		return 0;
	}
	
	cout << "Yes" << endl;

	return 0;
}*/

LL N,A,B;
int p[5000];
LL dp[5000][5001];
LL solve(int now, int hidari){
	if(now == N) return 0;
	if(dp[now][hidari] != -1) return dp[now][hidari];
	LL ans = 0;
	if(p[now] < hidari){
		ans = B+solve(now+1,hidari);
	}
	else{
		ans = min(A+solve(now+1, hidari), solve(now+1,max(hidari,p[now])));
	}
	return dp[now][hidari] = ans;
}
int main(){
	cin >> N >> A >> B;
	for(int i=0; i<N; i++){
		cin >> p[i];
		for(int j=0; j<=N; j++) dp[i][j] = -1;
	}
	cout << solve(0, 0) << endl;

	return 0;
}

Measured memory_bytes: 195840
#include<iostream>
#include<set>

using namespace std;

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

    long P[N];
    int value_index[N+1];
    for(int i = 0; i < N; i++) {
        cin >> P[i];
        value_index[P[i]] = i;
    }

    auto cmp = [](long a, long b) { return a > b;};

    set<long> larger_idx_right;
    set<long, decltype(cmp)> larger_idx_left(cmp);

    set<long>::iterator it;

    long ans = 0;

    for(int i = N; i > 0; i--) {
        long right_1 = N;
        long right_2 = N;
        it = larger_idx_right.upper_bound(value_index[i]);
        if(it != larger_idx_right.end()) {
            right_1 = *it;
            it = larger_idx_right.upper_bound(right_1);
            if(it != larger_idx_right.end()) {
                right_2 = *it;
            }
        }

        long left_1 = -1;
        long left_2 = -1;
        it = larger_idx_left.upper_bound(value_index[i]);
        if(it != larger_idx_left.end()) {
            left_1 = *it;
            it = larger_idx_left.upper_bound(left_1);
            if(it != larger_idx_left.end()) {
                left_2 = *it;
            }
        }

        larger_idx_right.insert(value_index[i]);
        larger_idx_left.insert(value_index[i]);

        if (right_1 != N) {
            ans += i*(value_index[i]-left_1)*(right_2-right_1);
        }
        if (left_1 != -1) {
            ans += i*(right_1-value_index[i])*(left_1-left_2);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 10752
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>

using namespace std;
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
#define rep(i, n) for(int i = 0;i < n;i++)
const int INF = 1LL << 30;

int MOD = 1000000007;

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

    string s; cin >> s;

    std::vector<int> ans(s.length(),0);

    int left=0,right=s.length()-1;

    while(s[left]=='L'){
        left++;
    }

    if(left!=0){
        ans[0]=left;
    }

    while(s[right]=='R'){
        right--;
    }

    if(right!=s.length()-1){
        ans[s.length()-1]=s.length()-right-1;
    }


    for(int i=left; i<=right;i++){

        if(s[i]=='R' && s[i+1]=='L'){

            int lb=i,rb=i+1;
            while(s[lb]=='R') lb--;
            while(s[rb]=='L') rb++;

            lb++;
            rb--;

            int l=i, r=i+1;
            int l_cnt=0, r_cnt=0;

            while(l>=lb){
                l_cnt++; l-=2;
            }

            while(r>=lb){
                r_cnt++; r-=2;
            }

            l=i, r=i+1;

            while(l<=rb){
                l_cnt++; l+=2;
            }

            while(r<=rb){
                r_cnt++; r+=2;
            }

            ans[i] = l_cnt-1;
            ans[i+1] = r_cnt-1;

            i = rb;

        }

    }
    


    rep(i,s.length()){
        cout << ans[i] << " ";
    }
    cout << '\n';

    return 0;
}

Measured memory_bytes: 1104
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
MOD = int(1e9) + 7

# 偶数の場合
if N % 2 == 0:
    c = Counter(A)
    if all(i == 2 for i in c.values()):
        print(pow(2, N//2, MOD))
    else:
        print(0)
# 奇数の場合
else:
    A.sort()
    A = A[1:]
    c = Counter(A)
    if all(i == 2 for i in c.values()):
        print(pow(2, N//2, MOD))
    else:
        print(0)

Measured memory_bytes: 20584
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	/** 大きい値 */
	private static final int INF = Integer.MAX_VALUE >> 1;

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), m = scanner.nextInt(), x = scanner.nextInt();
			int[][] a = new int[n][m];
			int[] c = new int[n];
			IntStream.range(0, n).forEach(i -> {
				c[i] = scanner.nextInt();
				IntStream.range(0, m).forEach(j -> a[i][j] = scanner.nextInt());
			});
			int[] current = new int[m];
			Arrays.fill(current, 0);
			int result = getResult(n, m, x, c, a, current, 0);
			System.out.println((result >= INF) ? -1 : result);
		}
	}

	/**
	 * 目標を達成するのに必要な金額の最小値を計算する
	 * 
	 * @param n
	 * @param m
	 * @param x
	 * @param c
	 * @param a
	 * @param current 現在の状態の配列
	 * @param index   現在処理している参考書のインデックス
	 * @return 目標を達成するのに必要な金額の最小値
	 */
	private static int getResult(final int n, final int m, final int x, final int[] c, final int[][] a,
			final int[] current, final int index) {
		boolean ok = true;
		for (int i = 0; i < m; i++) {
			if (current[i] < x) {
				ok = false;
				break;
			}
		}
		if (ok) {
			return 0;
		}
		if (index >= n) {
			return INF;
		}
		return Math.min(getResult(n, m, x, c, a, current, index + 1),
				getResult(n, m, x, c, a, add(current, a[index]), index + 1) + c[index]);
	}

	/**
	 * 配列aと配列bの和の配列を計算する
	 * 
	 * @param a 配列a
	 * @param b 配列b
	 * @return 配列aと配列bの和の配列
	 */
	private static int[] add(final int[] a, final int[] b) {
		int[] result = new int[a.length];
		IntStream.range(0, a.length).forEach(i -> result[i] = a[i] + b[i]);
		return result;
	}
}


Measured memory_bytes: 39536
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
namespace io{
    #define N 
    #define ll long long
    #define inf 0x3f3f3f3f
    #define il inline 
    #define in1(a) read(a)
    #define in2(a,b) in1(a),in1(b)
    #define in3(a,b,c) in2(a,b),in1(c)
    #define in4(a,b,c,d) in2(a,b),in2(c,d)
    il void readl(ll &x){
        x=0;ll f=1;char c=getchar();
        while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
        while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
        x*=f;
    }
    il void read(int &x){
        x=0;int f=1;char c=getchar();
        while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
        while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
        x*=f;
    }
}using namespace io;
int main(){
	double t,x;
	scanf("%lf%lf",&t,&x);
	printf("%lf",t/x);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;

int main()
{
    // 整数の入力
    ll n,x,t;
    cin >> n >> x >> t;
    cout << (n + x - 1)/x * t  << endl;
    return 0;
}

Measured memory_bytes: 3648
import java.util.*;

public class Main {

static class UnionFind {
    List<Integer> Parent;
    UnionFind(int N) {
        Parent = new ArrayList<Integer>();
        Integer[] values = new Integer[N];
        Arrays.fill(values, -1);
        Parent.addAll(Arrays.asList(values));
    }
    int root(int A) {
        if (Parent.get(A) < 0)
            return A;
        int root = root(Parent.get(A));
        Parent.set(A, root);
        return root;
    }
    int size(int A) {
        return -Parent.get(root(A));
    }

    boolean connect(int A, int B) {
        A = root(A);
        B = root(B);
        if (A == B) {
            return false;
        }

        if (size(A) < size(B)) {
            int temp = A;
            A = B;
            B = temp;
        }

        Parent.set(A, Parent.get(A) + Parent.get(B));
        Parent.set(B, A);

        return true;
    }
}

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int K = sc.nextInt();
        int[] A = new int[M];
        int[] B = new int[M];
        int[] C = new int[K];
        int[] D = new int[K];
        ArrayList<ArrayList<Integer>> friend = new ArrayList<ArrayList<Integer>>();
        ArrayList<ArrayList<Integer>> block = new ArrayList<ArrayList<Integer>>();
        for (int i=0;i<N;i++) {
            ArrayList<Integer> add = new ArrayList<Integer>();
            friend.add(add);
        }
        for (int i=0;i<N;i++) {
            ArrayList<Integer> add = new ArrayList<Integer>();
            block.add(add);
        }
        UnionFind uf = new UnionFind(N);
        for (int i=0;i<M;i++) {
            A[i] = sc.nextInt()-1;
            B[i] = sc.nextInt()-1;
            uf.connect(A[i], B[i]);
            friend.get(A[i]).add(B[i]);
            friend.get(B[i]).add(A[i]);
        }
        for (int i=0;i<K;i++) {
            C[i] = sc.nextInt()-1;
            D[i] = sc.nextInt()-1;
            block.get(C[i]).add(D[i]);
            block.get(D[i]).add(C[i]);
        }

        StringBuilder sb = new StringBuilder();
        for (int i=0;i<N;i++) {
            long ans = 0L;
            ans+=uf.size(i);
            int root = uf.root(i);
            HashSet<Integer> rem = new HashSet<Integer>();
            for (Integer j : friend.get(i)) {
                if (!rem.contains(j) && uf.root(j)==root) {
                    rem.add(j);
                    ans--;
                }
            }
            for (Integer j : block.get(i)) {
                if (!rem.contains(j) && uf.root(j)==root) {
                    rem.add(j);
                    ans--;
                }
            }
            sb.append(ans-1);
            if (i!=N-1) sb.append(" ");
        }
        System.out.println(sb);
    }
}

Measured memory_bytes: 192352
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
template<class T> void 
debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;
int n;
lint ar[100005];

int prm[3005],pcnt;

bool isprm(int a){
  for(int i=2;i*i<=a;++i) if(a%i==0) return false;
  return true;
}
typedef vector<pi> vp;
vp flip(const vp& a){
  vp res(a.size());
  REP(i,a.size()){
    res[i]=mp(a[i].fr,3-a[i].sc);
  }
  return res;
}

int main(){
  cin>>n;
  REP(i,n) scanf("%lld",&ar[i]);

  for(int i=2;i<=3333;++i) if(isprm(i)) prm[pcnt++]=i;

  int res=0;
  map<vp,int> app;
  REP(i,n){
    lint x=ar[i];
    vp fct;
    for(int j=0;j<pcnt && prm[j]<=x;++j) if(x%prm[j]==0){
      int cnt=0;
      while(x%prm[j]==0) x/=prm[j],++cnt;
      cnt%=3;
      if(cnt) fct.pb(mp(prm[j],cnt));
    }
    if(x>1){
      lint s=sqrt((double)x)+0.5;
      if(s*s==x || (s+1)*(s+1)==x || (s-1)*(s-1)==x) fct.pb(mp(s,2));
      else if(x<=100000 && isprm(x)) fct.pb(mp(x,1));
      else{
        ++res;
        continue;
      }
    }
    app[fct]++;
  }
  for(auto& e:app){
    vp f=flip(e.fr);
    if(f.empty()) ++res;
    else if(app.count(f)){
      if(f[0].sc==1){
        res+=max(app[f],e.sc);
      }
    }else res+=e.sc;
  }
  cout<<res<<endl;
  return 0;
}





Measured memory_bytes: 10368
#include <cstdio>
#include <algorithm>
using namespace std;

int main(){
  int N;
  scanf("%d",&N);
  int a[N];
  int i;
  int min,max,min_num=0,max_num=0;
  for(i=0;i<N;i++){
    scanf("%d",&a[i]);
    if(i==0){
      max=a[i];
      min=a[i];
    }
    else{
      if(a[i]<min){
	min=a[i];
	min_num=i;
      }
      if(a[i]>max){
	max=a[i];
	max_num=i;
      }
    }
  }
  printf("%d\n",2*N);
  int j;
  if(min+max>0){
    printf("%d %d\n",max_num+1,1);
    printf("%d %d\n",max_num+1,1);
    for(j=0;j<N-1;j++){
      printf("%d %d\n",j+1,j+2);
      printf("%d %d\n",j+1,j+2);
    }
  }
  else{
    printf("%d %d\n",min_num+1,N);
    printf("%d %d\n",min_num+1,N);
    for(j=0;j<N-1;j++){
      printf("%d %d\n",N-j,N-1-j);
      printf("%d %d\n",N-j,N-1-j);
    }
  }
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int n;
    cin >> n;
    int ans = 0;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n; i++){
        int b;
        cin >> b;
        ans += b;
    }
    int c[n-1];
    for(int i = 0; i < n; i++){
        cin >> c[i];
    }
    for(int i = 0; i < n - 1; i++){
        if(a[i] + 1 == a[i+1]){
            ans += c[a[i] - 1];
        }
    }
    cout << ans << endl;
}


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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "
#define fi first
#define se second

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

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;
}

ll modinv(ll a, ll mod){
  ll b=mod, u=1, v=0;
  while(b){
    ll t=a/b;
    a-=t*b; swap(a, b);
    u-=t*v; swap(u, v);
  }
  u%=mod;
  if(u<0)u+=mod;
  return u;
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}
/**************************************
** A main function starts from here  **
***************************************/
int main(){
  string s;
  cin >> s;
  ll ans = 0;
  rep(i, 4){
    ans += s[i]=='+'?1:-1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3596
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	var i int
	if sc.Scan() {
		if num, err := strconv.Atoi(sc.Text()); err == nil {
			i = num
		}
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	var set = map[int]bool{}
	var a = []int{}
	var n = nextInt()
	for i := 0; i < n; i++ {
		ai := nextInt()
		set[ai] = true
		a = append(a, ai)
	}
	if len(set) == len(a) {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound


signed main() {
    int N;
    cin >> N;
    cout << N * N * N << endl;
    return 0;
}


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

typedef int32_t i32;
typedef int64_t i64;
typedef double f64;

void *const null=(void *)0;
i64 const llinf=4611686018427387903LL;
i64 const mod=1000000009LL;
f64 const pi=3.141592653589793;
f64 const rad=57.295779513082323;

#define CODE_

i32 main(void){
    char *t=(char *)calloc(11LL,sizeof(char));
    scanf("%s%*c",t);
    i64 n;
    scanf("%lli%*c",&n);
    char *s=(char *)calloc(21LL,sizeof(char));
    i64 ans=0LL;
    for(i64 i=0LL;i<n;++i){
        scanf("%s%*c",s);
        for(i64 i=0LL;i<10LL;++i) s[i+10LL]=s[i];
        if(strstr(s,t)) ++ans;
    }
    printf("%lli\n",ans);
    return 0;
}



Measured memory_bytes: 2104
#define watch5(a,b,c,d,e) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d << " | "<<#e<<": "<<e<<endl;
#define watch4(a,b,c,d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define watch3(a,b,c) cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<endl;
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define sharingan cerr << "\n-------------------------------------------\n\n";
#define watch2(a,b) cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<< endl;
#define Yup ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define watch(a) cerr <<#a<<": "<<a<<endl;
#define __gcd(a, b) __algo_gcd(a, b)
#define PI 3.14159265358979323846
#define mod 1000000007
#include "bits/stdc++.h"
using namespace std;
#define int long long

int32_t main(){
    int n;
    cin >> n;
    int sum = 0;
    int ar[n];
    int br[n];
    for( int i = 0; i < n; i++ ){
        cin >> ar[i];
        br[i] = ar[i];
    }
    for( int i = n-2; i >= 0; i-- ){
        ar[i] += ar[i+1];
        ar[i] %= mod;
    }
    int ans = 0;
    for( int i = 0; i < n-1; i++ ){
        ans = (ans + (br[i]*ar[i+1])%mod)%mod;
    }
    cout << ans;
}

Measured memory_bytes: 6760
#define _GLIBCXX_DEBUG
#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()

void print_vec(vector<int> vec) {
  cout << "[";
  for (int i = 0; i < vec.size(); i++) {
    if (i) {
      cout << ", ";
    }
    cout << vec.at(i);
  }
  cout << "]...size: " << vec.size() << endl;
}

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

  if (x < y) {
    swap(x, y);
  }

  while (y > 0) {
    int r = x % y;
    x = y;
    y = r;
  }

  printf("%d\n", x);
}



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

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int n, K;
  cin >> n >> K;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  vector<bool> dp(K+5, false);
  for (int k = a[0]; k <= K; ++k) {
    bool win = false;
    rep(i,n) {
      if (k >= a[i]) {
        if (!dp[k-a[i]]) win = true;
      }
      else break;
    }
    dp[k] = win;
  }
  // rep(i,K+1) cout << dp[i] << " ";
  if (dp[K]) cout << "First" << endl;
  else cout << "Second" << endl;
  return 0;
}

Measured memory_bytes: 256
n,m = map(int ,input().split())
a = [list(map(int,input().split())) for i in range(n)]
b = set()
for i in range(n):
    a[i].pop(0)
b = set(a[0])
for i in range(n):
    c = set(a[i])
    b = b&c
print(len(list(b)))

Measured memory_bytes: 3064
import math

A, B, C, X, Y = map(int, input().split())

ans = A * X + B * Y

if (A + B) / 2 < C:
    pass
else:
    for i in range(max(X * 2, Y * 2)+1):
        j = max(0, X - int(i / 2))
        k = max(0, Y - int(i / 2))

        ans = min(ans, i * C + j * A + k * B)

print(ans)

Measured memory_bytes: 9096
from collections import deque
n, k = list(map(int, input().split()))
a = [0, ] + list(map(int, input().split()))
stack = deque([1, ])
visited = [0] * (n + 1)
hist = []
open = []
loop = []
while stack:
    now = stack.popleft()
    if visited[now] == 1:
        b = hist.index(now)
        open = hist[:b]
        loop = hist[b:]
        break
    next = a[now]
    visited[now] = 1
    hist.append(now)
    stack.append(next)
if k < len(open):
    print(open[k])
else:
    print(loop[(k - len(open)) % len(loop)])

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

int main() {
    int N;string S;cin >> N >> S;
    int R[N] = {};int G[N] = {};int B[N] = {};
    int Rsum = 0;int Gsum = 0;int Bsum = 0;
    for (int i = 0;i < N;i++){
        if (S[i] == 'R') Rsum++;
        else if (S[i] == 'G') Gsum++;
        else Bsum++;

        R[i] = Rsum;
        G[i] = Gsum;
        B[i] = Bsum;
    }
    ll sum = 0;
    for(int i = 0;i < N - 2;i++){
        for (int j = i + 1;j < N - 1;j++){
            if (S[i] == S[j]) continue;
            else{
                if (S[i] != 'G' && S[j] != 'G'){
                    sum += G[N - 1] - G[j];
                    if (S[j + j - i] == 'G') sum--;
                }
                if (S[i] != 'R' && S[j] != 'R'){
                    sum += R[N - 1] - R[j];
                    if (S[j + j - i] == 'R') sum--;
                }
                if (S[i] != 'B' && S[j] != 'B'){
                    sum += B[N - 1] - B[j];
                    if (S[j + j - i] == 'B') sum--;
                }
            }
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#define N 100005
using namespace std;
typedef long long ll;

ll n, q, a[N], k[N], sa[N], sb[N];
int main() {
	ll i, j, x, t;
	scanf("%lld%lld", &n, &q);
	for(i=1+n%2, j=0; j<n; i++, j++) scanf("%lld", &a[i]);
	n += n%2;
	for(i=1; i<=n/2; i++) k[i] = (a[i*2] + a[n/2+i])/2;
	for(i=1; i<=n; i++) sa[i] = sa[i-1] + a[i];
	for(i=1; i<=n; i++) sb[i] = sb[i-1] + (i%2 ? 0:a[i]);
	while(q--) {
		scanf("%lld", &x);
		t = lower_bound(k, k+n/2, x) - k;
		t = n/2 - t + 1;
		printf("%lld\n", sa[n] - sa[n-t] + sb[n-t*2]);
	}
	return 0;
}

Measured memory_bytes: 4480
ac,wa,tle,re = 0,0,0,0
n = int(input())
for i in range(n):
    s = input()
    if s=="AC": ac+=1
    if s=="TLE": tle+=1
    if s=="WA": wa+=1
    if s=="RE": re+=1
print("AC x",ac)
print("WA x",wa)
print("TLE x",tle)
print("RE x",re)

Measured memory_bytes: 9204
<?php
error_reporting(0);
$stdin = file_get_contents('php://stdin');
$line = explode("\n",$stdin);
$fi = 0;
$cnt = 0;
$list = array();
$key = new stdclass();
foreach($line as $l) {
  if (strlen($l)==0) continue;
  if ($fi == 0) {
    $a = explode(" ",$l);
    $key->A = $a;
    $fi++;
    continue;
  }
  if ($fi > 0) {
    $a = explode(" ",$l);
    $key->X[] = $a;
  }
}
$N = $key->A[0];
foreach($key->X as $v) {
  $X[]=$v[0];
}
$cnt=0;
$res=-1;
$pos=1;
while(1) {
  $pos = getNext($X,$pos);
  $cnt++;
  if ($pos == 2) {
    $res = $cnt;
    break;
  }
  if ($cnt > count($X)) {
    break;
  }
}
printf("%d\n",$res);

function getNext($X,$pos) {
  return $X[$pos-1];
}


Measured memory_bytes: 80116
while 1:
    a,b,c = map(int, input().split())
    if a == 0:
        break
    n = int(input())
    d = {}
    ans = [2]*(a+b+c)

    for _ in range(n):
        i, j, k, r = map(int, input().split())
        d[(i, j, k)] = r
        if r == 1:
            ans[i-1] = ans[j-1] = ans[k-1] = 1
    for i in d:
        if d[i] == 0:
            if ans[i[0]-1] == 1 and ans[i[1]-1] == 1:
                ans[i[2]-1] = 0
            elif ans[i[1]-1] == 1 and ans[i[2]-1] == 1:
                ans[i[0]-1] = 0
            elif ans[i[2]-1] == 1 and ans[i[0]-1] == 1:
                ans[i[1]-1] = 0
    for i in range(a+b+c):
        print(ans[i])



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

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

use std::cmp::{max, min};
use std::collections::HashMap;

fn main() {
  let x = read::<i64>();
  let mut ans = 0;
  for i in 0..x {
    let a = read::<i64>();
    let b = read::<i64>();
    ans += b - a + 1;
  }

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



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

int main(){
    string str;
    cin>>str;
    string ans;
    bool A=true;

    for(int i=0;i<str.size();i++){
        if(A&&str[i]=='A'){
            ans+='A';
            A=false;
        }
        else if(!A&&str[i]=='Z'){
            ans+='Z';
            A=true;
        }
    }

    if(ans.size()<2)cout<<-1<<endl;
    else cout<<ans.substr(0,ans.size()/2*2)<<endl;
    return 0;
}

Measured memory_bytes: 1184
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

const int MAX = 2e5 + 10;
int N;
LL A[MAX];

void naive() {
    int cnt = 0;
    REP(i, N) {
        FOR(j, i + 1, N) {
            if (abs(i - j) == A[i] + A[j]) {
                cnt++;
            }
        }
    }

    cout << cnt << endl;
}

int main(void) {
    cin >> N;
    REP(i, N) {
        cin >> A[i];
    }

    VI idx(N);
    iota(ALL(idx), 0);
    sort(ALL(idx), [&](const auto &l, const auto &r) {
        return A[l] - l < A[r] - r;
    });

    map<LL, int> cnt;
    LL ans = 0;
    FORE(i, idx) {
        ans += cnt[i + A[i]];
        cnt[i - A[i]]++;
    }

    cout << ans << endl;
}


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

int main() {
	stack<char> E;
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'B') {
			if (!E.empty())
				E.pop();
		} else {
			E.push(s[i]);
		}
	}
	vector<char> ans;
	while (!E.empty()) {
		ans.push_back(E.top());
		E.pop();
	}
	while (!ans.empty()) {
		cout << ans.back();
		ans.pop_back();
	}
	cout << endl;
	return 0;
}


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

#define REPI(i, n) for(int i = 0; i < n; i++)
#define REPJ(j, n) for(int j = 0; j < n; j++)

using ll = long long;
using namespace std;

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

    set<char> s;
    char c;
    while(cin >> c){
        s.insert(c);
    }
    auto itr = s.begin();

    for(int i = 0; i < 26; i++){
        if(*itr++ != 'a' + i){
            cout << char('a'+i);
            return 0;
        }
    }cout << "None";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const string EMP = " ";
const ll INF = 1LL<<60;
const ll MOD = 1000000007;
const double PI = acos(-1);

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

int main(){
  ll n,x; cin >> n >> x;
  ll xx; cin >> xx;
  ll ans = abs(xx - x);
  for(int i = 1; i < n; i++){
    cin >> xx;
    ans = gcd(ans, abs(xx - x));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);

using namespace std;
typedef long long int  ll;
typedef pair<int, int> P;


//lcm//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//a^n mod p//
ll modpow(ll a, ll n, ll p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / 2, p);
  return (t * t) % p;
}

//inversemod//
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];
// 
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//LARGE n
ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}
	return k;
}


////////////////////////////////////////////////////////////////////

int main() {
ll n;
cin>>n;
ll a[n+1];
ll sum=0;
rep(i, n){
	cin>>a[i];
	sum+=a[i];
}
sum/=2;

ll val=0;
for(int i=2;i<=n;i+=2){
val+=a[i];
}

ll c[n+1];
c[1]=sum-val;

for(int i=2;i<=n;i++){
	if(i==n){c[n]=a[n]-c[1];
break;
	}
c[i]=a[i-1]-c[i-1];
}


rep(i, n){
	if(i<=n-1) cout<<2*c[i]<<" ";
	if(i==n) cout<<2*c[n]<<endl;
}

return 0;



}




Measured memory_bytes: 2816
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
using namespace std;


signed main()
{
	int X, A;
	cin >> X >> A;
	if (X < A) cout << 0 << endl;
	else cout << 10 << endl;
}











Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().solve();
	}

	private void solve() throws IOException {
		try {
			//			solveA();
			solveB();
			//			 solveC();
			//			 solveD();
			//			 solveE();
			//			 solveF();
		} finally {
			if (in != null) {
				in.close();
			}
			if (out != null) {
				out.flush();
				out.close();
			}
		}

	}

	private void solveA() {
		int numA = nextInt();
		int numB = nextInt();

		if (numA % 3 == 0 || numB % 3 == 0 || (numA + numB) % 3 == 0) {
			out.println("Possible");
		} else {
			out.println("Impossible");
		}

	}

	private void solveB() {
		int numN = nextInt();
		int numK = nextInt();

		int[] wk = IntStream.range(0, numN).map(i -> nextInt()).toArray();

		Arrays.sort(wk);

		int res = IntStream.range(0, numN).filter(i -> i >= numN - numK).reduce(0, (sum, i) -> {
			sum += wk[i];
			return sum;
		});

		out.println(res);
	}

	private void solveC() {
		int numN = nextInt();

		out.println("");
	}

	private void solveD() {
		int numN = nextInt();

		out.println("");
	}

	private void solveE() {
		int numN = nextInt();

		out.println("");
	}

	private void solveF() {
		int numN = nextInt();

		out.println("");
	}

	private final PrintWriter out = new PrintWriter(System.out);
	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() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static 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 int nextInt() {
		return Integer.parseInt(next());
	}

	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 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: 26708
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val x = sc.nextInt()
  val y = sc.nextInt()

  for (i in 0..x) {
    val t = 2 * i
    val k = 4 * (x - i)
    if (t + k == y) {
      println("Yes")
      return
    }
  }

  println("No")

}


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

#define REP(i, n) for ( int i = 0; i < (n); i++ )

int bit[1<<26];

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  string s;
  cin >> s;

  int N = s.size();

  const int INF = 1e9;
  fill_n(bit, 1<<26, INF);
  bit[0] = 0;
  int now = 0;
  for ( int i = 0; i < N; i++ ) {
    now ^= (1<<(s[i]-'a'));
    for ( int j = 0; j < 26; j++ ) {
      int b = now ^ (1<<j);
      bit[now] = min(bit[now], bit[b]+1);
    }
  }

  cout << max(1, bit[now]) << endl;

  return 0;
}


Measured memory_bytes: 262804
MOD = 10**9 + 7

def fac(n):
    ans = 1
    for i in range(1, n + 1):
        ans = ans * i % MOD
    return ans

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

a, b = (2 * Y - X) // 3, (2 * X - Y) // 3
if (2 * X - Y) % 3 != 0 or a*b < 0:
    print(0)
else:
    print((fac(a + b) * pow(fac(a), MOD-2, MOD) * pow(fac(b), MOD-2, MOD)) % (10**9 + 7))

Measured memory_bytes: 62980
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }

long long f(long long x) {
  if (x % 4 == 0) return x;
  else if (x % 4 == 1) return 1;
  else if (x % 4 == 2) return x+1;
  else return 0;
}

int main() {
  long long a, b; cin>>a>>b;
  print(f(a-1)^f(b));

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>

using namespace std;

char s[100005];

int main() {
    scanf("%s",s);
    int len=strlen(s);
    if ((len&1)!=(s[0]==s[len-1])) printf("First\n"); else printf("Second\n");

    return 0;
}

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

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const ll Mod = 998244353LL;
const int Maxn = 2e5 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;

ll A[18];
map< pair<pll, pll>, ll> dp;

ll f(ll a, ll b, ll s, ll t){
	if(s == t - 1) return (a * A[s] + b * A[t]);
	if(dp.count({{a, b}, {s, t}})) return dp[ {{a, b}, {s, t}} ];
	ll mx = Inf;
	for(int i = s + 1; i < t; i++) mx = min(mx, f(a, a + b, s, i) + f(a + b, b, i, t) - (A[i] * (a + b)));
	return dp[{{a, b}, {s, t}}] = mx;
}

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n;
	cin >> n;
	for(int i = 0 ; i < n; i++) cin >> A[i];
	cout << f(1, 1, 0, n - 1);	
	return 0;
	
}

/*

                                 ____              ,----..               ,----..
   ,---,                       ,'  , `.           /   /   \             /   /   \
  '  .' \                   ,-+-,.' _ |          /   .     :           /   .     :
 /  ;    '.              ,-+-. ;   , ||         .   /   ;.  \         .   /   ;.  \
:  :       \            ,--.'|'   |  ;|        .   ;   /  ` ;        .   ;   /  ` ;
:  |   /\   \          |   |  ,', |  ':        ;   |  ; \ ; |        ;   |  ; \ ; |
|  :  ' ;.   :         |   | /  | |  ||        |   :  | ; | '        |   :  | ; | '
|  |  ;/  \   \        '   | :  | :  |,        .   |  ' ' ' :        .   |  ' ' ' :
'  :  | \  \ ,'        ;   . |  ; |--'         '   ;  \; /  |        '   ;  \; /  |
|  |  '  '--'          |   : |  | ,             \   \  ',  /          \   \  ',  /
|  :  :                |   : '  |/               ;   :    /            ;   :    /
|  | ,'                ;   | |`-'                 \   \ .'              \   \ .'
`--''                  |   ;/                      `---`                 `---`
                       '---'

*/


Measured memory_bytes: 20608
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T> bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
    for (int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
    for (auto &e : t) {
        fill_v(e, v);
    }
};
struct edge {
    ll to, cst;
    bool operator<(const edge &e) const { return cst < e.cst; }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m, k;
    cin >> n >> m >> k;
    vector<ll> p(n), c(n), j(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        --c[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> j[i];
    }
    vector<vector<edge>> G(n);
    for (int i = 0; i < m; i++) {
        int u, v, t;
        cin >> u >> v >> t;
        --u;
        --v;
        G[u].emplace_back(edge{v, t});
        G[v].emplace_back(edge{u, t});
    }
    priority_queue<P, vector<P>, greater<P>> q;
    vector<ll> d1(n, LINF), dp(n);
    d1[0] = 0;
    q.push(P(0, 0));
    while (!q.empty()) {
        P p = q.top();
        q.pop();
        int v = p.second;
        if (d1[v] < p.first) {
            continue;
        }
        for (auto &e : G[v]) {
            if (chmin(d1[e.to], d1[v] + e.cst)) {
                q.push(P(d1[e.to], e.to));
            }
        }
    }
    for (int i = 0; i < n; i++) {
        dp[i] = d1[i] - p[i];
        q.push(P(dp[i], i));
    }
    while (!q.empty()) {
        P p = q.top();
        q.pop();
        int v = p.second;
        if (dp[v] < p.first) {
            continue;
        }
        for (auto &e : G[v]) {
            if (chmin(dp[e.to], dp[v] + e.cst)) {
                q.push(P(dp[e.to], e.to));
            }
        }
    }
    vector<ll> res(k, -LINF);
    for (int i = 0; i < n; i++) {
        chmax(res[c[i]], j[i] - d1[i] - dp[i]);
    }
    for (int i = 0; i < k; i++) {
        cout << res[i] << endl;
    }
}



Measured memory_bytes: 21556
import math
import numpy as np
from fractions import gcd
import fractions
import statistics
import collections
from functools import reduce
import itertools
from collections import defaultdict

N,M=map(int, input().split())

ans = defaultdict(int)
wa = defaultdict(int)
for i in range(M):
    P,S = map(str, input().split())
    if (S == 'AC'):
        ans[P] = 1
    else:
        if (ans[P] != 1):
            wa[P] +=1

wa_cnt = 0
for k, v in wa.items():
    if ans[k] == 1:
        wa_cnt += v
val = ans.values()
print(list(val).count(1),wa_cnt)  

Measured memory_bytes: 27820
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;

namespace CSharpSpiral {
	class Program {
		static void Main(string[] args) {
			var sw = new StreamWriter(Console.OpenStandardOutput()) {
				AutoFlush =
#if DEBUG
			true
#else
			false
#endif
			};
			Console.SetOut(sw);
			new Program().Solve(new ConsoleInput(
#if DEBUG
			new StreamReader("../../../inputData.txt")
#else
			Console.In
#endif
			, ' '));
			Console.Out.Flush();
		}
		public void Solve(ConsoleInput cin) {
			while(true) {
				var cards = cin.ReadLine.Split(' ').Select(int.Parse).ToArray();
				if(cards[0] == 0) break;
				var aceC = cards.Count(x => x == 1);
				var notAce = cards.Where(x => x != 1).Sum(x => x > 10 ? 10 : x);
				if(notAce > 21) { Console.WriteLine(0); continue; }
				int[] acePoint = { 0 };
				if(aceC > 0) acePoint = Enumerable.Range(0, aceC + 1).Select(i => i + 11 * (aceC - i)).ToArray();
				var finalPoints = acePoint.Select(x => x + notAce).Where(x => x <= 21); ;
				var res = finalPoints.Any() ? finalPoints.Max() : 0;
				Console.WriteLine(res);
			}
		}
	}
	static class ExtendClass {
		public static string Join<T>(this IEnumerable<T> X, string separator = " ") => string.Join(separator, X);
		
	}
	class ConsoleInput {
		private readonly TextReader _stream;
		private readonly char _separator = ' ';
		private readonly Queue<string> inputStream;
		public ConsoleInput(TextReader stream, char separator = ' ') {
			this._separator = separator;
			this._stream = stream;
			inputStream = new Queue<string>();
		}
		public string Read {
			get {
				if(inputStream.Count != 0) return inputStream.Dequeue();
				string[] tmp = _stream.ReadLine().Split(_separator);
				for(int i = 0; i < tmp.Length; ++i)
					inputStream.Enqueue(tmp[i]);
				return inputStream.Dequeue();
			}
		}
		public string ReadLine { get { return _stream.ReadLine(); } }
		public int ReadInt { get { return int.Parse(Read); } }
		public long ReadLong { get { return long.Parse(Read); } }
		public double ReadDouble { get { return double.Parse(Read); } }
		public string[] ReadStrArray(long N) {
			var ret = new string[N];
			for(long i = 0; i < N; ++i)
				ret[i] = Read;
			return ret;
		}
		public int[] ReadIntArray(long N) { var ret = new int[N]; for(long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
		public long[] ReadLongArray(long N) { var ret = new long[N]; for(long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
		public double[] ReadDoubleArray(long N) { var ret = new double[N]; for(long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; }
		public bool isEOF {
			get { return _stream.Peek() == -1; }
		}
	}

}



Measured memory_bytes: 16836