akhauriyash/Code-Regression huggingface dataset:
N = int(input())
S = input()
acc_E = [0] * (N + 1)
for i in range(N):
    acc_E[i + 1] = acc_E[i] + (S[i] == 'E')
result = N
for leader in range(N):
    left_W = leader - acc_E[leader]
    right_E = acc_E[N] - acc_E[leader + 1]
    result = min(result, left_W + right_E)
print(result)

Measured memory_bytes: 15244
{-# LANGUAGE BangPatterns, TupleSections #-}
import qualified Data.ByteString.Char8 as BS

main :: IO ()
main = do
  str <- BS.getLine
  print $ (\(!cur,!tot) -> tot)
   $ BS.foldl'
     (\(!prev,!tot) !chr ->
       let now = if chr `elem` "ACGT" then prev + 1 else 0
       in (now,) $! now `max` tot)
     (0,0) str


Measured memory_bytes: 380
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef struct{
 double x;
 double y;
} Point;

void kohho(Point,Point,int);

int main(){
 int n;
 Point p1={0.0,0.0},p2={100.0,0.0};

 scanf("%d",&n);

 printf("%f %f\n",p1.x,p1.y);
 kohho(p1,p2,n);
 printf("%f %f\n",p2.x,p2.y);

 return 0;
}

void kohho(Point p1,Point p2,int n){
 Point s,t,u;

 if(n==0) return;

 s.x=(p2.x+(2*p1.x))/3;
 s.y=(p2.y+(2*p1.y))/3;  

 t.x=((2*p2.x)+p1.x)/3;
 t.y=((2*p2.y)+p1.y)/3;

 u.x=(t.x-s.x)/2-(t.y-s.y)*(sqrt(3)/2)+s.x;
 u.y=(t.x-s.x)*(sqrt(3)/2)+(t.y-s.y)/2+s.y;

 kohho(p1,s,n-1);
 printf("%f %f\n",s.x,s.y);
 kohho(s,u,n-1);
 printf("%f %f\n",u.x,u.y);
 kohho(u,t,n-1); 
 printf("%f %f\n",t.x,t.y);
 kohho(t,p2,n-1); 

}



  
  
  
  



Measured memory_bytes: 2044
a,b = (int(x) for x in input().split())

            
if a == 1 or b == 1:
    print(1)
elif a > b:#b対象
    anb1 = int(b * b) 
    anb2 = (int((a-b) * b))
    if (anb1 % 2) == 0:#偶数
            print(int(anb1/2) + int(anb2/2))
    else:#奇数
            print(int(anb1/2 + 1) + int(anb2/2))
elif a < b:#a対象            
    anb1 = int(a * a)
    anb2 = int((b-a) * a)
    if (anb1 % 2) == 0:#偶数
            print(int(anb1/2) + int(anb2/2))
    else:#奇数
            print(int(anb1/2 + 1) + int(anb2/2))
elif a == b:
    if a % 2 == 0:
        print(int(a / 2) * a)
    else:
        print(int((a * a) / 2) + 1)

Measured memory_bytes: 3064
lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end

N = lines[0][0]

ans = 0
last_dish = -10
for i in 1..N do
  dish = lines[1][i-1]
  ans += lines[2][dish-1]
  if dish == last_dish + 1 then
    ans += lines[3][last_dish-1]
  end
  last_dish = dish
end
print ans

Measured memory_bytes: 1788
N = int(input())
t,x,y = 0,0,0

for i in range(N):
  a,b,c = map(int, input().split())
  tmp = abs(a-t) - abs(b-x) - abs(c-y) 
  if tmp >= 0 and tmp % 2 == 0:
    t,x,y = a,b,c
  else:
    print('No')
    exit()
print('Yes')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int n,cntr[4444],cntg[4444],cntb[4444];
char s[4444];
long long ans;
int main(){
	scanf("%d\n%s",&n,s+1);
	for(int i=1;i<=n;i++){
		cntr[i]=cntr[i-1]+(s[i]=='R');
		cntg[i]=cntg[i-1]+(s[i]=='G');
		cntb[i]=cntb[i-1]+(s[i]=='B');
	}
	for(int i=1;i<=n;i++)
        for(int k=i+2;k<=n;k++)
	        if(s[i]=='G'&&s[k]=='R'||s[i]=='R'&&s[k]=='G'){
	            ans+=cntb[k]-cntb[i-1];
	            if((i+k)%2==0&&s[(i+k)/2]=='B')ans--;
	        }else if(s[i]=='G'&&s[k]=='B'||s[i]=='B'&&s[k]=='G'){
				ans+=cntr[k]-cntr[i-1];
				if((i+k)%2==0&&s[(i+k)/2]=='R')ans--;
			}else if(s[i]=='R'&&s[k]=='B'||s[i]=='B'&&s[k]=='R'){
				ans+=cntg[k]-cntg[i-1];
				if((i+k)%2==0&&s[(i+k)/2]=='G')ans--;
			}
	 printf("%lld\n",ans);
}

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

using namespace std;

int main() {

	long long n;
	scanf("%lld", &n);


	vector <int> a;

	while(n) {
		if(n%2==1) { //2*n+1
			a.push_back(0);
			n/=2;
		} else { // n+1
			a.push_back(1);
			n--;
		}
	}

	reverse(a.begin(), a.end());
	int cnt = 1;

	deque <int> ans;

	for (int i = 0; i < a.size(); ++i) {
		if(a[i] == 0) {
			ans.push_back(cnt++);
		} else {
			ans.push_front(cnt++);
		}
	}

	printf("%lu\n", 2*ans.size());
	for (int x: ans) {
		printf("%d ", x);
	}
	sort(ans.begin(), ans.end());
	for (int x: ans) {
		printf("%d ", x);
	}

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int cnt=0,i=0,mx=0;
	while(i<3)
	{
		if(s[i]=='R')
		cnt++;
		else
		cnt=0;
		mx=max(mx,cnt);
		i++;
	}
	cout<<mx<<endl;
}


Measured memory_bytes: 3624
#include <iostream>
#include <unordered_map>
#include <vector>
#include <set>
#include <string.h>
#include <algorithm>
#define mod 1000000007
#define inf 1LL<<61
#define ll long long
#define pr pair<int,int>
#define all vec.begin(),vec.end()
#define REP(i,a,b) for (int i = a; i < b; i++)
#define fi first
#define se second
#define pushb push_back
#define makep make_pair

using namespace std;

int main(){
	int h, w;
	cin >> h >> w;
	char arr[h+2][w+2];
	memset(arr, '#', sizeof(arr));
	char val;
	REP(i,1,h+1)
		REP(j,1,w+1){
			cin >> arr[i][j];
		}
	REP(i,0,h+2){
		REP(j,0,w+2){
			cout << arr[i][j];
		}
		cout << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <typeinfo>
using namespace std;

int main(){
    int N;
    std::cin >> N;
    int a[N];
    for (int i = 0; i < N; ++i)
    {
        std::cin >> a[i];
    }
    sort(a,a+N,[](int x, int y) { return x > y;});
    
    int alice = 0;
    int bob = 0;
    for (int i = 0; i < N; ++i)
    {
        // std::cout << "i:" << i << "\n";
        if (i%2 == 0)
        {
            alice = alice + a[i];
            // std::cout << "alic:" << alice << "\n";
        }else{
            bob = bob + a[i];
            // std::cout << "bob:" << bob << "\n";
        }
    }
    std::cout << alice - bob << "\n";
}

Measured memory_bytes: 256
import sys
#template by uwi 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
ar = na()
ans = ar[0]+ar[-1]
for i in range(n-2):
    ans += min(ar[i], ar[i+1])
print(ans)



Measured memory_bytes: 38384
/*
ID: new.sam1
PROG: ride
LANG: C++11 
*/
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <map>
#include <string>
#include <stdio.h>
#include <math.h>
#include <fstream>

using namespace std;
vector<int>v;
int main()
{
	ofstream fout("ride.out");
    ifstream fin("ride.in");
    //string a,b;
    //fin >> a >> b;
   	int n,x,cnt=0;
   	cin>>n;
   	while(n--)
   	{
   		cin>>x;
   		if(x&1)
   			cnt++;
   	}
   	if(cnt&1)
   		return cout<<"NO",0;
   	cout<<"YES";
   	return 0;
   	
   		
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

using namespace std;

int Q[1010000][2];
int head, tail;
int D[810][810];
int n, m, K, sx, sy;
char p[801][801];

void Ins(int x, int y, int d) {
	if (D[x][y] <= d || p[x][y] != '.') {
		return;
	}
	D[x][y] = d;
	tail++;
	Q[tail][0] = x;
	Q[tail][1] = y;
}

int main() {
	int i, j, x, y;
	scanf("%d%d%d", &n, &m, &K);
	for (i = 1; i <= n; i++) {
		scanf("%s", p[i] + 1);
		for (j = 1; j <= m; j++) {
			if (p[i][j] == 'S') {
				sx = i;
				sy = j;
				p[i][j] = '.';
			}
			D[i][j] = 1e9;
		}
	}
	Ins(sx, sy, 0);
	while (head < tail) {
		head++;
		x = Q[head][0];
		y = Q[head][1];
		Ins(x + 1, y, D[x][y] + 1);
		Ins(x, y + 1, D[x][y] + 1);
		Ins(x - 1, y, D[x][y] + 1);
		Ins(x, y - 1, D[x][y] + 1);
	}
	int res = 1e9;
	for (i = 1; i <= n; i++) {
		for (j = 1; j <= m; j++) {
			if (D[i][j] <= K) {
				res = min(res, 1 + (min(min(i - 1, n - i), min(j - 1, m - j)) + K - 1) / K);
			}
		}
	}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 8320
import math

n = int(raw_input())

for a in range(n):
  x = map(int,raw_input().split())
  x.sort()

  if x[0] == x[1] or x[0] == (x[1]-1):
    print (x[0]-1)*2
    continue

  q = x[0]*x[1]
  buf = math.sqrt(q)
  buf = int(buf)
  if buf*buf == x[0]*x[1]:
    buf -= 1

  ans = buf * 2 - 2
  if buf*(buf+1) < x[0]*x[1]:
    ans += 1

  print ans


Measured memory_bytes: 2568
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n; cin >> n;
  vector<int> a(n - 1); for (int &x : a) cin >> x;
  int ans = a[0] + a[n - 2];
  for (int i = 0; i < n - 2; ++i) {
    ans += min(a[i], a[i + 1]);
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
	int a,b,c,x,y;
	cin>>a>>b;
	for (c=0;c<b;c++){
		cin>>x>>y;
		if(y>a/2)y=(a+1)-y;
		if(x>a/2)x=(a+1)-x;
		if(x>y)x=y;
		if(x%3==0) cout<<"3"<<endl;
		else cout<<x%3<<endl;
	}
	return 0;
}

Measured memory_bytes: 3084
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll) 1000000007
#define P pair<ll, ll>



ll a, b, c;
int main() {
	cin >> a >> b >> c;
	cout << a + b + c - max({ a,b,c }) << endl;
}

Measured memory_bytes: 256
#include<iostream>

int main(){
    int num[] = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
    int x, y;
    std::cin >> x >> y;
    if(num[x] == num[y]) std::cout << "Yes" << std::endl;
    else std::cout << "No" << std::endl;
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>    
#define inf 100000000
#define INF 9223372036854775807
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
    int i;scanf("%d",&i);
    return i;
}
long long llin(void){
    long long i;scanf("%lld",&i);
    return i;
}
double din(void){
    double i;scanf("%lf",&i);
    return i;
}
void chin(char s[]){
    scanf("%s",s);
}
void print(int a){
    printf("%d\n",a);
}
void llprint(long long a){
    printf("%lld\n",a);
}
void dprint(double a){
    printf("%.10f\n",a);
}
void print2(int a,int b){
    printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
    return a>b?a:b;
}
long long min(long long a,long long b){
    return a<b?a:b;
}
double dmax(double a,double b){
    return a>b?a:b;
}
int cmp(const void *a,const void *b){
    return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
    return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
    return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
    return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
    int t=*a;
    *a=*b;
    *b=t;
}
long long gcd(long long x,long long y){
    return x%y?gcd(y,x%y):y;
}
long long lcm(long long x,long long y){
    return x/gcd(x,y)*y;
}

// write codes below this
// when you use 'sort',
// make sure TYPE macro is correct

int main(void){
    int a=in(),b=in(),c=in(),d=in();
    if(abs(a-b)<=d&&abs(b-c)<=d||abs(a-c)<=d)puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
const int MOD=1e9+7;
#ifndef HOME
#define cerr if(0)cerr
#endif

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    map<string,int>m;
    int ans=0;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        sort(s.begin(),s.end());
        ans+=m[s];
        m[s]++;
    }
    cout<<ans<<endl;
    
    return 0;
    
}



Measured memory_bytes: 11264
import bisect

A, B, Q = map(int, input().split())
INF = 10 ** 18

s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]


for q in range(Q):
    x = int(input())
    b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
    res = INF
    for S in [s[b-1], s[b]] : 
        for T in [t[d-1], t[d]] : 
            d1, d2 = abs(S-x) + abs(T-S), abs(T-x) + abs(S-T)
            res = min(res, d1, d2)
    print(res)

Measured memory_bytes: 14592
#include<stdio.h>
#include<stdlib.h>
#define HEAPSIZE 100

void insert(int heap[],int data,int *nheap);
void swap(int *sx,int *sy);
int deletemax(int heap[],int *nheap);

  

int main(void){
  int N,M;
  scanf("%d %d",&N,&M);

  int *heap=(int *)malloc(sizeof(int)*N);
  int i,A;
  
  int nheap = 0;

  for(i=0;i<N;i++){
    scanf("%d",&A);
    insert(heap, A, &nheap);
  }

  for(i=0;i<M;i++)
    insert(heap,deletemax(heap,&nheap)/2,&nheap);

  long int sum=0;
  for(i=0;i<N;i++)
    sum+=deletemax(heap,&nheap);

  printf("%ld\n",sum);

  free(heap);
  return 0;
}

void insert(int heap[],int data,int *nheap){
  heap[++*(nheap)]=data;
  int tmp=*nheap;
  while(heap[tmp]>heap[tmp/2] && tmp!=1){
    swap(&heap[tmp],&heap[tmp/2]);
    tmp/=2;
  }
 
}

void swap(int *sx,int *sy){
  int tmp=*sx;
  *sx=*sy;
  *sy=tmp;
}

int deletemax(int heap[],int *nheap){
  int par=1,data=heap[1];
  swap(&heap[(*nheap)--],&heap[par]);
  int chi=2*par;
  while(chi<=*nheap){
    if((chi<*nheap) && (heap[chi]<heap[chi+1]))
      chi++;
    if(heap[chi]<=heap[par])
      break;
    swap(&heap[chi],&heap[par]);
    par=chi;
    chi=2*par;
  }
  return data;
}


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

int main(){
  string s;
  cin >> s;
  for(int i=0;i<s.size();i++){
    if(i%2==1 && s.at(i)=='R' || i%2==0 && s.at(i)=='L'){
      cout << "No" << endl;
      return 0; 
    }
  }
  cout << "Yes" << endl;
}

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

#pragma region Macros
using ll = long long;
#define int ll
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
#define IOS\
    ios::sync_with_stdio(false);\
    cin.tie(0);\
    cout.tie(0);
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define SORT(name) sort(name.begin(), name.end())
#define RSORT(name)\
    SORT(name);\
    reverse(all(name));
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
template <class T> inline void print(T x){ cout << x << '\n';}
template<typename T1,typename T2> inline void chmin(T1 &a, T2 b){ if(a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 &a, T2 b){ if(a < b) a = b; }

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
#pragma endregion

#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const int MOD = 1000000007;
const int MAX_N = 100010;

signed main() {
    IOS;

    int X, K, D;
    cin >> X >> K >> D;

    X = abs(X);
    int cand1 = X - K * D;

    // 負までいくときの回数
    int cnt = X / D + 1;
    // 残り
    int rem = K - cnt;
    if(rem < 0) {
        print(cand1);
        return 0;
    }
    if(rem % 2 == 0) {
        print(abs(X - (D * cnt)));
    }
    else {
        print(abs(X - (D * cnt) + D));
    }

    return 0;
}


Measured memory_bytes: 3628
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1ll << 60;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N;
ll ans = 0, A[2005], DP[2005][2005];
Pll P[2005];

int main(){
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    P[i] = make_pair(A[i], i);
  }
  sort(P, P + N, greater<Pll>());

  for (int i = 1; i <= N; i++){
    ll Point = P[i - 1].first;
    ll Location = P[i - 1].second;
    for (int j = 0; j <= i; j++){
      ll now = 0;
      if (j > 0) now = max(now, DP[j - 1][i - j] + Point * abs(j - Location - 1));
      if (i - j > 0) now = max(now, DP[j][i - j - 1] + Point * abs(N - i + j - Location));
      DP[j][i - j] = now;
    }
  }

  ll ans = 0;
  for (int i = 0; i <= N; i++){
    ans = max(ans, DP[i][N - i]);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 26244
from sys import stdin
from math import cos, radians, sqrt

a,b,h,m = [int(x) for x in stdin.readline().strip().split()]
thete_t = 360*h/12+30*m/60
thete_m = 360*m/60
diff_thete = max(thete_t, thete_m)-min(thete_t, thete_m)
thete = diff_thete if diff_thete < 180 else 360 - diff_thete
c2 = a**2 + b**2 - 2*a*b*cos(radians(thete))

print(sqrt(c2))

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

using namespace std;

#define N 120000
#define INF 0x3f3f3f3f

int n,m,x,y,xb,cnt,pos[N],c[N],a[N],fa[N],f[N];
long long ans;
multiset<int> g[N];

bool cmp(int x,int y){return f[x]>f[y];}

int gfa(int x){return x==fa[x]?x:fa[x]=gfa(fa[x]);}

int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=1;i<=n;i++) fa[i]=i;
	for (int i=1;i<=m;i++){
		scanf("%d%d",&x,&y); x++; y++;
		x=gfa(x); y=gfa(y);
		fa[x]=y;
	}
	for (int i=1;i<=n;i++) f[gfa(i)]++,c[i]=i;
	sort(c+1,c+n+1,cmp);
	for (int i=1;i<=n;i++){
		if (f[c[i]]==0) break;
		pos[c[i]]=++cnt;
	}
	for (int i=1;i<=n;i++) g[pos[gfa(i)]].insert(a[i]);
	for (int i=2;i<=cnt;i++){
		if (g[1].empty()){puts("Impossible"); return 0;}
		ans+=*g[1].begin()+*g[i].begin();
		g[1].erase(g[1].begin()); g[i].erase(g[i].begin());
		for (set<int>::iterator j=g[i].begin();j!=g[i].end();j++)
			g[1].insert(*j);
		g[i].clear();
	}
	printf("%lld\n",ans);
	
	return 0;
}
			

Measured memory_bytes: 12672
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i32 = int32_t;
using i64 = int64_t;
constexpr char newl = '\n';

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
//#define F first
//#define S second
#define debug(x) cout << #x << ": " << x << '\n';
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int A[3][3];

  F0R(i, 3) F0R(j, 3) cin >> A[i][j];

  int N;
  cin >> N;
  F0R(i, N) {
    int b;
    cin >> b;
    F0R(j, 3) F0R(k, 3) if (A[j][k] == b) A[j][k] = -1;
  }

  bool result = false;
  F0R(i, 3) {
    bool bingo = true;
    F0R(j, 3) if (A[i][j] >= 0) bingo = false;
    if (result = bingo) break;

    bingo = true;
    F0R(j, 3) if (A[j][i] >= 0) bingo = false;
    if (result = bingo) break;
  }

  if (!result) {
    bool bingo = true;
    F0R(i, 3) {
      if (A[i][i] >= 0) bingo = false;
    }
    if (!(result = bingo)) {

      bingo = true;
      F0R(i, 3) {
        if (A[i][2-i] >= 0) bingo = false;
      }
      result = bingo;
    }
  }

  cout << (result ? "Yes" : "No");
}
#endif


Measured memory_bytes: 256
n = int(input())
d = {"M":0, "A":0, "R":0, "C":0, "H":0}
for i in range(n):
    s = input()
    letter = s[0]
    if letter in d:
        d[letter] += 1
ans = 0
if d["M"] != 0 and d["A"] != 0 and d["R"] != 0:
    ans += d["M"] * d["A"] * d["R"]
if d["M"] != 0 and d["A"] != 0 and d["C"] != 0:
    ans += d["M"] * d["A"] * d["C"]
if d["M"] != 0 and d["A"] != 0 and d["H"] != 0:
    ans += d["M"] * d["A"] * d["H"]
if d["M"] != 0 and d["R"] != 0 and d["C"] != 0:
    ans += d["M"] * d["R"] * d["C"]
if d["M"] != 0 and d["R"] != 0 and d["H"] != 0:
    ans += d["M"] * d["R"] * d["H"]
if d["M"] != 0 and d["C"] != 0 and d["H"] != 0:
    ans += d["M"] * d["C"] * d["H"]
if d["A"] != 0 and d["R"] != 0 and d["C"] != 0:
    ans += d["A"] * d["R"] * d["C"]
if d["A"] != 0 and d["R"] != 0 and d["H"] != 0:
    ans += d["A"] * d["R"] * d["H"]
if d["A"] != 0 and d["C"] != 0 and d["H"] != 0:
    ans += d["A"] * d["C"] * d["H"]
if d["R"] != 0 and d["C"] != 0 and d["H"] != 0:
    ans += d["R"] * d["C"] * d["H"]
print(ans)






Measured memory_bytes: 3188
package main

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

type node struct {
	key  int
	next *node
	prev *node
}

type linkedList struct {
	head *node
}

func newLinkedList(n *node) *linkedList {
	n.prev, n.next = n, n
	return &linkedList{n}
}

func (ll *linkedList) insert(x int) {
	next := ll.head.next
	n := &node{}
	n.key = x
	n.next = next
	n.prev = ll.head
	ll.head.next = n
	next.prev = n
}

func (ll *linkedList) delete(n *node) {
	next := n.next
	prev := n.prev
	prev.next = next
	next.prev = prev
}

func (ll *linkedList) deleteFromIndex(x int) {
	for n := ll.head.next; n != ll.head; n = n.next {
		if n.key == x {
			ll.delete(n)
			return
		}
	}
}

func (ll *linkedList) deleteFirst() {
	ll.delete(ll.head.next)
}

func (ll *linkedList) deleteLast() {
	ll.delete(ll.head.prev)
}

func main() {
	n := 0
	fmt.Scan(&n)

	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	ll := newLinkedList(&node{})
	for i := 0; i < n; i++ {
		s.Scan()
		cmd := s.Text()
		switch cmd {
		case "deleteFirst":
			ll.deleteFirst()
		case "deleteLast":
			ll.deleteLast()
		default:
			s.Scan()
			x, _ := strconv.Atoi(s.Text())
			if cmd == "insert" {
				ll.insert(x)
				break
			}
			ll.deleteFromIndex(x)
		}
	}

	e := []int{}
	for n := ll.head.next; n != ll.head; n = n.next {
		e = append(e, n.key)
	}
	fmt.Println(trimBracket(fmt.Sprint(e)))
}

func trimBracket(s string) string {
	return strings.Trim(s, "[]")
}



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

using namespace std;

using ll = long long;

int main (void){
  int n;
  cin >> n;
  cin.ignore();
  ll a[n];
  for (int i = 0; i < n; i++){
    cin >> a[i];
  }
  ll snuke = 0;
  ll arai = 0;
  snuke = a[0];
  
  for (int i = 1; i < n; i++){
    arai += a[i];
  }
  ll ans = abs(snuke - arai);
  ll tmpans;
  for (int i = 1; i < n - 1; i++){
    snuke += a[i];
    arai -= a[i];
    tmpans = abs(snuke - arai);
    if(tmpans < ans) ans = tmpans;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#pragma GCC optimize(2)
#pragma G++ optimize(2)
#include<bits/stdc++.h>
#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define ss(a) scanf("%s",a)
#define ms(a) memset(a,0,sizeof(a))
#define repi(i,a,b) for(register int i=a;i<=b;++i)
#define repd(i,a,b) for(register int i=a;i>=b;--i)
#define reps(s) for(int i=head[s];i;i=e[i].nxt)
#define ce(i,r) i==r?'\n':' '
#define pb push_back 
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define pr(x) cout<<#x<<": "<<x<<endl
using namespace std;
typedef long long ll;
const int MAX_N=2e5+5;
int n,x,cnt[MAX_N];
int main()
{
	si(n);
	repi(i,1,n-1) si(x),cnt[x]++;
	repi(i,1,n) printf("%d\n",cnt[i]);
	return 0;
}


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

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

int N, a[100001];

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

    map<int, int> m;
    for(int i=0;i<N;i++){
        m[ a[i] ]++;
    }

    int ans = 0;
    for(auto i : m){
        if(i.first != i.second){
            if(i.first < i.second)  ans += i.second - i.first;
            else ans += i.second;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 5120
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

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

int main() {
  //ll N, K;

  //cin >> N >> K;

  // int onePos = 0;
  // for (int i = 0; i < N; i++) {
  //   int tmp;
  //   cin >> tmp;
  //   if(tmp == 1){
  //     onePos = i;
  //     break;
  //   }
  // } // i

  ll N, K;
  cin >> N >> K;
  N--;
  K--;
  ll ans = N / K;
  if (N % K > 0) ans++;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
s = int(input())
al = {s:0}
ind = 1
while True:
    if s %2 == 0:
        s = s//2
    else:
        s = 3*s+1
    if s not in al:
        al[s] = 0
    else:
        print(ind+1)
        break
    ind += 1

Measured memory_bytes: 3060
def resolve():
    X= int(input())
    nums = dict()
    for A in range(10**4):
        nums[A**5] = A
        nums[-A**5] = -A        

        if A**5 - X in nums:
            print(A,nums[A**5-X])
            break
    



    

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 9176
import java.util.Scanner;


public class Main{
    
      public static int w,s;
      
      public static String isSafe(){
            if(w >= s) return "unsafe";
            return "safe";
      }

       public static void main(String []args){
         Scanner x = new Scanner(System.in);
         s = x.nextInt();
         w = x.nextInt();
         String ans = isSafe();
         System.out.println(ans);
        
      }
}

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

int main(){
	int n;
	double m1=0,m2=0,m3=0,mi=0;
	cin>>n;
	unsigned int *x =new unsigned int [n];
	unsigned int *y =new unsigned int [n];
	for(int i=0 ; i<n ; i++ ){
		cin >> x[i];
	}
	for(int i=0 ; i<n ; i++ ){
		cin >> y[i];
	}
	for(int i=0 ; i<n ; i++ ){
		m1+=abs((double)x[i]-(double)y[i]);
	}
	for(int i=0 ; i<n ; i++ ){
		m2+=pow(abs((double)x[i]-(double)y[i]),2.0);
	}
	m2=sqrt(m2);
	for(int i=0 ; i<n ; i++ ){
		m3+=pow(abs((double)x[i]-(double)y[i]),3.0);
	}
	m3=cbrt(m3);
	for(int i=0 ; i<n ; i++ ){
		if(mi<=abs((double)x[i]-(double)y[i])){
			mi=abs((double)x[i]-(double)y[i]);
		}
	}

	
	cout << fixed << setprecision(9) << m1 << endl;
	cout << fixed << setprecision(9) << m2 << endl;
	cout << fixed << setprecision(9) << m3 << endl;
	cout << fixed << setprecision(9) << mi << endl;
	delete [] x;
	delete [] y;
	return 0;
}

Measured memory_bytes: 1348
PROGRAM buildStairs
      IMPLICIT NONE
      integer(16) :: n
      integer(16),allocatable :: h(:)
      integer(16) :: i
      
      
      read*,n
      allocate( h(n) )
      read*,h(1:n)
      
      do i = n,2,-1
        if( h(i-1)-1>h(i) )then
          print*,'No';stop
        else if( h(i-1)-1==h(i) )then
          h(i-1) = h(i-1) - 1
        end if
      end do
      
      print*,'Yes'
      
      
      
      
      
      
      
      END PROGRAM

Measured memory_bytes: 2304
N = int(input())
A = list(map(int,input().split()))
mod = 1000000007
sum_A = (sum(A)**2) % mod
B = list(map(lambda x: (x**2)% mod,A))
sum_B = sum(B) % mod
print(((sum_A-sum_B)*500000004)%mod)

Measured memory_bytes: 31428
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit
#include <cstdio>	// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>	// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
#define DEBUG 0

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
string FILE_NAME = "testcase.soccer";
string NAME;
string itos (int n )
{
	stringstream ss;
	ss << n;

	return ss.str();
}
int score[100][100];

int main()
{
//	cut here before submit 
#if DEBUG
	NAME = FILE_NAME;
	int CNT = 1;
	NAME += itos (CNT );
	while (freopen (NAME.c_str() , "r", stdin ) != NULL ) {
#endif
	int n;
	cin >> n;
//	vector<int> score (n+1, 0 );
	memset (score, 0, sizeof (score ) );

	rep (i, n*(n-1)/2 ){
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		a--;b--;
		if (c > d ){
			score[a][b] = 	3;
		}else
		if (c < d ){
			score[b][a] = 3;
		}else{
			score[a][b] = score[b][a] = 1;
		} // end if
	} // end rep
	vector<P> total (n );
	rep (i, n ){
		total[i].second = i;
		rep (j, n ){
			total[i].first -= score[i][j];
		} // end rep
	} // end rep
	sort (ALL (total ) );
	vector<P> rank (n);
	rep (i, n ){
		rank[i].first = total[i].second;
		if (i != 0 && total[i-1].first == total[i].first ){
			rank[i].second = rank[i-1].second;
		}else{
			rank[i].second = i+1;
		} // end rep
	} // end rep

	sort (ALL (rank ) );
	rep (i, n ){
		cout << rank[i].second << endl;
	} // end rep

#if DEBUG
	CNT++;	// cut here before submit
	NAME = FILE_NAME;
	NAME += itos (CNT );
	} // end loop; cut here before submit
#endif			
	return 0;
}

Measured memory_bytes: 1260
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
//-----------------------------------------
#define dcml(n) fixed<<setprecision(n)
using namespace std;
int main(void){
    ll K,A,B;cin>>K>>A>>B;
    FOR(i,A-1,B){
        ll n=i+1;
        if(n%K==0){
            cout<<"OK\n";
            exit(0);
        }
    }
    cout<<"NG\n";
}

Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<utility>

#define lli long long
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define rep0(i,j) for(int i=0;i<j;i++)
#define rep1(i,j) for(int i=1;i<=j;i++)
#define rep0d(i,j) for(int i=j-1;i>=0;i--)
#define MAX 1000000007

using namespace std;


int main() {
	int n, a, b, c, d;
	cin >> a >> b >> c ;
	if (a<b&&b>c) { 
		cout << a+c;
	}
	else if (a < c) {
		cout << a + b;
	}
	else cout << b + c;
	return 0;
	
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
  long long int n,i,cnt = 0;
  scanf("%lld",&n);
  long long int a[n];
  for(i = 0;i < n;i++){
    scanf("%lld",&a[i]);
    if(a[i] % 4 < 1){
      cnt += 2;
    }else if(a[i] % 2 < 1){
      cnt++;
    }
  }
  if(cnt + n % 2 >= n){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#define Rep(i,a) for(int i = 0; i < (a); i++)
#define rep(i,a,b) for(int i = (a); i <= (b); i++)//(a)!
#define dep(i,a,b) for(int i = (a); i >= (b); i--)
#define ab(a) ((a) > 0 ? (a) : -(a))
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a)
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
const int N = 100100;
int a[N * 2], n, b[N * 2];

bool check(int m) {
	rep(i,1,2 * n - 1) a[i] = (b[i] >= m);
	dep(i,n - 1,1) if (a[i] == a[i + 1] || a[2 * n - i - 1] == a[2 * n - i]){
		if (a[i] == a[i + 1]) return a[i];
		if (a[2 * n - i - 1] == a[2 * n - i]) return a[2 * n - i];
	}
	return a[1];
}

int main() {
	scanf("%d",&n);
	rep(i,1,2 * n - 1) scanf("%d",&b[i]);
	int l = 1, r = 2 * n;
	while (l + 1 < r) {
		int mid = (l + r) >> 1;
		if (check(mid)) l = mid; else r = mid;
	}
	printf("%d\n",l);
	return 0;
}

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

using namespace std ;

int main() {
    long long l,r,i,ans[2],mi=INT_MAX,j;

    cin >> l >> r ;

    r= min(l+2019*2,r) ;

    for(i=l;i<=r;i++){
        for(j=i+1;j<=r;j++){
            if (mi>(i*j)%2019)
            {
                mi= (i*j)%2019 ;
             }
        }
    }

    cout<< mi ;



}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<bitset>
#include<utility>
#include<sstream>
#include<iomanip>
using namespace std;

#define ll long long
#define MP make_pair

int main(void) {
	int n,k,num=1;
	cin>>n>>k;
	for (int i = 0; i < n; i++) {
		num=min(num+k,num*2);
	}
	cout<<num<<"\n";

	return 0;
}


Measured memory_bytes: 256
# Sを入力する
S = list(input())
# Lを入力する
L = list(input())
 
# 3つの要素に定義しなおす
S1 = S[0]
S2 = S[1]
S3 = S[2]
L1 = L[0]
L2 = L[1]
L3 = L[2]
 
# 全部同じ
if S1 == L1 and S2 == L2 and S3 == L3:
  print(3)
# 全部違う
elif S1 != L1 and S2 != L2 and S3 != L3:
  print(0)
# 一つだけ
elif (S1 == L1 and S2 != L2 and S3 != L3) or (S1 != L1 and S2 == L2 and S3 != L3) or (S1 != L1 and S2 != L2 and S3 == L3):
  print(1)
# その他
else:
  print(2)

Measured memory_bytes: 3064
def solve():
    O = input()
    E = input()

    size = min(len(O), len(E))

    lis = []
    for i in range(size):
        lis.append(O[i] + E[i])

    if len(O) > size:
        lis.append(O[len(E):])
    elif len(E) > size:
        lis.append(E[len(O):])

    return "".join(lis)


if __name__ == '__main__':
    res = solve()
    print(res)


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

int main() {
  int N;
  cin >> N;
  
  vector<int> vec(N);
  
  for(int i=0; i<N;i++){
    cin >> vec.at(i);
  }
  
  int count;
  
  
  int M;
  cin >> M;
  
  
  
  
  for(int j=0; j<M; j++){
    
    count=0;
     for(int i=0; i<N; i++){
    count+=vec.at(i);
  }
  
   
    
    int P,X;
    cin >> P>> X;
    
    count -= vec.at(P-1);
    count += X;
    cout << count<< endl;
  }
    
    
}

Measured memory_bytes: 3604
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n,i;
	long long int _a;
	cin>>n;
	vector<long long int> a;
	for(i=0;i<n;i++){
		cin>>_a;
		a.push_back(_a);
	}
	sort(a.begin(),a.end());
	long long int b = (a.back() - (*a.begin()));
	cout<<b;
	return 0;
}

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

int main(){

	int n;
	while(cin >> n, n){
		int sum=0, s_max=0, s_min=10000;
		for(int i=0; i<n; i++){
			int s; cin >> s;
			sum += s;
			s_max = max(s_max, s);
			s_min = min(s_min, s);
		}
			cout << (sum - s_max - s_min)/(n-2) <<endl;
	}

	return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

int main(void){
    int p;
    cin>>p;
    rep(lp,p){
        string n;cin>>n;
        int ans=0;
        while(n.length()!=1){
            int mx=-1;
            range(i,1,n.length()){
                string a=n.substr(0,i);
                string b=n.substr(i);
                mx=max(mx,stoi(a)*stoi(b));
            }
            n=to_string(mx);
            ans++;
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 3284
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M = 1e9 + 7;

int x, y;

ll comb(int n, int m) {
    vector<ll> fact(2e6+1, 1);
    vector<ll> inv(2e6+1, 1);
    vector<ll> fi(2e6+1, 1);
    for (int i = 2; i <= 2e6; ++i) {
        fact[i] = (i * fact[i-1]) % M;
        inv[i] = M - (M/i) * inv[M%i] % M;
        fi[i] = (inv[i] * fi[i-1]) % M;
    }
    return (fact[n] * fi[m] % M) * fi[n-m] % M;
}

int main() {
    cin >> x >> y;
    if (((2*x-y)%3 != 0) || (2*x-y < 0) || ((x-(4*x-2*y)/3) < 0)) {
        cout << "0"; return 0;
    }
    int m = (2*x-y)/3;
    int n = x - 2*m;
    cout << comb(n+m, n);

    return 0;
}


Measured memory_bytes: 47104
#include <iostream>
using ll = long long;
using namespace std;

/* initialize */

/* main */
int main() {
    int n, p[101], m[101][101];
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> p[i] >> p[i+1];
    }
    for (int i = 1; i <= n; ++i) m[i][i] = 0;
    for (int l = 2; l <= n; ++l) {
        for (int i = 1; i <= n-l+1; ++i) {
            int j = i+l-1;
            m[i][j] = 1 << 21;
            for (int k = i; k <=j-1; ++k) {
                m[i][j] = min(m[i][j] , m[i][k]+m[k+1][j] +p[i-1]*p[k]*p[j]);
            }
        }
    }
    cout << m[1][n] << "\n";
    return 0;
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
#define int int64_t
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define REPP(i, n) for (int i = 1; (i) < (int)(n+1); ++ (i))
#define REPR(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i=(m)-1; i>=(n); i--)
#define ALL(v) v.begin(), v.end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).begin(),(c).end(),greater<int>());
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x,y) __gcd(x,y)
#define LCM(x,y) x/__gcd(x,y)*y
#define PB push_back
#define MP make_pair
#define endl "\n"
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
using namespace std;
using Graph = vector<vector<int> >;
using WeightedGraph = vector<vector<pair<int, int> > >;
typedef long double LD;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const int INF = 2000000000;
const long double PI = acosl(-1);
const int MOD = 1000000007;
void print() {cout << endl;}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " ";print(forward<Tail>(tail)...);}
template <class T> void print(vector<T> &vec) {for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " ";} cout << endl;}
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec);}}


signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int ans = 0;
    
    string N;
    cin >> N;
    REP(i,N.length()) {
        ans += N[i]-'0';
        ans %= 9;
    }
    if (ans == 0) yes;
    else no;
    
    
    
    return 0;
}

/*
cd ~/Desktop/Programming/AtCoder/contest/abc176/abc176_b && sh shellscripts/test_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc176/abc176_b && sh shellscripts/etest_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc176/abc176_b && sh shellscripts/submit_cpp.sh
*/


Measured memory_bytes: 3740
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        String planes = "";
        int row = 0;
        Scanner scan = new Scanner(System.in);
        while(scan.hasNext()){
            String str = scan.next();
            planes += str;
            if(row++ > 6){
                row = 0;
                if(planes.matches(".*1111.*"))System.out.println("C");
                if(planes.matches(".*110000011.*"))System.out.println("G");
                if(planes.matches(".*1100000011.*"))System.out.println("A");
                if(planes.matches(".*11000000011.*"))System.out.println("E");
                if(planes.matches(".*100000001100000001.*"))System.out.println("F");
                if(planes.matches(".*1000000110000001.*"))System.out.println("D");
                if(planes.matches(".*1000000010000000100000001.*"))System.out.println("B");
                planes = "";
            }
        }
    }
}



Measured memory_bytes: 29852
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#define FINAL_OUT(x) {cout << (x) << '\n'; exit(0);}




int main()
{
//    freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    ios_base::sync_with_stdio(false);

    int a,b,c,d,e,f;
    cin >> a >> b >> c >> d >> e >> f;

    vector<int> used(f + 1, 0);
    used[0] = 1;
    for(int i = 0; i < used.size(); ++i)
    {
        if (used[i])
        {
            if (i + c < used.size())
                used[i + c] = 1;
            if (i + d < used.size())
                used[i + d] = 1;
        }
    }


    int bestn = 0;
    int bestd = 1;
    double best = 0;
    pair<int,int> argbest;
    for(int i = 0; a*i <= f; ++i)
    for(int j = 0; a*i + b * j <= f; ++j)
    {
        int curw = a * i + b * j;
        for(int k = 0; k + curw * 100 <= f && k <= e * curw; ++k)
        {
            if (!used[k]) continue;
            int curn = 100 * k;
            int curd = k + 100 * curw;

            if (bestn * curd <= curn * bestd)
            {
                tie(bestn, bestd) = make_tuple(curn, curd);
                argbest = {curw * 100 + k, k};
            }
        }
    }
    cout << argbest.first << ' ' << argbest.second << ' ' << endl;
}


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

int main() {
    int n;
    long long a[100010];
    cin >> n;
    long long ans = 1;
    for (int i=0; i<n; i++) {
        cin >> a[i];
    }
    sort(a, a+n);
    long long max = 1e18;
    for (int i=0; i<n; i++) {
        if (a[i]==0) {
            cout << 0 << endl;
            return 0;
        }
        else if (ans > max / a[i]) {
            cout << -1 << endl;
            return 0;
        }
        ans *= a[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4376
#include <cstdio>
#include <algorithm>

using namespace std;

int a[29];
int b[3];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  int ans = 0;
  for (int i = 1; i < n - 1; ++i) {
    for (int j = -1; j <= 1; ++j) {
      b[j + 1] = a[i + j];
    }
    sort(b, b + 3);
    if (a[i] == b[1]) {
      ++ans;
    }
  }
  printf("%d\n", ans);
}


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

typedef long long ll;
typedef long double ld;


#define forr(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define forn(i,a,b) for(int i=(int)a;i>(int)b;i--)
#define si(a) scanf("%d",&a)
#define si2(a,b) scanf("%d%d",&a,&b)
#define sll(a) scanf("%I64d",&a)
#define sll2(a,b) scanf("%I64d%I64d",&a,&b)
#define ps " "
#define nln "\n"


int str_to_num(string x,int n)
{
	int temp=0;
	int i=0;

	while(n)
	{
		temp*=10;
		temp+=(x[i]-'0');
		n--;
		i++;
	}
		
	return temp;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	
	
	string x;
	cin>>x;
	
	int i=0;
	
	int ans=1000;
	
	while(i<x.size()-2)
	{
		string s="";
		for(int j=i;j<i+3;j++) s+=x[j];
		
		
		int temp=str_to_num(s,3);
		
		int dif=abs(753-temp);
		ans=min(dif,ans);
		
		//cout<<temp<<" "<<dif<<"\n";
		
		i++;
	}


	cout<<ans;			
		
	return 0;
}



Measured memory_bytes: 256
N, Q = gets.split.map(&:to_i)
edges = (N - 1).times.map { gets.split.map(&:to_i) }
queries = Q.times.map { gets.split.map(&:to_i) }

graph = Array.new(N) { Array.new }
edges.each do |(u, v)|
  u -= 1
  v -= 1
  graph[u].push(v)
  graph[v].push(u)
end

points = Array.new(N, 0)
queries.each do |u, x|
  points[u - 1] += x
end

def bfs(graph, s, points)
  ret = Array.new(N, 0)
  queue = [[s, -1, 0]]
  while !queue.empty?
    u, parent, parent_point = queue.shift
    ret[u] = points[u] + parent_point
    graph[u].each do |v|
      next if v == parent
      queue.push([v, u, ret[u]])
    end
  end
  ret
end

counters = bfs(graph, 0, points)
ans = counters.join(' ')
puts ans


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

using namespace std;

int main() {
    long long A,B,C,K,sum=0;
    cin >> A >> B >> C >> K;
    for(long long i = 0; i < K; i++) {
        if(i >= A && i < A+B) {
            continue;
        }
        if(i >= A+B) {
            sum--;
            continue;
        }
            sum++;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3620
package main

import "fmt"

func eatenChocoNum(param, day int) int {
	j := 0
	for ; j*param+1 <= day; j++ {
		continue
	}
	return j
}

func main() {
	var N, D, X int
	fmt.Scan(&N, &D, &X)
	A := make([]int, N)
	for i, _ := range A {
		fmt.Scan(&A[i])
	}

	// fmt.Println(A)

	cnt := 0
	for i, _ := range A {
		cnt += eatenChocoNum(A[i], D)
		// fmt.Println(cnt)
	}
	fmt.Println(cnt + X)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;

using ll = long long;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;

auto R(int s, int n) {
    return boost::irange(s, n);
}
auto R(int n) {
    return boost::irange(0, n);
}
void show(const auto& v){
    for(auto i:v) cout << i << " ";
    cout << endl;
}

int main()
{
    int n;
    cin>>n;
    vector<vector<vector<ll>>> z(n);
    for(int i:R(n-1)){
        int a,b,c;
        cin>>a>>b>>c;
        z.at(a-1).push_back({b-1,c});
        z.at(b-1).push_back({a-1,c});
    }
    int q,k;
    cin>>q>>k;
    k=k-1;

    vector<ll> distance(n);
    std::function<void(int,int,ll)> search = [&](int node,int p,ll d){
        distance.at(node)=d;
        for(auto v:z.at(node)){
            if(v.at(0)!=p){
                search(v.at(0),node,d+v.at(1));
            }
        }
    };
    search(k,k,0);

    for(int i:R(q)){
        int x,y;
        cin>>x>>y;
        x--;
        y--;
        cout<<distance.at(x)+distance.at(y)<<endl;
    }
    return 0;
}

Measured memory_bytes: 29952
import java.util.*;
import java.lang.Math;

public class Main{
	public static void main(String ards[]){
    	Scanner sc = new Scanner(System.in);
    	long N = sc.nextLong();
      	long[] A = new long[(int)N+10];
      	for(int i=0;i<N;i++){
        	A[i] = sc.nextLong();
        }
      
      	long tate =0L;
      	long yoko =0L;
      	quick_sort(A,0,(int)N-1);
      	for(int i =(int)N-1;i>=1;i--){
        	if(tate ==0L){
            	if(A[i]==A[i-1]){
                	tate = A[i];
                    i--;
                }
            }else if(yoko == 0L){
            	if(A[i]==A[i-1]){
                	yoko = A[i];
                }
            }else{
            	break;
            }
        }
        System.out.println(tate*yoko);
    }
  
      static void quick_sort(long[] d, int left, int right) {
        if (left>=right) {
            return;
        }
        long p = d[(left+right)/2];
        int l = left, r = right;
        long tmp;
        while(l<=r) {
            while(d[l] < p) { l++; }
            while(d[r] > p) { r--; }
            if (l<=r) {
                tmp = d[l]; d[l] = d[r]; d[r] = tmp;
                l++; r--;
            }
        }
        quick_sort(d, left, r); 
        quick_sort(d, l, right); 
    }
}

Measured memory_bytes: 50524