akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int ll;
int main(){
  ll n,k;
  cin >>n>>k;
  ll h[n],ans=1e10;
  for(ll i=0;i<n;i++) cin >>h[i];
  sort(h,h+n);
  for(ll i=0;i<=n-k;i++){
    ans=min(ans,h[i+k-1]-h[i]);
  }
  cout <<ans<<endl;
  return 0;
}


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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int n; cin >> n;
  vector<string> s(n); rep(i,n) cin >> s[i];

  map<string,ll> mp;
  
  rep(i,n){
    sort(s[i].begin(),s[i].end());
    string t = s[i];
    mp[t]++;
  }

  ll ans = 0;
  for(auto x : mp){
    ll tmp = x.second*(x.second-1)/2;
    if(x.second > 1) ans += tmp;
  }
  cout << ans << endl;
  
  return 0;
}


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

using namespace std;

int main(){
	int i=2,j=2,X,m=1;
	cin >> X;
	while(i*i<X){
		if(X >= pow(i,j)){
			if(pow(i,j) >= m){
				m=pow(i,j);
			}
			j++;
		}else{
			i++;j=2;
		}
	}
	cout << m << endl;
	return 0;
}

Measured memory_bytes: 256
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long int ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << 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;

int main()
{
    ll N;
    cin >> N;
    vector<ll> v(N);
    rep(i, N) cin >> v[i];
    sort(all(v));
    reverse(all(v));
    ll A , B;
    A = 0; B = 0;
    bool flag = false;
    rep(i, N) {
        if (!flag) {
            A += v[i];
        } else {
            B += v[i];
        }
        flag = !flag;
    }
    print(A-B);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<long> A(N);
  for (int i=0;i<N;i++) {
    cin >> A.at(i);
  }
  
  sort(A.begin(), A.end());
 
  int count=0, a;
  bool unfinished = true;
  while (A.at(N-2) != 1) {
    int count0=0;
    for (int i=count+1;i<N;i++) {
      A.at(i) = A.at(i) % A.at(count);
      if (A.at(i) == 0) {
        count0++;
      }
    }
    sort(A.begin(), A.end());
    if (count0 == N-count-1) {
      cout << A.at(N-1) << endl;
      unfinished = false;
      break;
    }
    count += count0;
  }
  
  if (unfinished) {
    cout << 1 << endl;
  }
}

Measured memory_bytes: 1024
k,s = map(int,input().split())

ans = 0

for i in range(k+1):
    for j in range(i,k+1):
        c = s-i-j
        if k >= c and c >=j:
            if i == j and j == c:
                ans += 1
            elif i!=j and j!=c and c!=j:
                ans += 6
            else:
                ans += 3
        
print(ans)

Measured memory_bytes: 3064
import sys
def input():
    return sys.stdin.readline()[:-1]

import collections
def main():
    N = int(input())
    s = [input() for i in range(N)]
    c = collections.Counter(s)
    print('AC x ' + str(c['AC']))
    print('WA x ' + str(c['WA']))
    print('TLE x ' + str(c['TLE']))
    print('RE x ' + str(c['RE']))

    
if __name__ == "__main__":
    main()

Measured memory_bytes: 16620
H,W = map(int,input().split())
N = int(input())
A = list(map(int,input().split()))
check = []

for i,v in enumerate(A):
    check += [i + 1] * v

for i in range(H):
    if i % 2 ==0:
        print(*check[i*W:(i+1)*W])
    else:
        print(*check[i*W:(i+1)*W][::-1])

Measured memory_bytes: 9420
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;

int main(){
    int a,b,c;
    string s1,s2,s3;
    cin >> s1 >> s2 >> s3;
    if(s1[s1.size()-1] == s2[0]&& s2[s2.size()-1] == s3[0]) 
        cout << "YES"<< endl;
    else
        cout << "NO"<< endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int a, b, c, x, y;
    int total1, total2, total3;
    scanf("%d%d%d%d%d", &a, &b, &c, &x, &y);
    total1 = a * x + b * y;
    if(x > y){
        total2 = 2 * y * c + (x - y) * a;
        total3 = 2 * x * c;
    }
    else{
        total2 = 2 * x * c + (y - x) * b;
        total3 = 2 * y * c;
    }
    if(total1 < total2 && total1 < total3)
        printf("%d\n", total1);
    else{
        if(total2 < total3)
            printf("%d\n", total2);
        else
            printf("%d\n", total3);
    }
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
string s,t;

int LCS(vector<vector<int>> &dp,vector<vector<int>> &pi,int x,int y){
	if(x<0||y<0)
		return 0;
	if(dp[x][y]!=-1)
		return dp[x][y];
	if(s[x]==t[y]){
		pi[x][y]=1;
		dp[x][y]=LCS(dp,pi,x-1,y-1)+1;
	}
	else{
		int i=LCS(dp,pi,x-1,y);
		int j=LCS(dp,pi,x,y-1);
		if(i>=j){
			pi[x][y]=2;
			dp[x][y]=i;
		}
		else{
			pi[x][y]=3;
			dp[x][y]=j;
		}
	}
	return dp[x][y];
}

string LCSstring(vector<vector<int>> &pi){
	string ans;
	int x=s.size()-1;
	int y=t.size()-1;
	while(x>=0&&y>=0){
		if(pi[x][y]==1){
			ans+=s[x];
			x--;y--;
		}
		else if(pi[x][y]==2){
			x--;
		}
		else if(pi[x][y]==3){
			y--;
		}
	}
	reverse(ans.begin(),ans.end());
	return ans;
}

int main(){
	cin>>s>>t;
	vector<int> sdp(t.size(),-1);
	vector<vector<int>> dp(s.size(),sdp);
	vector<vector<int>> pi=dp;
	int f=LCS(dp,pi,s.size()-1,t.size()-1);
	cout<<LCSstring(pi)<<endl;
	return 0;	
}

Measured memory_bytes: 71296
#include<stdio.h>
int main(){
	int n,m,a[1001],b[1001];
	int i,j,ct,k=0;
	int yu,se;
	scanf("%d %d",&n,&m);
	for(i=1;i<=m;i++){
		scanf("%d%d",&a[i],&b[i]);
		if(n<=a[i])a[i]=b[i]=-1;
	}
	for(i=1;i<=m;i++){
		if(a[i]==-1)ct++;
	}
	if(ct>=m-1){
		printf("%d\n",k);
	}
	else{
		for(i=1;i<=m;i++){
			for(j=i+1;j<=m;j++){
				if(a[i]<a[j]){
					yu=a[i];
					a[i]=a[j];
					a[j]=yu;
				}
			}
		}
		m=m-1;
		yu=m-ct;
		for(i=1;i<=yu;i++){
			se=n-a[i];
			k=k+se;
		}
		printf("%d\n",k);
	}
	return 0;
}



Measured memory_bytes: 2024
use std::cmp::max;

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
//usage
//input! {
//  h: i32;
//  v: [i32; n]
//  x: [[i32; n]; m]
//  f: chars <- Vec<char>
//}

fn main() {
    input! {
        q: usize,
        str: [(chars, chars); q]
    }

    // dp[i][j] = str1のi文字目までとstr2のj文字目までの共通部分列の最大値
    // dp[i][j] = max(dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1])

    for (l, r) in str {
        let llen = l.len();
        let rlen = r.len();

        let mut dp = vec![vec![0; llen + 1]; rlen + 1];

        for i in 0..rlen as usize {
            for j in 0..llen as usize {
                if r[i] == l[j] {
                    dp[i + 1][j + 1] = dp[i][j] + 1;
                } else {
                    dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
                }
            }
        }
        println!("{}", dp[rlen][llen]);
    }
}


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

#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint=vector<int>;
using vvint=vector<vint>;
using pint=pair<int, int>;
using vpint=vector<pint>;
template<typename T> using priority_queue_rev=priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028L;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T1, typename T2> bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> bool chmin(T1 &a, const T2 &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N, K;
string S;
signed main() {
    cin >> N >> S >> K;
    rep(i, N) { if (S[i] != S[K - 1]) { S[i] = '*'; }}
    cout << S << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
 
int main() {
  
  int N,X,Y;
  cin >> N >> X >> Y;

  vector<vector<int>> d(N+1,vector<int>(N+1,0));
  
  for(int i = 1;i <= N;i++) {
    for(int j = 0;j <= N;j++) {
      d[i][j] = abs(i-j);
    }
  }

  for(int i = 1;i < N;i++) {
    if(Y > i) {
      d[i][Y] = min(d[i][Y],d[i][X]+1);
    }

    if(Y > i) {
      for(int j = Y;j < N;j++) {
        d[i][j+1] = min(d[i][j+1],d[i][j]+1);
      }

      for(int j = Y;j > i;j--) {
        d[i][j-1] = min(d[i][j-1],d[i][j]+1);
      }
    }
    for(int j = 0;j < i;j++) d[i][j] = 0;
  }


  for(int i = 1;i <= N;i++) {
    sort(d[i].begin(),d[i].end());
  }

  for(int i = 1;i <= N-1;i++) {
    int sum = 0;
    for(int j = 1;j < N;j++) {
      sum += upper_bound(d[j].begin()+j+1,d[j].end(),i) - lower_bound(d[j].begin()+j+1,d[j].end(),i);
    }
    cout << sum << endl;
  }

  



  
}


Measured memory_bytes: 16000
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <limits>
#include <ios>
#include <iomanip>
#include <stdio.h>
#include <iomanip>
using namespace std;

#define rep(i,N) for(int i=0; i<N; i++)
#define revrep(i,N) for(int i=N-1; i>=0; i--)
#define coutline cout<<"------------ ("<<__LINE__<<")"<<endl;

typedef long long ll;
ll gcd(ll a, ll b);

int main(void)
{
    int N,K;
    cin >> N >> K;

    ll bunbo = 1;
    ll bunshi = 0;
    for (int i = 1; i <= N; i++) {
        ll r = 1;
        
        if (i < K) {
            ll j = i;
            while(j < K) {
                j *= 2;
                r *= 2;
            }
        }
        r *= N;
        
        bunshi = r*bunshi + bunbo;
        bunbo = bunbo*r;

        ll u = gcd(bunshi, bunbo);
        bunbo /= u;
        bunshi /= u;
        int temp;
    }

    long double ret = (long double)bunshi/bunbo;
    cout << std::setprecision(20) << ret << endl;

    return 0;
}

/* _a < _b */
ll gcd(ll a, ll b)
{
    if (a == 0) return b;

    ll c = b % a;
    return gcd(c, a);
}


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

using namespace std;

char f(char x){
  const static int all = 'Z' - 'A' + 1;
  return (x - 'A' + all - 3) % all + 'A';
}

int main(){
  string str;
  while(cin >> str){
    transform(str.begin(), str.end(), str.begin(), &f);
    cout << str << endl;
  }
  return 0;
}

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

int main(){
    string s;
    cin >> s;
    int count = 0;
    if(s[0] == '1') ++count;
    if(s[1] == '1') ++count;
    if(s[2] == '1') ++count;
    cout << count <<endl;
    return 0;
}


Measured memory_bytes: 256
from sys import stdin
import numpy as np
def main():
    #入力
    readline=stdin.readline
    n,k=map(int,readline().split())
    a=np.array(readline().strip().split(),dtype="int64")
    
    a.sort()
    neg=a[a<0]
    neg_p=neg**2
    zero=a[a==0]
    pos=a[a>0]
    pos_p=pos**2
    l=-10**18-1
    r=10**18
    while l<r-1:
        x=(l+r)//2
        cnt=0
        if neg.size>0:
            cnt+=(a.size-np.searchsorted(a,(x+neg+1)//neg)).sum()
            cnt-=neg_p[neg_p<=x].size
        if zero.size>0:
            if x>=0:
                cnt+=(a.size-1)*zero.size
        if pos.size>0:
            cnt+=np.searchsorted(a,x//pos,side="right").sum()
            cnt-=pos_p[pos_p<=x].size

        cnt//=2
        if cnt>=k: r=x
        else: l=x

    print(r)

if __name__=="__main__":
    main()

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

using namespace std;

typedef pair<string, string> P;
typedef pair<string, int> S;

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

	int n;
	while (cin >> n, n)
	{
		vector<P> v(n);
		for (int i = 0; i < n; i++)
		{
			string a, b;
			cin >> a >> b;
			v[i] = P(a, b);
		}
		string c, d;
		cin >> c >> d;
		queue<S> q;
		q.push(S(c, 0));
		bool flag = false;
		while (!q.empty())
		{
			S next = q.front();
			q.pop();
			string st = next.first;
			int cnt = next.second;
			if (st == d)
			{
				cout << cnt << endl;
				flag = true;
				break;
			}
			if (st.length() > d.length())
				continue;
			for (int i = 0; i < n; i++)
			{
				string from = v[i].first, to = v[i].second;
				string str = st;
				string::size_type pos = str.find(from);
				while (pos != string::npos)
				{
					str.replace(pos, from.size(), to);
					pos = str.find(from, pos + to.size());
				}
				if (str == st)
					continue;
				q.push(S(str, cnt + 1));
			}
		}
		if (!flag)
			cout << -1 << endl;
	}
}



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

#define ll long long int
#define ull unsigned long long int
#define Max 1000005
#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ALL(x) x.begin(),x.end()
#define pi acos(-1.0)
#define pb push_back
#define load(array,size)  for(ll i=0 ; i<size ; i++) cin>>array[i] ;
#define endl '\n'

#define sc(n) scanf("%d",&n)
#define scan(n) scanf("%lld",&n)
/*        speed up       */
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define sci(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define load1(array,size)  for(ll i=1 ; i<=size ; i++) cin>>array[i] ;
#define INF    1LL<<19
#define pll pair<ll,ll>
#define mst(arr,value) memset(arr,value,sizeof(arr));
#define tst() _fastio;int testsalam;cin >> testsalam;while(testsalam--)
#define Mod 100000007
#define YES cout<<"Yes"<<endl;
#define NO cout<<"No"<<endl;

//void inversemod(ll n, ll mod, ll invmod[],ll MOD){for(int i=2; i<=n; ++i) invmod[i]=MOD-MOD/i*invmod[MOD%i]%MOD;}
//void bigmod( ll a, ll b ,ll mod){ll r = 1;a = a%mod;while(b){if( b%2 ) r = (r*a)%mod;b = b/2;a = (a*a)%mod; }return (ll)r;}
string inttostr(ll n){std::stringstream ss;ss << n;string out=ss.str();return out;}
ll stringtoint(string s){istringstream iss (s);ll n;iss >> n;return n;}
template <typename T> T gcd(T a,T b){if(a < 0)return gcd(-a,b);if(b < 0)return gcd(a,-b);return (b == 0)?a:gcd(b,a%b);}
template <typename T> T lcm(T a,T b) {if(a < 0)return lcm(-a,b);if(b < 0)return lcm(a,-b);return a*(b/gcd(a,b));}
typedef vector<ll>vec;
typedef pair<ll,ll> pii;
typedef map<ll,ll>mpll;
typedef set<ll>seet;
typedef tuple<ll,ll,ll>tpl;

int main()
{
    int n;
    cin >> n;
    map<string ,int>mp;
    for (int i = 0; i < n; ++i)
    {
    	string s;
    	cin>> s;
    	mp[s]++;
    }
    cout<<"AC x "<<mp["AC"]<<endl;
    cout<<"WA x "<<mp["WA"]<<endl;
    cout<<"TLE x "<<mp["TLE"]<<endl;
    cout<<"RE x "<<mp["RE"]<<endl;
}
/*
     remember:
     ll vs int
     array size
     case for 1 2 3 
*/



Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define F first
#define S second
#define INF 1 << 30

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int w, h;
int board[20][20];
int dx[] = {0,-1,0,1}, dy[] = {-1,0,1,0};

int dfs(int y, int x, int c){
  int ret = INF;
  if(c >= 10) return ret;
  rep(d, 4){
    int ny = y+dy[d], nx = x+dx[d];
    if(ny < 0 || nx < 0 || ny >= h || nx >= w) continue;
    if(board[ny][nx] == 1) continue;
    if(board[ny][nx] == 3) return c+1;
    while(true){
      ny += dy[d]; nx += dx[d];
      if(ny < 0 || nx < 0 || ny >= h || nx >= w) break;;
      if(board[ny][nx] == 3) return c+1;
      if(board[ny][nx] == 1){
	board[ny][nx] = 0;
	ret = min(ret, dfs(ny-dy[d], nx-dx[d], c+1));
	board[ny][nx] = 1;
	break;
      }
    }
  }
  return ret;
}

int main(){
  while(scanf("%d%d", &w, &h) && w+h){
    rep(i, h) rep(j, w) scanf("%d", &board[i][j]);
    int y, x;
    rep(i, h) rep(j, w) if(board[i][j] == 2) y = i, x = j;
    board[y][x] = 0;
    int res = dfs(y, x, 0);
    printf("%d\n", res==INF?-1:res);
  }
  return 0;
}

Measured memory_bytes: 1188
#include<cstdio>
using namespace std;
const char N_MAX = 105;
int INF = 1<<30;
int dp[N_MAX][N_MAX];
char matrix[N_MAX];
int n;
int solve() {
    for(char offset = 1; offset < n; offset++) {
        for(char c = 1, r = c + offset; r <= n; c++, r++) {
            dp[c][r] = INF;
            for(char divid = 1; divid <= offset; divid ++) {
                int newValue = dp[c][c - 1 + divid] + dp[c + divid][r] + matrix[c - 1] * matrix[r] * matrix[c + divid - 1];
                if(newValue < dp[c][r])
                    dp[c][r] = newValue;
            }
        }
    }
    return dp[1][n];
}
int main(){
    scanf("%d", &n);
    for(char i=0;i<n;i++) scanf("%d %d", &matrix[i], &matrix[i+1]);
    printf("%d\n", solve());
    return 0;
}



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

int main()
{
	int input_number;
	cin >> input_number;
	int plan_t[input_number + 1];
	int plan_x[input_number + 1];
	int plan_y[input_number + 1];

	plan_t[0] = 0;
	plan_x[0] = 0;
	plan_y[0] = 0;


	for(int i = 1; i <= input_number; i++){
		cin >> plan_t[i] >> plan_x[i] >> plan_y[i];
	}

	bool ans = true;
	int length;
	for(int i = 0; i < input_number; i++){
		length = abs(plan_x[i+1] - plan_x[i]) + abs(plan_y[i+1] - plan_y[i]);
		if((plan_t[i+1] - plan_t[i]) < length || (length - (plan_t[i+1] - plan_t[i])) % 2 != 0){
			ans = false;
			break;
		}
	}

	if(ans){
		cout << "Yes\n";
	}else{
		cout << "No\n";
	}

	return 0;
}


Measured memory_bytes: 1408
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var N = Sarray()[0];
            var Xi = Sarray();
            long min = 100 * 100 * 100;
            for (var j = 1; j <= 100; ++j)
            {
                long sum = 0;
                for (var i = 0; i < Xi.Count(); ++i)
                {
                    sum += (j - Xi[i]) * (j - Xi[i]);
                }
                min = Math.Min(sum, min);
            }
            WriteLine(min);
            //Out.Flush();
        }
    }
}

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

char rot(char c, int n) { return ((c - 'A' + n) % 26 + 'A'); }

int main() {
    string s;
    int n;
    cin >> n >> s;
    for (int i = 0; i < s.size(); i++) {
        s[i] = rot(s[i], n);
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380


int main() {
    cout << fixed << setprecision(10);
    int N,M;
    cin >> N>>M;

    vector<int> v(N,-1);
    
    REP(i, M) {
        int s, c;
        cin >> s >> c;

        s--;
        if (N <= s) {
            cout << -1;
            return 0;
        }
        if (s == 0 && c == 0&& N != 1) {
            cout << -1;
            return 0;
        }
        if (v[s] == -1 || v[s] == c) {
            v[s] = c;
        }
        else {
            cout << -1;
            return 0;
        }
    }

    if (N == 1&&v[0]<=0) {
        cout << 0;
        return 0;
    }

    REP(i, N) {
        if (v[i] == -1) {
            if (i == 0) {
                v[i] = 1;
            }
            else {

            v[i] = 0;
            }
        }
        cout << v[i];
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define INF 1001001001

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;


vector<int> ar;
vector<int> br;
vector<int> to[200005];
vector<int> to2[200005];

void dfs(int v){
  for(int u: to[v]){
    if(ar[u])continue;
    ar[u]=ar[v];
    dfs(u);
  }
}

void dfs2(int v){
  for(int u: to2[v]){
    if(br[u])continue;
    br[u]=br[v];
    dfs2(u);
  }
}

int main(){
  int n, k, l, a, b;
  cin >> n >> k >> l;
  ar.resize(n);
  br.resize(n);
  rep(i, k){
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  rep(i, l){
    cin >> a >> b;
    --a; --b;
    to2[a].push_back(b);
    to2[b].push_back(a);
  }
  int cnt=1;
  rep(i, n){
    if(ar[i])continue;
    ar[i]=cnt;
    cnt++;
    dfs(i);
  }
  cnt=1;
  rep(i, n){
    if(br[i])continue;
    br[i]=cnt;
    cnt++;
    dfs2(i);
  }
  map<P, int> M;
  rep(i, n){
    M[P(ar[i], br[i])]++;
  }
  rep(i, n){
    cout << M[P(ar[i], br[i])] << endl;
  }
  return 0;
}


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

int n,x,hitung,dp[112],l[121];
int main(){
	cin >> n>> x;
	dp[0] = 0;
	l[0] = 0;
	hitung = 1;
	for(int i = 1; i <= n; i++){
		cin >> l[i];
		dp[i] = dp[i-1] + l[i];
		if(dp[i] <= x){
			hitung += 1;
		}
	}
	cout << hitung << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;


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

	string N;
	cin >> N;
	int a, b, c, d;
	a = (int)N[0]-48;
	b = (int)N[1]-48;
	c = (int)N[2]-48;
	d = (int)N[3]-48;
	string ans;
	rep(i, 8) {
		int t = 0;
		if ((i & 1) == 1) {
			t = a + b;
		}
		else {
			t = a - b;
		}
		if ((i & 2) == 2) {
			t += c;
		}
		else {
			t -= c;
		}
		if ((i & 4) == 4) {
			t += d;
		}
		else {
			t -= d;
		}

		if (t == 7) {
			ans += N[0];
			if ((i & 1) == 1) {
				ans += '+';
			}
			else {
				ans += '-';
			}
			ans += N[1];
			if ((i & 2) == 2) {
				ans += '+';
			}
			else {
				ans += '-';
			}
			ans += N[2];
			if ((i & 4) == 4) {
				ans += '+';
			}
			else {
				ans += '-';
			}
			ans += N[3];
			ans += "=7";
			break;
		}
	}
	cout << ans << endl;


	return 0;
}

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

using namespace std;

#define ll long long
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef set<int> si;
typedef set<vi> svi;
typedef set<ll> sll;
typedef set<vll> svll;
typedef set<pii> spii;
typedef set<vpii> svpii;
typedef set<pll> spll;
typedef set<vpll> svpll;
typedef vector<si> vsi;
typedef vector<sll> vsll;
typedef vector<spii> vspii;
typedef vector<spll> vspll;
#define ft first
#define sc second
#define pb push_back
#define ins insert
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define all(v) v.begin(),v.end()
#define Sort(v) sort(all(v))
#define sortarr(a,n) sort(a,a+n)
#define tt ll tc; cin >> tc; while(tc--)
#define rep(var,start,end,interval) for(ll var=start;(interval>0 and var<end) or (interval<0 and var>end);var+=interval)
#define each(x,v) for(auto x : v)
#define takearr0(a,n) rep(z,0,n,1) cin >> a[z];
#define takearr1(a,n) rep(z,1,n+1,1) cin >> a[z];

int main()
{
	io;
	ll x;
	cin >> x;
	if(x >= 30)
		cout << "Yes\n";
	else
		cout << "No\n";
	return 0;
}

Measured memory_bytes: 3608
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    a,b,c,n = [int(x) for x in input().split()]
    d = [0] * 10000
    d[0] = 1
    for i in range(0,5000):
        d[i + a] += d[i]
    for i in range(0,5000):
        d[i + b] += d[i]
    for i in range(0,5000):
        d[i + c] += d[i]

    print(d[n])
    

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

1 + k



"""


Measured memory_bytes: 9536
import heapq

N, M = list(map(int, input().split()))
baito = []
for i in range(N):
	baito.append(list(map(int, input().split())))

baito.sort()
m = [0]*(M+1)
kouho = []
num = 0
x = 0
for day in range(M + 1):
	while True:
		if x >= N or baito[x][0] > day:
			break
		else:
			heapq.heappush(kouho, -baito[x][1])
			x+=1
	if len(kouho) > 0:
		num -= heapq.heappop(kouho)

print(num)

Measured memory_bytes: 74968
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e9;
const long long MOD = 1e9+7;
using Graph = vector<vector<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;}

// 0 false, 1 true 
// string to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

struct PrimeNumber
{
    //O(sqrt(n))
    bool is_prime(long long n){
        for(long long i = 2; i * i <= n; i++){
            if(n % i == 0) return false;
        }
        return n != 1;
    }

    //O(sqrt(n))  isn't sorted
    vector<long long> divisor(long long n){
        vector<long long> res;
        for(long long i = 1; i * i <= n; i++){
            if(n % i == 0){
                res.push_back(i);
                if(i != n / i) res.push_back(n / i);
            }
        }
        return res;
    }

    //O(sqrt(n))
    map<long long, long long> prime_factor(long long n){
        map<long long, long long> res;
        for(long long i = 2; i * i <= n; i++){
            while(n % i == 0){
                n /= i;
                res[i]++;
            }
        }
        if(n != 1) res[n] = 1;
        return res;
    }

    //O(n log log n)
    map<ll,ll> eratosthenes(long long n){
        map<ll,ll> prime;
        vector<bool> is_prime(n + 1, true);
        long long p = 0;
        is_prime[0] = false; is_prime[1] = false;
        for(long long i = 2; i <= n; i++){
            if(is_prime[i]) prime[i]++;
            for(long long j = 2 * i; j <= n; j += i) is_prime[j] = false;
        }
        return prime;
    }
};

int main() {
    std::cout << std::fixed << std::setprecision(15);
    PrimeNumber prime;
    //map<ll,ll> p = prime.eratosthenes(100000000);
    ll n; cin >> n;
    ll ans = 0;
    rep(i, n){
        ll tmp; cin >> tmp;
        if(prime.is_prime(tmp)){
            ans++;
        }
        /*
        if(p.count(tmp) >= 1){
            ans++;
        }
        */
    }
    cout << ans << endl;

}


Measured memory_bytes: 3084
io = STDIN
a,b=[],[]
amax=0
n,h=io.gets.split.map(&:to_i)
n.times do
  aa,bb=io.gets.split.map(&:to_i)
  a << aa
  amax=[aa,amax].max
  (b << bb) if amax<bb
end
def calc(a,b,h,amax)
  sum=0
  cnt=0
  b.sort_by{|i|-i}.each do |bb|
    next if bb<=amax
    sum+=bb
    cnt+=1
    if sum>=h
      return cnt
    end
  end
  return ((h-sum).to_f/amax).ceil+cnt
end
puts calc(a,b,h,amax)


Measured memory_bytes: 6620
#include <iostream>

using namespace std;

int main()
{
    int N;
    int d[110];
    cin >> N;
    for (int i = 0; i < N; ++i) cin >> d[i];

    int num[110] = {};
    for (int i = 0; i < N; ++i) {
        num[d[i]]++;
    }

    int ans = 0;
    for (int i = 1; i <= 100; ++i) {
        if (num[i]) ++ans;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;

void main(){
	string str;
	while((str = readln()).length != 0){
		int n = to!int(chomp(str));
		int cv;
		
		foreach(a; 0 .. 10){
			foreach(b; 0 .. 10){
				foreach(c; 0 .. 10){
					int d = n - a - b - c;
					if(0 <= d && d <= 9){
						cv++;
					}
				}
			}
		}
		
		writeln(cv);
	}
}

Measured memory_bytes: 1052
#include <iostream>
#include <stdio.h>
#include <cmath>

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

typedef long long ll;

using namespace std;

const int INF = 1e9;
const int MOD = 1e9+7;
const double PI=3.14159265358979323846;

int main(){
  ll H, n=1;
  cin >> H;
  while(H!=1){
    n++;
    H/=2;
  }
  ll ans = pow(2,n)-1;
  printf("%ld\n", ans);
}

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

int main() {
    string s;
    cin>>s;
    int count=0;
    int x=0;
    for(int i=0;i<s.length();i++){
        if(s.at(i)=='R'){
            count+=1;
        }else{
            
            count=0;
        }
        if(count>x){
            x=count;
        }
    }
    cout<<x<<endl;
    
    
    
        
        
    return 0;
    
    
}



Measured memory_bytes: 3620
n,t=map(int,input().split())
for x in range(n+1):
  for y in range(n-x+1):
    z=n-x-y
    if 10000*x+5000*y+1000*z==t and z>=0:
      print(x,y,z)
      exit()
print(-1,-1,-1)

Measured memory_bytes: 3060
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};
ll power(ll x, ll n){
	if(n == 0) return 1LL;
	ll res = power(x * x % MOD, n/2);
	if(n % 2 == 1) res = res * x % MOD;
	return res;
}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll M;
	cin >> M;
	string C;
	cin >> C;
	ll N = C.size();
	ll tt[11] = {};
	ll mod_def = 0;
	rep(i,0,N){
		ll num = C[i] - '0';
		tt[num] += power(10, N-i-1) % MOD;
		mod_def += num * power(10, N-i-1) % MOD;
		mod_def %= MOD;
		tt[num] %= MOD;
	}
	vector<ll> v(10);
	iota(v.begin(), v.end(), 0);
	do {
		ll mod_val = mod_def;
		rep(i,0,10){
			mod_val += tt[i] * (v[i] - i + MOD) % MOD;
			mod_val %= MOD;
		}
		if(mod_val == M && v[C[0]-'0'] != 0){
			rep(i,0,N){
				cout << v[C[i]-'0'];
			}
			cout << endl;
			return 0;
		}else if(mod_val == M && N == 1){
			print(0);
			return 0;
		}

	}while(next_permutation(v.begin(), v.end()));
	print(-1);


	
}


Measured memory_bytes: 3340
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;

int main()
{
	ll a,b,c;
	cin >> a >> b >> c;
	double A,B,C;
	A = a;
	B = b;
	C = c;
	if(c-a-b>=0)
	{
		if((a*b*4)<(c-a-b)*(c-a-b))
		{
			cout<<"Yes"<<endl;
		}
		else
		{
			cout<<"No"<<endl;
		}
	}
	else
	{
		cout<<"No"<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
import com.sun.org.apache.xpath.internal.operations.Bool
import java.lang.Math.*

const val MOD = 1000000007L

fun main(args: Array<String>) {
    val (a, b) = readIntList()

    println(max(a + b, max(a - b, a * b)))
}

fun readList() = readLine()!!.split(' ')
fun readInt() = readLine()!!.split(' ').map(String::toInt).first()
fun readIntList() = readList().map(String::toInt)
fun readLongList() = readList().map(String::toLong)
fun readDoubleList() = readList().map(String::toDouble)

fun readPair(): Pair<String, String> {
    val splite = readLine()!!.split(' ')
    return Pair(splite[0], splite[1])
}

fun <T> List<T>.copy() = this.map { it }

inline fun <reified T> dualArray(h: Int, w: Int, init: (Int, Int) -> T) {
    Array(h) { i ->
        return@Array Array(w) { j ->
            return@Array init(i, j)
        }
    }
}

// 速度のためforEachは避ける
inline fun Int.rep(start: Int = 0, shiftLast: Boolean = false, body: (Int) -> Unit) {
    for (i in start until if (shiftLast) this + start else this) {
        body(i)
    }
}

inline fun Long.rep(start: Long = 0, shiftLast: Boolean = false, body: (Long) -> Unit) {
    for (i in start until if (shiftLast) this + start else this) {
        body(i)
    }
}

// 約数のList
fun divisor(value: Long): List<Long> {
    val max = sqrt(value.toDouble()).toLong()
    val former = mutableListOf<Long>()
    val latter = mutableListOf<Long>()
    (1..max).filter { value % it == 0L }
        .forEach {
            former.add(it)
            latter.add(value / it)
        }
    former.addAll(latter.reversed())
    return former
}

// 範囲内の素数を取得
// fromだけ指定すると戻り値の個数で素数判定ができる
fun prime(from: Long, to: Long = from): List<Long> {
    return (from..to).filter { i ->
        val max = Math.sqrt(i.toDouble()).toLong()
        (2..max).all { j -> i % j != 0L }
    }
}

// 素因数分解
fun decom(value: Long): List<Long> {
    if (value == 1L) return listOf(1)
    val max = Math.sqrt(value.toDouble()).toLong()
    return prime(2, max).filter { value % it == 0L }
}

// 最大公約数
fun gcd(a: Long, b: Long): Long {
    return if (a % b == 0L) b else gcd(b, a % b)
}

// 文字列を入れ替え
fun swap(base: String, a: String, b: String): String {
    return base.map {
        when (it) {
            a.toCharArray()[0] -> b
            b.toCharArray()[0] -> a
            else -> it.toString()
        }
    }.joinToString()
}

// 二分探索
fun List<Long>.binarySearch(target: Long, _start: Int = 0, _end: Int = this.size): Int {
    var start = (_start - 1).toLong()
    var end = _end.toLong()
    while (end - start > 1) {
        val mid = (start + end) / 2
        if (this[mid.toInt()] < target) {
            start = mid
        } else {
            end = mid
        }
    }
    return end.toInt()
}

// bit全探索
inline fun Int.bitAllSearch(body: (Array<Int>) -> Unit) {
    for (bit in 0 until (1 shl this)) {
        val s = mutableListOf<Int>()
        for (i in 0 until this) {
            if ((bit and (1 shl i)) shr i == 1) { // i が bit に入るかどうか
                s.add(i)
            }
        }
        body(s.toTypedArray())
    }
}

Measured memory_bytes: 38224
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for(ll i = 1; i < (ll)(n); i++)
const ll mo=1000000007;
const ll INF=1<<30;
ll ans=0;
bool v[16020];
bool vv[16020];
 
int main()
{ 
string s;
cin >> s; 
ll x,y;
cin >> x>>y;
vector<ll> xx;
vector<ll> yy;
ll temp=0;
bool xy=0;
rep(i,s.size()){
    if(s[i]=='F')temp++;
    else break;
}
x=x-temp;
ll a=temp;
temp=0;
for(ll i = a; i < (ll)(s.size()); i++){
    if(s[i]=='F')temp++;
    else{
        if(xy){
            if(temp!=0)yy.push_back(temp);
            xy=0;
            temp=0;
        }
        else{
            if(temp!=0)xx.push_back(temp);
            xy=1;
            temp=0;
        }
    }
} 
if(temp!=0){
    if(xy)yy.push_back(temp);
    else xx.push_back(temp);
}
 
if(xx.size()==0){
    if(x!=0){
        cout << "No" << endl;
        return 0;
    }
}
else{
    rep(i,16020){
        v[i]=false;
        vv[i]=false;
    }
    v[0+8010]=true;
    rep(i,xx.size()){rep(j,16020){
        if(v[j]){
            vv[j+xx[i]]=true;
            vv[j-xx[i]]=true;
        }
    }
    rep(j,16020){
        v[j]=vv[j];
        vv[j]=false;
    }
    }
    if(!v[x+8010]){
        cout << "No" << endl;
        return 0;
    }
}
 
if(yy.size()==0){
    if(y!=0){
        cout << "No" << endl;
        return 0;
    }
}
else{
    rep(i,16020){
        v[i]=false;
        vv[i]=false;
    }
    v[0+8010]=true;
    rep(i,yy.size()){rep(j,16020){
        if(v[j]){
            vv[j+yy[i]]=true;
            vv[j-yy[i]]=true;
        }
    }
    rep(j,16020){
        v[j]=vv[j];
        vv[j]=false;
    }
    }
    if(!v[y+8010]){
        cout << "No" << endl;
        return 0;
    }
}
 
 
cout << "Yes" << endl;
return 0;
} 

Measured memory_bytes: 384
#include<stdio.h>

int main(void)
{
	int a,b,c;
	scanf("%d",&a);
	scanf("%d",&b);
	if(a<=b){
		c=b-a;
	}
	else{
		c=a-b;
	}
	printf("%d\n",c);
    return 0;
}


Measured memory_bytes: 2124
#include<iostream>
    #include<cstdlib>
    #include<math.h>
    #include<set>
    #include<string>
    #include<stdlib.h>
    using namespace std ;

    int gcd(int a, int b){
      if(a%b==0)return b;
      else return gcd(b,a%b);
    }
    int main(){
      string S;
      cin>>S;
      if(S[0]==S[1]&&S[2]==S[3]&&S[0]!=S[2]){
        cout<<"Yes"<<endl;
        return 0;
      }
      if(S[0]==S[2]&&S[1]==S[3]&&S[0]!=S[1]){
        cout<<"Yes"<<endl;
        return 0;
      }
      if(S[0]==S[3]&&S[1]==S[2]&&S[0]!=S[1]){
        cout<<"Yes"<<endl;
        return 0;
      }
      else cout<<"No"<<endl;
      return 0;
    }

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main() {
  int a;
  int b;
  scanf("%d %d",&a,&b);
  if (b%a == 0)	{
    printf("%d\n",a+b);
  }
  else {
    printf("%d\n",b-a);
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    string S,T; cin>>S>>T;

    string ans="No";
    rep(i,0,S.size()){
        S=S.substr(1)+S.at(0);
        if(S==T) ans="Yes";
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>

int main() {
  char s[4];
  scanf("%s", s);

  if (s[0] == '7' || s[1] == '7' || s[2] == '7') {
    puts("Yes");
  } else {
    puts("No");
  }
}


Measured memory_bytes: 1664
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n;
    int[] a;
    int i, tmp;

    n = sc.nextInt();
    a = new int[n];
    for(i = 0;i < n;i++){
      a[i] = sc.nextInt();
    }

    for(i = 0;i < (n / 2);i++){
      tmp = a[i];
      a[i] = a[n - 1 - i];
      a[n - 1 - i] = tmp;
    }

    for(i = 0;i < (n - 1);i++){
      System.out.print(a[i] + " ");
    }
    System.out.println(a[i]);

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 19104
N = int(input())
C = [[0 for _ in range(10)] for _ in range(10)]
for n in range(1, N+1):
    s, e = int(str(n)[0]), int(str(n)[-1])
    C[s][e] += 1
ans = 0
for i in range(10):
    for j in range(10):
        ans += C[i][j] * C[j][i]
print(ans)

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

typedef long long ll;

bool isPalindrome(string s) {
    int L = 0, R = s.size() - 1;

    while (R > L) {
        if (s[L++] != s[R--])
            return false;
    }
    return true;
}

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

    string s;
    cin >> s;

    int half = (s.size() - 1) / 2;
    int secondStart = (s.size() + 3) / 2 - 1;
    int secondLen = s.size() - secondStart;

    string first = s.substr(0, half);
    string second = s.substr(secondStart, secondLen);
    if (isPalindrome(s) && isPalindrome(first) && isPalindrome(second)) {
        cout << "Yes" << "\n";
    } else {
        cout << "No" << "\n";
    }
}


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

int gcd(int x,int y){
	// cerr << x << " " << y << endl;
	if( x < y )swap(x,y);
	if( x % y == 0 )return y;
	return gcd( x%y, y);
}

int main(void){
	int x,y;
	cin >> x >> y;
	cout << gcd(x,y) << endl;
	return 0;
}

Measured memory_bytes: 3088
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main(){
	double a,b,c,angle;
	cout<<fixed<<setprecision(4);
	cin >> a >> b >> angle;
	cout<<0.5*a*b*sin(angle*M_PI/180)<<endl;
	c=sqrt(a*a+b*b-2*a*b*cos(angle*M_PI/180));
	cout<<a+b+c<<endl<<(a*b*sin(angle*M_PI/180))/a<<endl;
}


Measured memory_bytes: 3596
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <bits/stdc++.h>
using namespace std;
int main()
{
   int t,i=0,j=0;
   cin>>t;
   vector<string>m;
   int k[t],tk=t;
   string s;
       int n;
   while(tk--)
   {
       cin>>s;
        cin>>n;
       m.push_back(s);
       k[j++]=n;
      // cout<<m[j-1]<<" ";
   }
   
   string x;
   int f=9,sum=0;
   cin>>x;
   for(int p=0;p<t;p++)
   {
       if(m[p]==x)
       {f=p;break;}
   }
   //cout<<f<<"\n";
   for(int p=f+1;p<t;p++)
   {
       sum=sum+k[p];
   }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
 
#define $(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define endl '\n'
#define x first
#define y second
#define int long long
#define double long double
#define pii pair<int, int>
#define pb push_back
#define vec vector
#define beg begin
#define dbg(x) cout << #x << " = " << x << endl;
 
template<class T> ostream& operator<<(ostream &str, vector<T> &a) {
    for (auto &i : a) {
        str << i << " ";
    }
    return str;
}
 
template<class T> istream& operator>>(istream &str, vector<T> &a) {
    for (auto &i : a) {
        str >> i;
    }
    return str;
}
 
template<class T> ostream& operator<<(ostream &str, pair<T, T> &a) {
    str << a.first << " " << a.second;
    return str;
}
 
template<class T> istream& operator>>(istream &str, pair<T, T> &a) {
    str >> a.first >> a.second;
    return str;
}
 
void solve(); signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(6);
    solve();    
    return 0;   
}
 
const int MOD = 1e9 + 7, MAXN = 5e5 + 10, INF = 1e18 + 10, BASE = 37; 

void solve() {
    int n;
    cin >> n;
    vec<int> a(n);
    cin >> a;
    sort(rall(a));

    int ans = a[0], k = n - 2;
    for (int i = 1; i < n; ++i) {
        if (k > 0) {
            ans += a[i];
            k--;
        }
        if (k > 0) {
            ans += a[i];
            k--;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 4760
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n,i;
  cin>>n;
  int a[n];
  for(i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a,a+n);
  cout<<a[n-1]-a[0];
}


Measured memory_bytes: 256