akhauriyash/Code-Regression huggingface dataset:
from itertools import permutations
from scipy.sparse.csgraph import floyd_warshall
INF = 1001001001

N, M, R = map(int, input().split())
r = list(map(int, input().split()))
graph = [[INF]*N for _ in range(N)]
for i in range(M):
    A, B, C = map(int, input().split())
    graph[A-1][B-1] = C
    graph[B-1][A-1] = C
dist_matrix = floyd_warshall(graph)

ans = INF
for root in permutations(r):
    cnt = 0
    for j in range(R-1):
        cnt += dist_matrix[root[j]-1][root[j+1]-1]
    ans = min(ans, cnt)
print(int(ans))


Measured memory_bytes: 19284
#include<stdio.h>
int main(void)
{
	int a,s[1000],d[1000],f,g,h,j,i;
	while(1){
		f=0;
		scanf("%d",&a);
		if(a==0)	break;
		for(i=0;i<a;i++)
			scanf("%d",&s[i]);
		while(1){
			g=0;
			for(i=0;i<a;i++)
				d[i]=1;
			for(i=0;i<a;i++){
				for(j=i+1;j<a;j++){
					if(s[i]==s[j]){
						d[i]++;
						d[j]++;
					}
				}
			}
			for(i=0;i<a;i++){
				if(d[i]==s[i]){
					g++;
				}
			}
			if(g==a)
				break;
			else f++;
			for(i=0;i<a;i++)
				s[i]=d[i];
		}
		printf("%d\n",f);
		for(i=0;i<a;i++){
			if(i!=0)	printf(" ");
			printf("%d",s[i]);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 2588
import heapq
n = int(input())
edge = [[] for i in range(n)]
for i in range(n-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    edge[u].append([w, v])
    edge[v].append([w, u])

def dijkstra_heap(s):
    #始点sから各頂点への最短距離
    d = [float("inf")] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        d[v] = minedge[0]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,[e[0]+d[v],e[1]])
    return d

Path_from_0 = dijkstra_heap(0)
for i in range(n):
    print(Path_from_0[i] % 2)

Measured memory_bytes: 92064
using System;
using System.Linq;
 
class main{
  static void Main(string[] args){
    string s = Console.ReadLine();
    string firstNums = s.Substring(0,2);
    string secondNums = s.Substring(2,2);
    
    string[] mms = new string[]{"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"};
    string ans = "NA";
    
    if(mms.Any(p => p == firstNums) && mms.Any(p => p == secondNums))
      ans = "AMBIGUOUS";
    else if(mms.Any(p => p == firstNums) && !mms.Any(p => p == secondNums))
      ans = "MMYY";
    else if(!mms.Any(p => p == firstNums) && mms.Any(p => p == secondNums))
      ans = "YYMM";
    
    Console.WriteLine(ans);
  }
}

Measured memory_bytes: 26176
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define Mid ((l+r)/2)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define drep(i,a,b) for(int i=(a);i>=(b);--i)
#define file(a) freopen(#a".in","r",stdin),freopen(#a".out","w",stdout);
const int maxn=1e5+5,mod=1e9+7,inf=0x3f3f3f3f;
int n,m,Q,K,T,D,S;
int read(){
    int x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}

signed main(){
    //file(a);
    D=read(),T=read(),S=read();
    if(T*S>=D)puts("Yes");
    else puts("No");


    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(){
    string a, b, c;
    cin >> a >> b >> c;
    transform(a.begin(), a.end(), a.begin(), ::toupper);
    transform(b.begin(), b.end(), b.begin(), ::toupper);
    transform(c.begin(), c.end(), c.begin(), ::toupper);
    cout << a[0] << b[0] << c[0] << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main {

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

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

        for (int i = 0 ; i < m ; i++) {
            b[i] = sc.nextInt();
            c[i] = sc.nextInt();
        }

        Map<Integer, Long> map = new HashMap<>();
        for (int i = 0 ; i < n ; i++) {
            if (map.containsKey(a[i])) {
                map.put(a[i], map.get(a[i]) + 1);
            } else {
                map.put(a[i], 1l);
            }
        }

        for (int i = 0 ; i < m ; i ++) {
            if (map.containsKey(c[i])) {
                map.put(c[i], (long) map.get(c[i]) + b[i]);
            } else {
                map.put(c[i], b[i]);
            }
        }
        Pair[] pairs = new Pair[map.size()];
        int index = 0;
        for (Entry<Integer, Long> entry : map.entrySet()) {
            Pair pair = new Pair();
            pair.from = entry.getKey();
            pair.end = entry.getValue();
            pairs[index] = pair;
            index++;
        }

        Arrays.sort(pairs);
        long sum = 0 ;
        int remain = n;
        for (int i = map.size() - 1 ; i >= 0 ; i--) {
            if (pairs[i].end < remain) {
                sum += (long) pairs[i].from * pairs[i].end;
                remain -= pairs[i].end;
                } else {
                    sum += (long) pairs[i].from * remain;
                    remain = 0;
                }

            if (remain == 0) break;
        }

        System.out.println(sum);


    }
}

class Pair implements Comparable {
    int from;
    long end;
    @Override
    public int compareTo(Object other) {
        Pair otherpair = (Pair) other;
        return from - otherpair.from;
    }
}

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

int main(){
    long long n;
    cin >> n;
    string s;
    cin >> s;
    char t = s.at(0);
    long long ans = 1;
    for(long long i = 1; i < n; i++){
        if(t != s.at(i)){
            ans++;
            t = s.at(i);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>

#define vvi vector<vector<int>>
#define vi vector<int>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
const int INF = 10e7;

int main() {
  int r, g;
  cin >> r >> g;

  cout << (double)(2 * g - r) << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String...args){
    Scanner s = new Scanner(System.in);
    int n = s.nextInt(); int k = s.nextInt();
    int c = 1;
    while (n / k != 0){
      n/=k; c++;
    }
    System.out.println(c);
  }
}
      

Measured memory_bytes: 21844
from collections import defaultdict

n = int(input())
s = []
t = []
a = defaultdict(int)
for i in range(n):
    d = defaultdict(int)
    st = list(input())
    st.sort()
    for j in range(len(st)):
        d[st[j]]+=1    
    if i==0:
        t = set(st)
        for j in t:
            a[j] = d[j]
    else:
        u = set(st)
        t = t & u 
        for j in t:
            a[j] = min(a[j],d[j])
ans = ""
t = list(t)
t.sort()
for i in t:
    for j in range(a[i]):
        ans = ans + i
print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ABC127D - Integer Cards
  // N枚のカード、i番目のカードには整数Ai
  // 順に以下の操作を1回ずつ行う
  // Bj枚まで選ぶ(0枚でもよい)　選んだカードに書かれている整数をそれぞれCjに書き換える
  // M回の操作終了後にN枚のカードに書かれた整数の合計値の最大値を求める
  // 愚直にやるならpriority_queueで最小値を出力して更新可能なら数値を書き換えてpush
  // M回の操作で最大Bj枚書き換えるので間に合わない
  // pair = {Cj, Bj}でCjの降順に並び替え
  // Aiは昇順に並び替えてBjの和が枚数に満ちるまで比較していく、更新可能なら更新
  int N, M; cin >> N >> M;
  vector<int> A(N);
  ll ans = 0;
  REP(i, N){
    cin >> A[i];
    ans += A[i];
  }
  sort(A.begin(), A.end());
  vector<pair<ll, ll> > CB(M);
  REP(i, M){
    ll b, c; cin >> b >> c;
    CB.push_back({c, b});
  }
  sort(CB.begin(), CB.end(), greater<pair<ll, ll> >());
  int idx = 0;
  ll total = CB[idx].second;
  REP(i, N){
    if(i >= total){
      idx++;
      total += CB[idx].second;
    }
    if(A[i] < CB[idx].first) ans += CB[idx].first - A[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int h[n];
	for(int i=0;i<n;i++)cin>>h[i];
	int dp[n];
	dp[0]=0;
	for(int i=1;i<n;i++)
	{
		dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
		if(i>1)dp[i]=min(dp[i],dp[i-2]+abs(h[i]-h[i-2]));
	}
	cout<<dp[n-1];
}

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

#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

#define endl        '\n'
#define ll          long long
#define pb          push_back
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define rs(v,n)     v.resize(n)
#define hell        1000000007
#define peak        9123372036854775807
#define pii         acos(-1)
#define clr(a,x)    memset(a,x,sizeof(a))
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

namespace InOp{
template<class x,class y>
istream &operator>>(istream &in,pair<x,y> &p) 
{ 
    in>>p.F>>p.S;
    return in;
}
template<class x>
istream &operator>>(istream &in,vector<x> &v) 
{
    for(auto& i:v)
        in>>i;
    return in;
}
template<class x,class y>
ostream &operator<<(ostream &out,pair<x,y> &p) 
{ 
    out<<"("<<p.F<<","<<p.S<<") ";
    return out; 
}
template<class x>
ostream &operator<<(ostream &out,vector<x> &v) 
{ 
    out<<v.size()<<endl;
    for(auto i:v)
        out<<i<<" ";
    out<<endl;
    return out; 
}
}
using namespace InOp;

namespace ModOp{
template<class x,class y,class z> z add(x a,y b,z m){return (a+b)%m;}
template<class x,class y,class z> z sub(x a,y b,z m){return (a-b+m)%m;}
template<class x,class y,class z> z mul(x a,y b,z m){return ((ll)a*b)%m;}
template<class y,class z> z expo(ll b,y e,z m){ll a=1;b%=m;while(e!=0){if((e&1)==1){a=a*b;a=a%m;}b=b*b;b%=m;e>>=1;}return a%m;}
template<class x,class z> z inv(x b,z m){return expo(b,m-2,m);}
template<class x,class y> x invGeneral(x a,y b){if(a==0)return b==1?0:-1;x m=invGeneral(b%a,a);return m==-1?-1:((1-(ll)b*m)/a+b)%b;}
template<class x,class y,class z> z div(x a,y b,z m){ll c=inv(b,m);return mul(a,c,m);}
}
using namespace ModOp;

namespace Debug{
template<class x> void deb(x a){cerr<<"a"<<": "<<a<<endl;}
template<class x,class y> void deb(x a,y b){cerr<<"a"<<": "<<a<<" | "<<"b"<<": "<<b<<endl;}
template<class x,class y,class z> void deb(x a,y b,z c){cerr<<"a"<<": "<<a<<" | "<<"b"<<": "<<b<<" | "<<"c"<<": "<<c<<endl;}
template<class x,class y,class z,class xy> void deb(x a,y b,z c,xy d){cerr<<"a"<<": "<<a<<" | "<<"b"<<": "<<b<<" | "<<"c"<<": "<<c<<" | "<<"d"<<": "<<d<<endl;}
}
using namespace Debug;

#define N  1000005

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll tt=1;
    // cin>>tt;
    while(tt--)
    {
        ll i,j,k,l,r,x,y,m,n;
        ll d,t,s;
        cin>>d>>t>>s;
        if(s*t>=d)cout<<"Yes";
        else cout<<"No";
    }
    return 0;
}

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

int main()
{
    int arr[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    
    int n;
    cin>>n;
    cout<<arr[n-1]<<endl;
    
    
}

Measured memory_bytes: 256
x,y=map(int,input().split())

if x>3 :
    if y>3:
        print(0)
        exit()
    elif y==3:
        print(100000)
        exit()
    elif y==2:
        print(200000)
        exit()
    elif y==1:
        print(300000)
        exit()
elif x==3:
    if y > 3:
        print(100000)
        exit()
    elif y == 3:
        print(200000)
        exit()
    elif y == 2:
        print(300000)
        exit()
    elif y == 1:
        print(400000)
        exit()
elif x==2:
    if y > 3:
        print(200000)
        exit()
    elif y == 3:
        print(300000)
        exit()
    elif y == 2:
        print(400000)
        exit()
    elif y == 1:
        print(500000)
        exit()

elif x==1:
    if y > 3:
        print(300000)
        exit()
    elif y == 3:
        print(400000)
        exit()
    elif y == 2:
        print(500000)
        exit()
    elif y == 1:
        print(1000000)
        exit()

Measured memory_bytes: 3064
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#ifndef LOCAL
#define cerr if(0)cout
#endif
typedef long long ll;
//My i/o stream
struct fastio
{
	char s[100000];
	int it, len;
	fastio() {it=len=0;}
	inline char get()
	{
		if (it<len) return s[it++]; it=0;
		len=fread(s, 1, 100000, stdin);
		if (len==0) return EOF; else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while (c==' '||c=='\n') c=get();
		if (it>0) it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0; bool ng=0; char c; c=_buff.get();
	while (c!='-'&&(c<'0'||c>'9')) c=_buff.get();
	if (c=='-') ng=1, c=_buff.get();
	while (c>='0'&&c<='9') r=r*10+c-'0', c=_buff.get();
	return ng?-r:r;
}
template <class T> inline void putnum(T x)
{
	if (x<0) putchar('-'), x=-x;
	register short a[20]={}, sz=0;
	while (x) a[sz++]=x%10, x/=10;
	if(sz==0) putchar('0');
	for (int i=sz-1; i>=0; i--) putchar('0'+a[i]);
}
inline char getreal() {char c=_buff.get(); while (c<=32) c=_buff.get(); return c;}

const int mod = 1e9+7;
ll qpow(ll x, ll k) {return k==0? 1: 1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
int n, m;
char s[111][111];
int dis[111][111];
deque<int> q;
bool check(int x, int y)
{
	return dis[x][y]==-1&&(x>=1&&x<=n&&y>=1&&y<=m||x==n+1&&y==m);
}
const int dx[2] = {1, 0};
const int dy[2] = {0, 1};
int main()
{
	scanf("%d%d", &n, &m);
	for (int i=1; i<=n; i++)
	{
		scanf("%s", s[i]+1);
	}
	memset(dis, -1, sizeof(dis));
	q.PB(0);
	q.PB(1);
	dis[0][1] = 0;
	while (q.size())
	{
		int x = q.front(); q.pop_front();
		int y = q.front(); q.pop_front();
		for (int d=0; d<2; d++)
		{
			int nx = x+dx[d], ny = y+dy[d];
			if (check(nx, ny))
			{
				if ((s[x][y]=='#')==(s[nx][ny]=='#'))
				{
					dis[nx][ny] = dis[x][y];
					q.push_front(ny);
					q.push_front(nx);
				}
				else
				{
					dis[nx][ny] = dis[x][y]+1;
					q.PB(nx);
					q.PB(ny);
				}
			}
		}
	}
	cout<<dis[n+1][m]/2<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <stdlib.h>
#include <cassert>
#include <time.h>
#include <numeric>
#include <iomanip> 
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef vector<int> vi;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(v) (int)v.size()
#define ll long long int
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fill(a,v) memset(a,v,sizeof(a));
#define all(v) v.begin(),v.end()
#define forn(i, a, b) for(int i = a; i < b; i++)


#define trarr(a,n) forn(i,0,n) cerr<<a[i]<<" \n"[i==n-1];
#define trmat(g,n,m) forn(i,0,n)forn(j,0,m) cerr<<g[i][j]<<" \n"[i==m-1];
#define tr(...) cerr<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)
template<typename S, typename T> 
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.ff<<", "<<p.ss<<')';return out;}
template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
int l=v.size();for(int i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}
template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}
template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}

const ld PI = acos(-1);
const ld EPS = 1e-9;
const int inf = 1e9+10;
const ll INF = 1e18+10;
const int P = 1e9+7;
const int N = 2e2+10;
const int W = 1e5+10;

void solve(int _t){
	int n, c;
	cin >> n >> c;
	ll w[n], v[n];
	forn(i, 0, n){
		cin >> w[i] >> v[i];
	}
	ll dp[N][W] = {0};
	forn(i, w[0], W) dp[0][i] = v[0];
	forn(i, 1, n){
		forn(j, 1, c+1){
			dp[i][j] = dp[i-1][j];
			if(j < w[i]) continue;
			dp[i][j] = max({dp[i][j], dp[i-1][j-w[i]]+v[i]});
		}
	}
	cout<< dp[n-1][c]<<endl;
}	
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t = 1;
	// cin >> t;
	forn(test, 1, t+1){
		solve(test);
	}
	return 0;
}

Measured memory_bytes: 167724
t=gets.to_i
a=0
b=0
t.times do
  arr=gets.split(' ')
  if arr[0]==arr[1] then
     a+=1
     b+=1
  elsif arr.sort==arr then
     b+=3
  else
     a+=3
  end
end
printf("%d %d\n",a,b)

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

#define MX 100005
int k;
long long a[MX];

int check(long long x)
{
    long long y;
    for(int i=0; i<k; i++)
    {
        if(a[i]>x)  return  false;
        y = x/a[i];
        x = (y*a[i]);
    }
    if(x==2) return 1;
    else if(x>2)    return  2;
    return  -1;
}

void BS()
{
    int x;
    long long lo,hi,md,mn=-1,mx=-1;
    lo = 2;
    hi = 1000000000000000;
    while(lo<=hi)
    {
        md = (lo+hi)/2;
        x = check(md);
        if(x==1)
        {
            mn = md;
            hi = md-1;
        }
        else if(x==2)   hi = md-1;
        else    lo = md+1;
    }
    lo = 2;
    hi = 1000000000000000;
    while(lo<=hi)
    {
        md = (lo+hi)/2;
        x = check(md);
        if(x==1)
        {
            mx = md;
            lo = md+1;
        }
        else if(x==2)   hi = md-1;
        else    lo = md+1;
    }
    //cout<<check(8)<<endl;
    //cout<<mn<<" "<<mx<<endl;
    if(mn==-1 || mx==-1)    puts("-1");
    else    printf("%lld %lld\n",mn,mx);
    return;
}

int main()
{
    int i;
    scanf("%d",&k);
    for(i=0; i<k; i++)  scanf("%lld",&a[i]);
    BS();
    return  0;
}


Measured memory_bytes: 1024
/*
    Author: aksayushx
*/
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define all(a) a.begin(),a.end()
#define mp make_pair
#define mod 1000000007
using namespace std;
typedef long long ll;
typedef long double ld;
ll n;
vector<ll> a,pref;
vector<vector<ll>> dp;

void aksayushx()
{
    cin>>n;
    a.resize(n);
    pref.assign(n+1,0);
    dp.assign(n,vector<ll>(n,pow(10,18)));
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        pref[i+1]=pref[i]+a[i];
        //cout<<pref[i+1]<<' ';
    }
    for(ll l=n-1;l>=0;l--)
    {
        for(ll r=l;r<=n-1;r++)
        {
            if(l==r)
            dp[l][r]=0;
            for(ll i=l;i<r;i++)
            dp[l][r]=min(dp[l][r],dp[l][i]+dp[i+1][r]+pref[r+1]-pref[l]);
        }
    }
    cout<<dp[0][n-1];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test=1;
    //cin>>test;
    while(test--)
        aksayushx();
    return 0;
}


Measured memory_bytes: 4516
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
using namespace std;
#define INF 1000000007
using P = pair<int, int>;
using ll = long long;
long long factorial_mod(long long k){
    long long r=1;
    for(long long i=1;i<=k;i++){
        r*=i;
        r%=1000000007;
    }
    return r;
}
int main(){
    int n,m;
    cin>>n>>m;
    long long ans;
    if(n==m)ans=factorial_mod(n)*factorial_mod(m)*2%INF;
    else if(abs(n-m)==1)ans=factorial_mod(n)*factorial_mod(m)%INF;
    else ans=0;
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
N, K = gets.split.map &:to_i
A = gets.split.map &:to_i

Kb = "0"*(40 - K.to_s(2).size) + K.to_s(2)

Ab = A.map{|a| "0"*(40 - a.to_s(2).size) + a.to_s(2)}

count = [0]*40

for a in Ab do
	for b in 0...40 do
		count[b] += 1 if a[b] == '1'
	end
end

best_ans = "0"*40

for i in 0...40 do
	best_ans[i] = '1' if count[i] <= N - count[i]
end

xors = []

for i in 0...40 do
	ans = best_ans

	ans[0, i] = Kb[0, i]

	ans[i] = '0'

	ans_10 = ans.to_i(2)
	if ans_10 <= K then
		val = A.map{|a| a^ans_10 }.inject(0, :+)
		#puts "i: #{i} ans_10: #{ans_10} val: #{val}"
		xors << val
	end
end

p xors.max


Measured memory_bytes: 57372
#include<iostream>
#include<climits>
using namespace std;
typedef long long ll;

ll N;

ll capacity[5];

int main() {
    cin>>N;

    ll min_val = LLONG_MAX;
    int min_idx = 0;
    for(int i=0;i<5;i++) {
        cin>>capacity[i];
        if(capacity[i] < min_val) {
            min_val = capacity[i];
            min_idx = i;
        }
    }

    cout<<4+(N/min_val)+((N%min_val)>0);
}

Measured memory_bytes: 256
def separate_and_calc(S,plus_list):
    if plus_list == []:
        return array_to_num(S)
    
    result = 0
    for i in range(len(plus_list)):
        if i == len(plus_list)-1:
            result += array_to_num(S[plus_list[i]:])
        if i == 0:
            result += array_to_num(S[0:plus_list[i]])
            continue
        result += array_to_num(S[plus_list[i-1]:plus_list[i]])

    return result

def array_to_num(S):
    result = 0
    for i in range(len(S)):
        result += int(S[len(S) -1 - i]) * (10**(i))
    return result

S = input()
N = len(S)
result = 0
for bit in range(2**N):
    plus_list = []
    if bit & 1 or bit & (1<<N):
        continue

    for i in range(N):
        if (bit & (1<<i)):
            plus_list.append(i)
    
    result += separate_and_calc(S,plus_list)
    
    # print(" }")
print(result)

Measured memory_bytes: 9216
#include <iostream>
#include <stdio.h>
using namespace std;

int main(void){
  int n,m,tmp;
  int a[100][100] = {0};
  int b[100] = {0};
  int t[100] = {0};

  cin >> n >> m;
  for (int i=0;i<n;i++) {
    for (int j=0;j<m;j++) {
      cin >> a[i][j];      
    }
  }
  for (int i=0;i<m;i++) {
    cin >> b[i];
  }

  for (int i=0;i<n;i++) {
    for (int j=0;j<m;j++) {
      t[i] += (b[j] * a[i][j]);      
    }
    cout << t[i] << endl;
  }
}


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

int main()
{
    int a, b, C;
    cin >> a >> b >> C;
    double r = C * M_PI / 180.0; 
    double S = (a * b * sin(r)) / 2.0;
    double H = b * sin(r);
    double x = sqrt(pow(a,2) + pow(b,2) - 2 * a * b * cos(r)) + a + b;
    printf("%f\n",S);
    printf("%f\n",x);
    printf("%f\n",H);
    return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f=true){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f=true){cout<<(f?"YES":"NO")<<endl;}
#define ANS(a) cout<<a<<endl

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int W,a,b; cin >>W>>a>>b;

    cout << max(0, abs(a-b)-W) << endl;
}


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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

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

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf=1e9;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};	

int main(){
	int n,r;
  	cin>>n>>r;
  	
  	if(n>=10){
      cout<<r<<endl;
    }else{
    	cout<<r+(100*(10-n))<<endl;
    }
  
  
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <set>

using namespace std;

int main()
{
  int k, a, b;
  cin >> k >> a >> b;
  int r = (a - 1) / k + 1;
  if(a <= (r*k) && b >= (r*k) ) cout << "OK"<< endl;
  else cout << "NG"<< endl;
}


Measured memory_bytes: 3596
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), k = sc.nextInt();
        int[] p = new int[n];
        for(int i=0;i<n;i++){
            p[i] = sc.nextInt();
        }
        Arrays.sort(p);
        int sum = 0;
        for(int i=0;i<k;i++){
            sum += p[i];
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 30180
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program2
{
    static void Main(string[] args)
    {
        string s = Console.ReadLine();
        int i = s.Length - 2;
        string res = s[0] + i.ToString() + s[s.Length-1];
        Console.Write(res);
    }
}

Measured memory_bytes: 13140
m1, d1 = map(int, input().split())
m2, d2 = map(int, input().split())
# if (m1 == 4 or 6 or 9 or 11) and d1 ==30:
#     print(1)
# elif m1 == 2 and d1 ==28:
#     print(1)
# elif d1 == 31:
#     print(1)
# else:
#     print(0)

if d2 == 1:
    print(1)
else:
    print(0)

Measured memory_bytes: 2940
/* 
	Author: ankrypt
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int
#define ff first
#define ss second
#define all(x) x.begin(), x.end() 
#define ub upper_bound
#define lb lower_bound
#define MAX_INT 1000005
#define PI 3.141592653589793
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fi(a, b, c, d) for(int a = b; a < c; a += d)
#define fl(a, b, c, d) for(ll a = b; a < c; a += d)
#define fei(a, b, c, d) for(int a = b; a <= c; a += d)
#define fel(a, b, c, d) for(ll a = b; a <= c; a += d)
#define quit exit(0)
#define mem(x, a) memset(x, a, sizeof x)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pcl pair<char, ll>
#define psl pair<string, ll>


ll N, M, A, B, C;
ll arr[MAX_INT], arr1[MAX_INT], data[MAX_INT];
vector<ll> V;
unordered_map<ll, ll> mp;
set<ll> s;
string S[MAX_INT];
ll cases;

int main() {
	go;
    cin >> N;
    if(7 % N == 0) {
    	cout << 1 << "\n";
    	quit;
    }
    ll answer = 1;
    ll rem = 7;
    ll cnt = 10000005;
    ll ok = 0;
    while(cnt > 0) {
    	ll X = rem * 10 + 7;
    	answer++;
    	rem = X % N;
    	if(rem == 0) {
    		ok = 1;
    		break;
    	}
    	cnt--;
    }
    if(!ok) {
    	cout << -1 << "\n";
    }
    else {
    	cout << answer << "\n";
    }
	return 0;
}
/*
	Powered by Buggy Plugin
*/




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

using namespace std;

int main(){
    char a[3];
    cin>>a[0]>>a[1]>>a[2];
    if(a[0]!=a[1]&&a[1]!=a[2]&&a[0]!=a[2]){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

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

int main(){
    int n;
    bool flag = true; 
    cin >> n;
    vector<int> a(n,0);
    for(int i=0;i<n;i++) cin >> a[i];
    for(int i=0;i<n;i++){
        if(a[i] % 2 == 0) if(a[i] % 5 != 0 && a[i] % 3 != 0) flag = false;

    }
    if(flag)cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;
}

Measured memory_bytes: 256
#include<iostream>
	#include<stdlib.h>
	#include<vector>
	#include<algorithm>
	#include<stdio.h>
	#include<string>
	#include<map>
	#include<math.h>
	#include<iomanip>
	#include<set>
	#include<limits.h>
	#define rep(i,n) for(ll i = 0; i < (ll)n; i++)
	#define swap(a,b) a^=b;b^=a;a^=b;
	#define chmax(a,b) {if(a < b) a = b;}
	#define chmin(a,b) {if(a > b) a = b;}
	using namespace std;
	typedef long long ll;
	ll gcd(ll, ll);
	vector<bool> to_binary(int);
	int sum(vector<int>);
	int min(vector<int>);
	int max(vector<int>);
	ll nCr(ll n, ll r);

	const ll INF = 1LL << 60;

	typedef tuple<ll, ll> mtupl;

	bool mycomp(mtupl x, mtupl y) {
		return get<1>(x) < get<1>(y);
	}

	bool solve(int a, int b, int c) {
		vector<int> tmp{ a,b,c };
		sort(tmp.begin(), tmp.end());
		return tmp[1] == b;
	}

	int main(void) {
		cin.tie(0);
		ios::sync_with_stdio(false);
		//Program Start	

		int n;
		cin >> n;
		vector<int> p(n);

		rep(i, n) {
			cin >> p[i];
		}

		int ans = 0;
		for (int c = 1; c < n - 1; c++) {
			if(solve(p[c - 1],p[c],p[c + 1])) ans++;
		}

		cout << ans << endl;

	ProgramEndPointLabel:;

		//Program End
		system("pause");

		return 0;
	}

	ll nCr(ll n, ll r) {
		ll res = 1;
		for (int i = 0; i < r; i++) {
			res *= (n - i);
		}
		for (int i = 1; i <= r; i++) {
			res /= i;
		}
		return res;
	}

	int vsum(vector<int> v) {
		int res = 0;
		for (auto it = v.begin(); it != v.end(); it++)
			res += *it;
		return res;
	}
	int vmin(vector<int> v) {
		int min = INT32_MAX;
		for (auto it = v.begin(); it != v.end(); it++)
			min = std::min(min, *it);
		return min;
	}
	int vmax(vector<int> v) {
		int max = 0;
		for (auto it = v.begin(); it != v.end(); it++)
			max = std::max(max, *it);
		return max;
	}

	ll gcd(ll A, ll B) {
		int r = A % B;
		while (r != 0) {
			A = B;
			B = r;
			r = A % B;
		}

		return B;
	}

	vector<bool> to_binary(int x) {
		vector<bool> res;
		while (x != 0) {
			res.push_back(x % 2);
			x /= 2;
		}
		return res;
	}


Measured memory_bytes: 504
import sys
N = int(sys.stdin.readline().rstrip())

cnt = [[0] * 10 for _ in range(10)]

for i in range(1, N + 1):
    i = str(i)
    cnt[int(i[0])][int(i[-1])] += 1

ans = 0
for i in range(1, 10):
    for j in range(1, 10):
        ans += cnt[i][j] * cnt[j][i]
print(ans)

Measured memory_bytes: 40940
import java.util.Scanner;
 
class Main {
    Scanner sc = new Scanner(System.in);
 
    public void run() {
        while (true) {
            int a = sc.nextInt();
            String op = sc.next();
            int b = sc.nextInt();
            if ("+".equals(op)) {
                ln(a + b);
            } else if ("-".equals(op)) {
                ln(a - b);
            } else if ("*".equals(op)) {
                ln(a * b);
            } else if ("/".equals(op)) {
                ln(a / b);
            } else {
                break;
            }
        }
    }
 
    public static void main(String[] args) {
        new Main().run();
    }
 
    public static void pr(Object o) {
        System.out.print(o);
    }
 
    public static void ln(Object o) {
        System.out.println(o);
    }
 
    public static void ln() {
        System.out.println();
    }
}


Measured memory_bytes: 26224
n = int(input())
x = list(map(int,input().split()))
x_sort = sorted(x)
med_l = x_sort[n//2-1]
med_r = x_sort[n//2]
for i in range(n):
    x[i]
    if x[i] <= med_l:
        print(med_r)
    else:
        print(med_l)

Measured memory_bytes: 25220
import sys
 
BUILDINGS = tuple(x for x in range(4))
FLOORS = tuple(x for x in range(3))
ROOMS = tuple(x for x in range(10))
 
occupant = [[[0 for r in ROOMS] for f in FLOORS] for b in BUILDINGS]
 
n = input() # 読み捨て
 
for line in sys.stdin:
    b, f, r, v = map(int, line.split())
    occupant[b - 1][f - 1][r - 1] += v
     
for b in BUILDINGS:
    if b:
        print('#' * 20)
    for f in FLOORS:
        print("", *occupant[b][f])

Measured memory_bytes: 6724
#include <algorithm>
#include <cmath>
#include <iostream>

using namespace std;

using ll = long long;
using ld = long double;

#ifdef EBUG
#define debug(x) cout << "\033[31m" << #x << ": " << x << "\033[0m\n";
#else
#define debug(x)
#endif

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

ll a, b, c, k, sum;

int main() {
  cin >> a >> b >> c >> k;

  if (a >= k) {
    cout << k << endl;
    return 0;
  }
  sum += a;
  k -= a;

  if (b >= k) {
    cout << sum << endl;
    return 0;
  }
  k -= b;

  sum -= k;
  cout << sum << endl;
}

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }

vector<pair<long long, long long>> makeprime(long long n) {
    vector<pair<long long, long long>> factor;
    long long tmp = pow(n, 0.5) + 1;
    int cnt;
    for (long long i = 2; i < tmp; i++) {
        cnt = 0;
        while (n % i == 0) {
            n /= i;
            cnt++;
        }
        factor.push_back(make_pair(i, cnt));
    }
    if (n > 1) factor.push_back(make_pair(n, 1));
    return factor;
}

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

    ll N, P; cin >> N >> P;
    auto fac = makeprime(P);
    ll res = 1;
    for (auto p : fac) {
        res *= pow(p.first, p.second/N);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 18792
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"---------------"#x"---------------"<<endl
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
						For(_x,L,R)cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector <int> vi;
typedef long double LD;
LL read(){
	LL x=0,f=0;
	char ch=getchar();
	while (!isdigit(ch))
		f|=ch=='-',ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
const int N=305;
int n,k;
char s[N];
int dp[N][N][N];
void ckmax(int &x,int y){
	x=max(x,y);
}
int DP(int L,int R,int k){
	if (L>R)
		return 0;
	if (L==R)
		return 1;
	if (~dp[L][R][k])
		return dp[L][R][k];
	int ans=0;
	ckmax(ans,DP(L,R-1,k));
	ckmax(ans,DP(L+1,R,k));
	if (s[L]==s[R])
		ckmax(ans,DP(L+1,R-1,k)+2);
	else if (k>0)
		ckmax(ans,DP(L+1,R-1,k-1)+2);
	return dp[L][R][k]=ans;
}
int main(){
	cin>>s+1>>k;
	n=strlen(s+1);
	memset(dp,-1,sizeof dp);
	cout<<DP(1,n,k)<<endl;
	return 0;
}

Measured memory_bytes: 111104
#include "bits/stdc++.h"
    #include <math.h>
    #define LF '\n'
    #define ALL(x) x.begin(), x.end()
    #define iostreamBooster() do{cin.tie(nullptr);ios::sync_with_stdio(false);}while(0)
    using namespace std;
    typedef int64_t i64;
    typedef pair<int,int> pii;
    template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
    template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
    const int INF = 0x3f3f3f3f;
    signed main()
    {
    int N;
    int T, A;
    int h[1005];
    double t[1005];
    cin >> N >> T >> A;
    for (int i = 0; i < N; ++i) {
    cin >> h[i];
    t[i] = (double)T - h[i] * 0.006;
    }
    int p = 0;
    double v = INF;
    for (int i = 0; i < N; ++i) {
    double d = fabs(A - t[i]);
    if (d < v) {
    p = i;
    v = d;
    }
    }
    cout << p+1 << endl;
    return 0;
    }


Measured memory_bytes: 256
#include<iostream>

using namespace std;
#define int long long

signed main(){

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

    int ans=1e18;
    for(int k=-100; k<=100; k++){
        int sum=0;
        for(int i=0; i<N; i++){
            sum+=(a[i]-k)*(a[i]-k);
        }
        ans=min(ans, sum);
    }

    cout<< ans<< endl;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  int c1 = 1, c2 = 1;
  for (int i = 0; i < N; i++){
    c1 *= 3;
    cin >> A[i];
    if (A[i] % 2 == 0){
      c2 *= 2;
    }
  }
  cout << c1 - c2;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX_LENGTH 200
#define INF 100000;
int m[MAX_LENGTH][MAX_LENGTH];
int min(int a, int b)
{
    if(a<b)
        {return a;}
    else
        {return b;}}
void MatrixChainOrder(int p[], int n)
{
    for(int i = 0;i<n;i++){m[i][i] = 0;}
    for(int r = 2;r<=n;r++)
    {
        for(int i = 1;i<=n-r+1;i++)
        {
            int j = i+r-1;
            m[i][j] = INF;
            for(int k = i;k<j;k++)
            {
                int q = m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j];
                m[i][j] = min(m[i][j], q);
            }
            
        }
    }
}
int main() {
    int N;
    scanf("%d", &N);
    int p[MAX_LENGTH];
    for(int i = 0;i<N;i++){scanf("%d %d", &p[i], &p[i+1]);}
    MatrixChainOrder(p, N);
    printf("%d\n", m[1][N]);
    return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define rep0(i,n) for (int i=0; i<=(int)(n); ++i)
#define rep1(i,n) for (int i=1; i<=(int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using vb = vector<bool>;
using boolGraph = vector<vb>;
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const int MOD2 = 998244353;
const double EPS = 1e-9;

template<typename T>
struct is_vector : false_type{};

template<typename T>
struct is_vector<vector<T>> : true_type{};

template<typename T>
ostream &operator << (ostream &ostr, const vector<T> &vec) {
  if (vec.empty()) {
    return ostr;
  }
  ostr << vec.front();
  for (auto itr = ++vec.begin(); itr != vec.end(); ++itr) {
    if (is_vector<T>()) ostr << "\n" << *itr;
    else ostr << ' ' << *itr;
  }
  return ostr;
}

string candy = "753";

void make_candy(vector<string> &candies, int i, string num) {
  if (i == 0) {
    candies.push_back(num);
    return;
  }

  for (auto v : candy) {
    make_candy(candies, i-1, num + v);
  }
}

void solve() {
  int n; cin >> n;

  vi dp(9);
  dp[0] = dp[1] = 0;
  int pow3 = 27;
  int pow2 = 8;

  for (int i=2; i<9; ++i) {
    dp[i] = pow3 - pow2 * 3 + 3;
    pow3 *= 3;
    pow2 *= 2;
  }

  int pow10 = 10;
  int ans = 0;

  rep(i,9) {
    if (n >= pow10) {
      ans += dp[i];
      pow10 *= 10;
      continue;
    }

    vector<string> candies;
    make_candy(candies, i+1, "");

    map<char, int> pos;
    rep(i,3) pos[candy[i]] = i;

    for (auto str : candies) {
      bitset<3> s;
      s.set();
      for (auto c : str) {
        s.reset(pos[c]);
      }
      if (!s.any()) {
        int num = stoi(str);
        if (num <= n) ++ans;
      }
    }

    break;
  }

  cout << ans << endl;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);
  solve();
  return 0;
}


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

const int MAX = numeric_limits<int>::max();

class Node{
public:
  int _id;
  bool _isFound;
  vector<int> _adj_index; // 隣接点のid
  vector<int> _adj_vertices;  // 隣接点との距離(重み)
  int _cost;

  void init(int id, int n){
    _id = id;
    _isFound = false;
    for(auto i = 0; i < n; i++){
      _adj_vertices.push_back(MAX);
    }
  }
};


void inputAdjList(vector<Node>& graph){
  for(auto i = 0; i < graph.size(); i++){
    int id, dim;
    cin >> id >> dim;
    graph[i].init(i, graph.size());
    for(auto j = 0; j < dim; j++){
      int vertex, distance;
      cin >> vertex >> distance;
      graph[i]._adj_index.push_back(vertex);
      graph[i]._adj_vertices[graph[i]._adj_index[j]] = distance;
    }
  }
}

void dijkstra(vector<Node>& nodes, int start){
  for(auto& node : nodes){
    node._isFound = false;
    node._cost = MAX;
  }

  nodes[start]._cost = 0;

  while(true){
//  cout << endl << "while start" << endl;
    Node *doneNode = nullptr;
    for(auto& node : nodes){
//  cout << "call for start" << node._cost << endl;
      if(node._isFound || node._cost == MAX){
//  cout << "continue" << node._cost << endl;
        continue;
      }
      if(doneNode == nullptr || node._cost < doneNode->_cost){

        doneNode = &node;
//  cout << "call" << node._cost << endl;
      }
    }
    if(doneNode == nullptr){
      break;
    }

//    cout << nodes[0]._isFound << endl;
    doneNode->_isFound = true;
//    cout << nodes[0]._isFound << endl;
    for(auto i = 0; i < doneNode->_adj_index.size(); i++){
//      cout << "i " << i << endl;
      auto nextIndex = doneNode->_adj_index[i];
      auto cost = doneNode->_cost + doneNode->_adj_vertices[doneNode->_adj_index[i]];
//    cout << endl << nextIndex << endl;
//    cout << cost << endl;
//    cout << nodes[nextIndex]._cost << endl;
      if(nodes[nextIndex]._cost == MAX || cost < nodes[nextIndex]._cost){
        nodes[nextIndex]._cost = cost;
//    cout << "called " << endl;
      }
    }
  }
}


int main(){
  int n;
  cin >> n;
  vector<Node> graph(n);

  inputAdjList(graph);
  dijkstra(graph, 0);

  for(auto g : graph){
    cout << g._id << " " << g._cost << endl;
  }

  return 0;
}


Measured memory_bytes: 3236
from sys import stdin


def main():
    w = next_str()
    dic = dict()

    ans = "Yes"

    for v in w:
        if v not in dic:
            dic[v] = 0

        dic[v] += 1

    for v in dic.values():
        if v % 2 != 0:
            ans = "No"
            break

    print(ans)


def next_str():
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

#define mt make_tuple
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sqr(x) ((ll)(x) * (x))
double dp[3100][3100];
int main()
{
    int n;
    cin >> n;
    vector <double> v(n+1);
    for(int i = 1; i <= n; i++)
    {
        cin>>v[i];
    }
    dp[0][0] = 1;
    for(int i = 1; i <=n; i++)
    {
        for(int j = 0; j < i; j++)
        {
            if(j)dp[i][j]+=dp[i-1][j-1]*v[i];
            dp[i][j]+=dp[i-1][j]*(1-v[i]);
        }
        dp[i][i]=dp[i-1][i-1]*v[i];
    }

    double resenje = 0;

    for(int i = (n + 1) / 2; i <= n; i++)
    {
        resenje += dp[n][i];
    }

    cout << fixed << setprecision(10) << resenje << '\n';

    return 0;
}


Measured memory_bytes: 72448
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  int N; cin >> N;
  vector<pair<int, int>> pos, neg;
  int all_sum = 0;
  for (int i = 0; i < N; ++i) {
    string S; cin >> S;
    int sum = 0, vmin = 0;
    for (char c : S) {
      if (c == '(') ++sum;
      else          --sum;
      vmin = min(vmin, sum);
    }
    if (sum > 0) pos.emplace_back(vmin, sum);
    else         neg.emplace_back(vmin - sum, -sum);
    all_sum += sum;
  }
  if (all_sum != 0) {
    cout << "No" << endl;
    return 0;
  }

  sort(pos.rbegin(), pos.rend());
  sort(neg.rbegin(), neg.rend());

  all_sum = 0;
  for (auto [vmin, sum] : pos) {
    if (all_sum + vmin < 0) {
      cout << "No" << endl;
      return 0;
    }
    all_sum += sum;
  }

  all_sum = 0;
  for (auto [vmin, sum] : neg) {
    if (all_sum + vmin < 0) {
      cout << "No" << endl;
      return 0;
    }
    all_sum += sum;
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 11256
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>

#define nl '\n'

int a, b;

using namespace std;

int main(){
    cin >> a >> b;

    if(a < 10 && b < 10 && a > 0 && b > 0){
        cout << a*b;
    } else{
        cout << -1;
    }

}

//g++ -std=c++14 comp.cpp -o b; ./b.exe


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

Measured memory_bytes: 128