akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Optional;
import java.util.OptionalDouble;
import java.util.stream.DoubleStream;
import java.util.stream.Stream;

public class Main {

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

      String line;
      String[] lines;
      double[] s;
      while( !(line = br.readLine()).equals("0") ){

        int n = Integer.parseInt(line);
        lines = br.readLine().split(" ");

        s =
          Stream.of(lines)
            .parallel()
            .mapToDouble(Double::parseDouble)
            .toArray();
        
        double dm =
          Arrays.stream(s)
            .parallel()
            .average()
          .getAsDouble();

        double result =
        Arrays.stream(s)
          .parallel()
          .map(d -> Math.pow((d-dm),2) / n)
          .sum();

        System.out.printf("%.8f\n" , Math.sqrt(result));
      }
    }
  }
}


Measured memory_bytes: 33536
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

constexpr int maxN = 10005;
constexpr int maxM = 400005;

int N, M;

int adj[maxN], gto[maxM], gnxt[maxM], length[maxM], cost[maxM], e;
void add_edge(int u, int v, int d, int c) {
    gto[e] = v; length[e] = d; cost[e] = c; gnxt[e] = adj[u]; adj[u] = e++;
}

void print_edge(int s) {
    printf("%d:", s);
    for (int e = adj[s]; ~e; e = gnxt[e])
        printf(" %d", gto[e]);
    putchar('\n');
}

int dis[maxN], pre[maxN];
int qu[maxN], qh, qt; bool inq[maxN];
void bellman_ford(int s) {
    memset(dis, 0x3f, sizeof dis); dis[s] = 0;
    for (inq[qu[qh = qt = 0] = s] = 1; qh <= qt; inq[qu[qh++ % N]] = 0)
        for (int u = qu[qh % N], e = adj[u], v = gto[e]; ~e; v = gto[e = gnxt[e]])
            if (dis[v] > dis[u] + length[e]) {
                dis[v] = dis[u] + length[e];
                pre[v] = cost[e];
                if (!inq[v]) inq[qu[++qt % N] = v] = 1;
            } else if (dis[v] == dis[u] + length[e]) {
                pre[v] = min(pre[v], cost[e]);
            }
}

int main() {
    while (~scanf("%d%d", &N, &M) && (N || M)) {
        memset(adj, -1, sizeof adj);
        for (int i = 0; i != M; ++i) {
            int u, v, d, c; scanf("%d%d%d%d", &u, &v, &d, &c);
            add_edge(u, v, d, c); add_edge(v, u, d, c);
        }
        bellman_ford(1);
        long long ans = 0;
        for (int i = 1; i <= N; ++i) ans += pre[i];
        printf("%lld\n", ans);
    }
    return 0;
}

Measured memory_bytes: 8868
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();
        int k = sc.nextInt();
        if(k == 1) System.out.println(0);
        else System.out.println(n-k);
    }

    private static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;

        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }

        private int readByte() {
            if (hasNextByte())
                return buffer[ptr++];
            else
                return -1;
        }

        private static boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

        public boolean hasNext() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr]))
                ptr++;
            return hasNextByte();
        }

        public String next() {
            if (!hasNext())
                throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        public long nextLong() {
            if (!hasNext())
                throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
                throw new NumberFormatException();
            return (int) nl;
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}



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

unsigned getSerial( int y, int m, int d ){
	if ( y < 0 || y > 2000 ) return 0;
	int month[ 12 ] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
	unsigned serial = 0;
	serial += ( y - 1 ) * 365 + ( y - 1 ) / 4;
	if ( !( y % 4 ) ) month[ 1 ] = 29;
	for ( int i = 0; i < m - 1; ++i ){
		serial += month[ i ];
	}
	serial += d;
	return serial;
}

int main(){
	int y, m, d;
	unsigned serial;

	while ( cin >> y >> m >> d ){
		if ( y < 1868 ){
			cout << "pre-meiji" << endl;
			continue;
		}else if ( y > 1989 ){
			cout << "heisei " << y - 1988 << " " << m << " " << d << endl;
			continue;
		}
		serial = getSerial( y, m, d );

		if ( serial < getSerial( 1868, 9, 8 ) ){
			cout << "pre-meiji" << endl;
		}else if (  serial >= getSerial( 1989, 1, 8 ) ){
			cout << "heisei " << y - 1988 << " " << m << " " << d << endl;
		}else if ( serial < getSerial( 1912, 7, 30 ) ){
			cout << "meiji " << y - 1867 << " " << m << " " << d << endl;
		}else if ( serial < getSerial( 1926, 12,25 ) ){
			cout << "taisho " << y - 1911 << " " << m << " " << d << endl;
		}else{
			cout << "showa " << y - 1925 << " " << m << " " << d << endl;
		}
	}
	return 0;
}

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

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)

using namespace std;

vector< pair<int, char> > v;
int ind = 0;

int calc(int level){
  if(isdigit(v[ind].second)) {
    //cout<<"num: "<<v[ind].second - '0'<<" :level>"<<level<<endl;
    return (v[ind].second - '0');
  }
  vector<int> tv;
  char op = v[ind].second;
  while(ind < v.size()-1){
    ind++;
    if(v[ind].first == level+1) tv.push_back(calc(level+1));
    else{
      ind--;
      break;
    }
  }
  int ret;
  if(op == '*') ret = 1;
  else ret = 0;
  REP(i,0,tv.size()){
    if(op == '*') ret *= tv[i];
    else ret += tv[i];
  }
  //cout<<"ret> "<<ret<<endl;
  return ret;
}

int main() {
  while(1){
    int n;
    cin>>n;
    if(n == 0) break;
    string s;
    int level = 0;

    v.erase(v.begin(), v.end());
    REP(i,0,n){
      cin>>s;
      int tmp = 0;
      char c;
      REP(j,0,s.size()){
        if(s[j] == '.') tmp++;
        if(j == (s.size()-1)) c = s[j];
      }
      v.push_back(make_pair(tmp, c));
    }
    ind = 0;
    cout<<calc(0)<<endl;
  }

  return 0;
}

Measured memory_bytes: 3160
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
B.sort()
C.sort()

def mybisectl(mylist, mytarget):
  if mytarget <= mylist[0]:
    return 0
  mylen = len(mylist)
  if mylist[mylen-1] < mytarget:
    return mylen
  L, R = 0, len(mylist)
  while R-L > 0:
    mid = (R+L) //2
    mymid = mylist[mid]
    mymidl = mylist[mid-1]
    if (mymidl < mytarget) and (mytarget <= mymid):
      return mid
    else:
      if mytarget <= mymidl:
        R = mid
      else:
        L = mid

B_kinds = [0] + [mybisectl(A, B[i]) for i in range(N)]
for i in range(N):
  B_kinds[i+1] += B_kinds[i]

ans = 0
for i in range(N):
  ans += B_kinds[mybisectl(B, C[i])]

print(ans)

Measured memory_bytes: 23328
s=input()
a=(int(s[0])-0)*10+int(s[1])
b=(int(s[2])-0)*10+int(s[3])
if 1<=b<=12 and (12<a or a==0):
    print("YYMM")
elif 1<=a<=12 and (12<b or b==0):
    print("MMYY")
elif 1<=a<=12 and 1<=b<=12: 
    print("AMBIGUOUS")
else:
    print("NA")



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

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

int main()
{
    int n;
    cin >> n;
    vector<long long> a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    long long ans = 0;
    rep(i, n - 1) ans += a[n - (i + 1) / 2 - 1];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4840
n,k=[int(k) for k in raw_input().split(" ")]


nbc=[0]

nbk=[0]*k

for i in range(1,n+1):
    nbk[i%k]+=1

res=0
for i in range(k):
    if (i+i)%k==0:
        res+=nbk[i]**3

print res


Measured memory_bytes: 10500
A, B = map(int, input().split())

mina = 12.5 * A 
maxa = 12.5 * A + 12.5
minb = 10 * B 
maxb = 10 * B + 10

Min = int(min(mina, minb))
Max = int(max(maxa, maxb)) + 1

ans = -1
for i in range(Min, Max+2):
    if (mina <= i) and (minb <= i) and (i < maxa) and (i < maxb):
        ans = i
        break
print(ans)

Measured memory_bytes: 3064
r, g, b, n = list(map(int, input().split()))

a1, a2, a3 = sorted([r, g, b])
ans = 0
a3n = n // a3
a2n = n // a2
for i in range(a3n + 1):
    for j in range(a2n + 1):
        r = n - (a3 * i + a2 * j)
        if r < 0:
            break
        if r % a1 == 0:
            ans += 1

print(ans)


Measured memory_bytes: 40300
import java.util
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val n, k = sc.nextInt()
    var x = new Array[Int](n)
    var ans = 0
    for(i <- 0 until n) {
      x(i) = sc.nextInt()
      ans += Math.min(x(i), k-x(i))
    }
    println(ans*2)
  }
}


Measured memory_bytes: 27304
// A. 

#include <iostream>
#include <algorithm>
#include <sstream>
#include <cstdio>
#include <cstring>

using namespace std;

int memo[102][102][102];

int win(int l, int m, int r) {
	int &ret = memo[l][m][r];
	if (!ret) {
		if (m == 1 && r == 0) {
			ret = 1;
			return ret;
		}
		if (l == 0 && m == 0) {
			ret = 3;
			return ret;
		}
		ret = 2;
		if (m > 0) {
			int x = win(r, m - 1, l + 1);
			if (x == 1) {
				ret = 3;
			}
			if (x == 3) {
				ret = 1;
				return ret;
			}
		}
		if (l > 0) {
			int x = win(r, m + 1, l - 1);
			if (x == 1) {
				ret = 3;
			}
			if (x == 3) {
				ret = 1;
				return ret;
			}
		}
	}
	return ret;
}

int main(int argc, char *argv[])
{
	memset(memo, 0, sizeof(memo));
	int n, a, b;
	cin >> n >> a >> b;
	if (a > b) {
		a = n - a + 1;
		b = n - b + 1;
	}
	int l = a - 1;
	int m = b - a - 1;
	int r = n - b;
	int ans = win(l, m, r);
	const char *res[] = { "", "Alice", "Draw", "Borys" };
	cout << res[ans] << endl;
	return 0;
}


Measured memory_bytes: 4352
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#define int long long

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define FOR(i,a,b) for(int i=(a), i##_len=(b);i< i##_len; ++i)
#define CLR(a) memset((a), 0 ,sizeof(a))
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define INF (3e15)

using namespace std;

int N;
int A[200005];

signed main()
{
    cin >> N;
    REP(i, N) cin >> A[i];

    deque<int> dq;
    REP(i, N)
    {
        if (N%2 == 0)
        {
            i%2 != 0 ? dq.push_front(A[i]) : dq.push_back(A[i]);
        }
        else
        {
            i%2 == 0 ? dq.push_front(A[i]) : dq.push_back(A[i]);
        }
    }

    int index = 0;
    for (int x : dq)
    {
        if (index != 0) printf(" ");
        printf("%lld", x);
        ++index;
    }
    printf("\n");

    return 0;
}

Measured memory_bytes: 5888
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
//#define int ll
#define INF INT_MAX/10
#define MOD 1000000007

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;

int Input[100100];
vector<int> Temp;

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

  int maxx = *max_element(Input, Input+N);


  int ans = 0;
  for (int i = 1; i <= maxx; i++) {
    Temp.assign(N, 0);
    for (int j = 0; j < N; j++) {
      Temp[j] = (Input[j] - i >= 0 ? 1 : 0);
    }
    // for (int j = 0; j < N; j++) {
    //   cout << Temp[j] << " ";
    // }
    // cout << endl;
    Temp.insert(Temp.begin(), 0);
    int acc = 0;
    for (int j = 1; j <= N; j++) {
      acc += (Temp[j] == 1 && Temp[j-1] == 0);
    }
    // cout << acc << endl;
    ans += acc;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,b,a) for(int i=b;i>=a;i--)
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forenska(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-x))
#define GREATER(x) x,vector<x>,greater<x>
#define randIn(L,R) (((LL)rand()*rand())%(R-L)+L)
#define __lcm(a,b) ((a)/__gcd(a,b)*(b))
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
typedef vector<int> vec;
typedef vector<LL> vecL;
typedef vector<pii> vecP;
typedef vector<pLL> vecPL;
typedef vector<string> vecS;
typedef vector<vec> mat;
typedef complex<double> point;
const long double PI=3.14159265358979323846264338327950288419716939937510582097;
const LL INFLL=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const long double EPS=1e-10;
int read()
{
    int x=0;
    char ch=' ';
    bool flag=false;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')flag=true;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return flag?-x:x;
}

int main()
{
	int n;
	cin>>n;
	int ans=0;
	For(i,1,n)
	{
		int x=i,cnt=0;
		For(j,1,x)
		{
			if(x%j==0)cnt++;
		}
		if(x%2 && cnt==8)ans++;
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 256
R, G, B, N = map(int, input().split())

count = 0
for i in range(N // R + 1):
    n = N - R * i
    for j in range(n // G + 1):
        if (n - G*j) >= 0 and (n - G*j) % B == 0:
            count += 1

print(count)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define For(i,m,n) for(int i=m;i<n;i++)
#define FOR(n) for(int i=0;i<n;i++)
#define ll long long
ll mob=1000000007;
using namespace std;
int main()
{ int a;
std::cin >> a;
long s=a/500;
long d=a%500;
long f=d/5;

long h=(s*1000)+(f*5);
std::cout <<h;





return 0;
}


Measured memory_bytes: 256
import fractions
from functools import reduce
N = int(input())
A = [int(i) for i in input().split()] 

def lcm(x, y):
  return (x * y) // fractions.gcd(x, y)

l = reduce(lcm, A)

print(sum(list(map(lambda x: (l-1) % x, A))))

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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);	cout.tie(NULL);
	int n;	cin >> n;
	int ans = 0;
	for (int i = 1; i <= n; i += 1) {
		int a;	cin >> a;
		if (i&1 and a&1)
			ans++;
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <vector>
#define N 55
using namespace std;

int n,m, s, k, cnt, v[N];
vector<int> a[N], b[N];
void f(int p) {
	int i;
	if (v[p] == k) return;
	v[p] = k;
	for (i = 0; i < a[p].size(); i++) {
		if (b[p][i] == k) continue;
		f(a[p][i]);
	}
}
int main()
{
	int i,j, t1,t2;
	cin >> n >> m;
	for (i = 1; i <= m; i++) {
		scanf ("%d %d", &t1, &t2);
		a[t1].push_back(t2);
		b[t1].push_back(i);
		a[t2].push_back(t1);
		b[t2].push_back(i);
	}
	for (k = 1; k<= m; k++) {
			s = 0;
		for (j = 1; j <= n; j++) {
			if (v[j] ==k) continue;
			s++;
			f(j);
		}
		if (s > 1) cnt++;
	}
	cout << cnt;
	return 0;
}



Measured memory_bytes: 256
#include "iostream"

using namespace std;

int main()
{
	int n;
	int i = 1;
	while (true) {
		cin >> n;
		if (n != 0) {
			cout << "Case " << i << ": " << n << endl;
			i++;
		}
		else {
			break;
		}
	}

    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(0),cin.tie(0);
#define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a)
#define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define mt make_tuple
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define bit(x,i) ((x>>(i-1))&1)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1<<(i-1)))
#define gg exit(0);

const int N=310,
          M=1000000007;

int n,m,ret;
int l[N],r[N],c[N];
int f[N][N][N];
vector<int> qr[N];

main(){
    #define task "lysieu"
    //freopen(task".inp","r",stdin);
    //freopen(task".out","w",stdout);

    n=in,m=in;
    forinc(i,1,m){
        l[i]=in,r[i]=in,c[i]=in;
        qr[r[i]].pb(i);
    }

    auto chk=[&](int i,int j,int t){
        if(i && i==j) return 0;
        if(j && j==t) return 0;
        if(t && t==i) return 0;
        forv(k,qr[max({i,j,t})]){
            if((i>=l[k])+(j>=l[k])+(t>=l[k])!=c[k])
                return 0;
        }
        return 1;
    };

    f[0][0][0]=1;
    forinc(x,0,n-1){
        forinc(y,0,x) forinc(z,0,y){
            vector<int> per={x,y,z};
            sort(all(per));
            do{
                int i=per[0], j=per[1], t=per[2];
                if(!f[i][j][t] || !chk(i,j,t)) continue;
                f[x+1][j][t]=(f[x+1][j][t]+f[i][j][t])%M;
                f[i][x+1][t]=(f[i][x+1][t]+f[i][j][t])%M;
                f[i][j][x+1]=(f[i][j][x+1]+f[i][j][t])%M;
            } while(next_permutation(all(per)));
        }
    }
    forinc(i,0,n)
        forinc(j,0,n)
            forinc(t,0,n)
                if(max({i,j,t})==n && chk(i,j,t))
                    ret=(ret+f[i][j][t])%M;
    cout<<ret;
}


Measured memory_bytes: 227584
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int c = 0;
        int N = sc.nextInt();
        int D = sc.nextInt();
        double[] X = new double[N];
        double[] Y = new double[N];
        double[] X2 = new double[N];
        double[] Y2 = new double[N];
        double[] K = new double[N];
        for (int i = 0; i < N; i++) {
            X[i] = sc.nextDouble();
            Y[i] = sc.nextDouble();
            X2[i] = X[i]*X[i];
            Y2[i] = Y[i]*Y[i];
            K[i] = Math.sqrt(X2[i] + Y2[i]);
            if (K[i] <= D) {
                c = c + 1;
            } else {
                c = c;
            }
        }
        System.out.println(c);
    }
}

Measured memory_bytes: 72344
#include <bits/stdc++.h> 
#define ll long long int
using namespace std; 
int n,m,x;  
ll ans=INT_MAX;
vector<vector<int>>v(100,vector<int>(100));
vector<int> cost(100);


void subsetsUtil(vector<int>& A, vector<vector<int> >& res, 
                 vector<int>& subset, int index) 
{ 
    res.push_back(subset); 
    for (int i = index; i < A.size(); i++) { 
  
        // include the A[i] in subset. 
        subset.push_back(A[i]); 
  
        // move onto the next element. 
        subsetsUtil(A, res, subset, i + 1); 
  
        // exclude the A[i] from subset and triggers 
        // backtracking. 
        subset.pop_back(); 
    } 
  
    return; 
} 
  
// below function returns the subsets of vector A. 
vector<vector<int> > subsets(vector<int>& A) 
{ 
    vector<int> subset; 
    vector<vector<int> > res; 
  
    // keeps track of current element in vector A; 
    int index = 0; 
    subsetsUtil(A, res, subset, index); 
  
    return res; 
} 

bool check(vector<int> has){
    for(int a=0;a<m;a++){
        if(has[a]<x)return false;
    }
    return true;
}


int main(){
    cin >> n >> m >> x;
    vector<int> A(0);
    for(int i=0;i<n;i++){
        A.push_back(i);
    }
    vector<int> min1(m);
    for(int i=0;i<n;i++){
        cin >> cost[i];
        for(int j=0;j<m;j++){
            cin >> v[i][j];
            min1[j]+=v[i][j];
        }
    
    }
    bool ok = true;
    for(int i=0;i<m;i++){
        if(min1[i]<x)ok=false;
    }
    if(ok){
        vector<vector<int>>res=subsets(A);
        for(int i = 0;i<res.size();i++){
            vector<int> ans1(m);
                vector<int> ind = res[i];
                long long int cost1 = 0;
                for(int k:ind){
                    for(int j=0;j<m;j++){
                        ans1[j]+=v[k][j];
                    }
                    cost1+=cost[k];
                }
                if(check(ans1)){
                   ans=min(ans,cost1);
                }
            }
        cout << ans;
    }
    else cout << -1;
}

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int d,s,t;
    cin >> d >> t >> s;
    if(d/s+(d%s > 0) <= t)cout << "Yes";
    else cout << "No";
    return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<vector>

using namespace std;
vector <vector<int> > randb (vector <vector<char> >tile,vector <vector<int> > canmove,int si,int sj,int w,int h);
int main(){
  int w,h;
  cin >> w >> h;
  while(w != 0 || h != 0){
    vector <vector<char> > tile(h,vector<char>(w));
    vector <vector<int> > canmove(h,vector<int>(w,0));
    int si,sj;
    int cnt = 0;
    for(int i = 0 ; i < h ; i++){
      for(int j = 0 ; j < w ; j++){
        cin >> tile[i][j];
        if(tile[i][j] == '@'){
          canmove[i][j] = 1;
          si = i;
          sj = j;
        }
      }
    }
    canmove = randb(tile,canmove,si,sj,w,h);
    for(int i = 0 ; i < h ; i++){
      for(int j = 0 ; j < w ; j++){
          cnt += canmove[i][j];
        }
      }
      cout << cnt << endl;
    cin >> w >> h;
  }
  return 0;
}

 vector <vector<int> > randb (vector <vector<char> >tile,vector <vector<int> > canmove,int si,int sj,int w,int h){
   if( si+1 < h && tile[si+1][sj] == '.'  && canmove[si+1][sj] == 0){
     canmove[si+1][sj] = 1;
     canmove = randb(tile,canmove,si+1,sj,w,h);
   }
   if( si-1 >= 0 && tile[si-1][sj] == '.'  && canmove[si-1][sj] == 0){
     canmove[si-1][sj] = 1;
     canmove = randb(tile,canmove,si-1,sj,w,h);
   }
   if( sj+1 < w && tile[si][sj+1] == '.'  && canmove[si][sj+1] == 0){
     canmove[si][sj+1] = 1;
     canmove = randb(tile,canmove,si,sj+1,w,h);
   }
   if( sj-1 >= 0 && tile[si][sj-1] == '.'  && canmove[si][sj-1] == 0){
     canmove[si][sj-1] = 1;
     canmove = randb(tile,canmove,si,sj-1,w,h);
   }

   return canmove;

}


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

int main() {
	int a, b;
	string str;
	cin >> a >> b;
	if (a < b) {
		str = "a < b";
	}
	else if (a > b) {
		str = "a > b";
	}
	else {
		str = "a == b";
	}
	cout << str << endl;
	return 0;
}

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

int mod = 1000000007;
int64_t large = 9223372036854775807;

int main()
{
    string S;
    cin >> S;
    if (S == "Sunny")
        cout << "Cloudy";
    if (S == "Cloudy")
        cout << "Rainy";
    if (S == "Rainy")
        cout << "Sunny";
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define LOOP(i) while(i--)
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	string S;
	while(cin>>S){
		int win=0;
		REP(i,3){
			if((S[3*i]=='o' && S[3*i+1]=='o' && S[3*i+2]=='o') ||
				(S[i]=='o' && S[3+i]=='o' && S[6+i]=='o')){
				win = 1;
				break;
			}
		}
		if((S[0]=='o' && S[4]=='o' && S[8]=='o') ||
			(S[2]=='o' && S[4]=='o' && S[6]=='o')){
			win = 1;
		}
		if(win==1){
			out('o');
			continue;
		}
		REP(i,3){
			if((S[3*i]=='x' && S[3*i+1]=='x' && S[3*i+2]=='x') ||
				(S[i]=='x' && S[3+i]=='x' && S[6+i]=='x')){
				win = 2;
				break;
			}
		}
		if((S[0]=='x' && S[4]=='x' && S[8]=='x') ||
			(S[2]=='x' && S[4]=='x' && S[6]=='x')){
			win = 2;
		}
		if(win==2){
			out('x');
			continue;
		}
		out('d');
	}
	
	return 0;
}



Measured memory_bytes: 3024
#include<stdio.h>
#include<string.h>
int main(void)
{
	int i,j,k,s,len,n,flg;
	char a[11],b[21];
	scanf("%s",a);
	scanf("%d",&n);
	s=0;
	len=strlen(a);
	for(k=0;k<n;k++){
		scanf("%s",b);
		for(i=0;i<10;i++){
			b[i+10]=b[i];
		}
		for(i=0;i<20;i++){
			flg=1;
			for(j=0;j<len;j++){
				if(i+j>=20 || b[i+j]!=a[j]){
					flg=0;
				}
			}
			if(flg==1){
				s=s+1;
				break;
			}
		}
	}
	printf("%d\n",s);
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<queue>
#include<vector>
#include<cstdio>
#include<cstring>

using namespace std;

struct P{int c,r;};
struct State{
  int t;
  int pos, remain;
  bool operator < (const State& st) const {
    return t > st.t;
  }
};

const int MAX = 5001;
const int INF = (1<<25);
int T[MAX][MAX];
vector<int> Edge[MAX];
P price[MAX];
int N,K;

void input(){
  scanf("%d %d",&N,&K);
  for(int i = 0; i < N; i++) scanf("%d %d",&price[i].c, &price[i].r);
  for(int i = 0; i < K; i++){
    int a,b;
    scanf("%d %d",&a, &b);
    a--;b--;
    Edge[a].push_back(b);
    Edge[b].push_back(a);
  }
}

void solve(){
  //fill(T[0], T[0]+MAX*MAX, INF);
  memset(T, -1, sizeof(T));
  T[0][0] = 0;
  priority_queue<State> Q;
  Q.push((State){0,0,0});
  while(!Q.empty()){
    const State now = Q.top();
    Q.pop();
    
    if(now.t > T[now.pos][now.remain]) continue;
    
    if(now.remain > 0){
      for(int i = 0; i < (int)Edge[now.pos].size(); i++){
	State nex = now;
	nex.pos = Edge[now.pos][i];
	nex.remain--;
	
	if(T[nex.pos][nex.remain] == -1 || T[nex.pos][nex.remain] > nex.t){
	  T[nex.pos][nex.remain] = nex.t;
	  Q.push(nex);
	}
      }
    }
    
    State nex = now;
    nex.t += price[now.pos].c; 
    nex.remain = price[now.pos].r;
    if(T[nex.pos][nex.remain] == -1 || T[nex.pos][nex.remain] > nex.t){
      T[nex.pos][nex.remain] = nex.t;
      Q.push(nex);
    }
  }
  
  int ans = INF;
  for(int i = 0; i < MAX; i++) 
    if(T[N-1][i] >= 0) ans = min(ans,T[N-1][i]);
  printf("%d\n",ans);
}

int main(){

  input();
  solve();
  return 0;
}

Measured memory_bytes: 99420
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <queue>
#include <stack>
#include <string.h>
#include <list>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)


int main(){
    int n;
    cin >> n;
    if(n%2 == 0)cout << n <<endl;
    else cout << n*2 << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;

/**
 * ACB069
 * D - Grid Coloring
 */
public class Main {

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

		line = br.readLine();

		int H, W;
		H = parseInt(line.substring(0, line.indexOf(' ')));
		W = parseInt(line.substring(line.indexOf(' ') + 1));

		String[][] c = new String[H][W];

		int N = parseInt(br.readLine());

		StringTokenizer st = new StringTokenizer(br.readLine());

		int y = 0, x = 0;

		for (int i = 1; i <= N; i++) {
			int a = parseInt(st.nextToken());
			for (int j = a; j > 0; j--) {
				c[y][x] = String.valueOf(i);
				if (y % 2 == 0) {
					if (x == W - 1) y++;
					else x++;
				} else {
					if (x == 0) y++;
					else x--;
				}
			}
		}

		for (int i = 0; i < H; i++) {
			System.out.println(String.join(" ", c[i]));
		}
	}
}

Measured memory_bytes: 23252
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;

const int INF = INT_MAX;
const long long INFL = 1LL<<40;
const double PI = atan(1)*4;
const long long MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}


int main() {
    int n,a,b;cin>>n>>a>>b;
    
    string s;cin>>s;
    int c = 0;
    int f = 0;
    rep(i,s.size()){
        if(s[i]=='b')f++;
        if(s[i]=='a' && c<a+b) {c++;cout<<"Yes"<<endl;}
        else if(s[i]=='b' && c<a+b && f<=b ) {c++;cout<<"Yes"<<endl;}
        else cout<<"No"<<endl;
    
        
        
    }
    return 0;
}





Measured memory_bytes: 896
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    int d, t, s;
    cin >> d >> t >> s;
    cout << (s * t >= d ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
int main()
{
  int N;
  char S[101],T[101];
  scanf("%d",&N);
  scanf("%s %s",&S,&T);
  
  for(int i=0;i<N;i++){
    printf("%c",S[i]);
    printf("%c",T[i]);
  }
}


Measured memory_bytes: 128
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

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

  int N, C;
  cin >> N >> C;
  vector<vector<pair<int, int>>> v(C);
  rep(i, 0, N) {
    int a, b, c;
    cin >> a >> b >> c;
    c--;
    v[c].push_back(make_pair(a, b));
  }
  vector<int> imos(1e5 + 10, 0);
  rep(i, 0, C) {
    if(v[i].empty())continue;
    sort(all(v[i]));
    int b = 1;
    rep(j, 1, v[i].size()) {
      if (v[i][b - 1].second == v[i][j].first) {
        v[i][b - 1].second = v[i][j].second;
      } else {
        v[i][b++] = v[i][j];
      }
    }
    rep(j, 0, b) { imos[v[i][j].first - 1]++, imos[v[i][j].second]--; }
  }
  rep(i, 1, imos.size()) imos[i] += imos[i - 1];

  cout << *max_element(all(imos)) << endl;

  return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    while(true){
        ll H, W;
        cin >> H >> W;
        if (H == 0 && W == 0) break;
        
        string s, t;
        rep(i, W) s += '#';
        t += '#';
        rep(i, W - 2) t += '.';
        t += '#';

        cout << s << '\n';
        rep(i, H - 2) cout << t << '\n';
        cout << s << '\n'
             << '\n';
    }
}


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

template <typename T>
void print_vec(const vector<T>& v, bool is_reverse=false, ll num=0){
  if(num == 0) num = (ll)v.size();
  cout << endl; cout << "i=  ";for(ll i=0; i<num; i++) cout << i << "   ";cout << endl;  
  cout << "    ";
  if(is_reverse) for(ll i=num-1; i>=0; i--){ cout<<v[i]; if(i!=0) cout<<"   ";}
  else for(ll i=0; i<num; i++){ cout<<v[i]; if(i!=num-1) cout<<"   ";}
  cout << endl;
}

// template <typename T>
// void print_pairvec(const vector<T> &v, ll num=0){
//   if(num == 0) num = (ll)v.size();
//   cout << endl; for(ll i=0; i<num; i++){ cout << v[i].first << " " << v[i].second << endl;}
// }
template <typename T>
void print_pairvec(const T &_pair, ll num=0){
  cout << endl; for(pair<ll, int> x: _pair){ cout << x.first << " " << x.second << endl;}
}

template <typename T>
void print_vec2(const vector<vector<T>>& v){
  cout << endl; cout << "       ";
  for(ll i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(ll i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(ll j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  for(int i=0; i<n; i++) cin >> h[i];
  sort(h.begin(), h.end());

  int ans = 1e9+1;
  k--;
  for(int i=k; i<n; i++) ans = min(ans, h[i] - h[i-k]);
  cout << ans << endl;

  return 0;
  // cout << fixed;//小数点を確実に10桁で表示するためのもの
  // cout << setprecision(10); 
}


Measured memory_bytes: 3732
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <map>
#include <vector>
#include <iomanip>

using namespace std;

int main(void) {
  int N;
  cin >> N;
  vector<string> S;
  string s;
  int T[N];
  for (int i = 0; i < N; i++) {
    cin >> s >> T[i];
    S.push_back(s);
  }
  string X;
  cin >> X;
  int a = 0;
  int f = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] == X) {
      f = 1;
      continue;
    }
    if (f == 1) {
      a += T[i];
    }
  }
  cout << a << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
l = [int(i) for i in input().split()]

memo = [0]*n

def dp(n,l,memo):
    for i in range(1,n):
        if i == 1:
            memo[i] = abs(l[i] - l[i-1])
        else:
            memo[i] = min(memo[i-1] + abs(l[i] - l[i-1]),memo[i-2] + abs(l[i] - l[i-2]))
            
    return memo


ans = dp(n,l,memo)

print(ans[n-1])


Measured memory_bytes: 13928
package main

import "fmt"

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_4_C>
 */

func init() {
}

func main() {
	var a,b int
	var op string
	for{
		fmt.Scanf("%d %s %d",&a,&op,&b)
		if op == "?"{
			break
		}
		if op == "+"{
			fmt.Println(a+b)
		}else if op == "-"{
			fmt.Println(a-b)
		}else if op == "*"{
			fmt.Println(a*b)
		}else if op == "/"{
			fmt.Println(a/b)
		}
	}
}

Measured memory_bytes: 1124
#include <iostream>
#include <vector>
#include <cmath>

int main(int argc, char** argv) {
  int N;
  std::cin >> N;
  std::vector<long long> H(N);
  for (auto& e : H) std::cin >> e;
  std::vector<long long> Sum_H(N);
  Sum_H[1] = std::abs(H[1] - H[0]);
  for (auto i = 2;i < N;++i) {
    Sum_H[i] = std::min(Sum_H[i-1] + std::abs(H[i] - H[i-1]), Sum_H[i-2] + std::abs(H[i] - H[i-2]));
  }
  std::cout << Sum_H[N-1] << '\n';
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
multiset<int>s;
int main()
{

    int ans=0;
    int n;scanf("%d",&n);
    for(int i=1,x;i<=n;i++)
    {
        scanf("%d",&x);
        x=-x;
        multiset<int>::iterator it=s.upper_bound(x);
        if(it==s.end())
        {
            ans++;
        }
        else
        {
            s.erase(it);
        }
        s.insert(x);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
#define vecmin(A) *min_element(A.begin(),A.end());
#define vecmax(A) *max_element(A.begin(),A.end());
typedef long long ll;

vector<vector<int>> d(10,vector<int>(9));

void warshall_floyd(int n) {
  for (int k = 0; k < n; k++){       // 経由する頂点
    for (int i = 0; i < n; i++) {    // 始点
      for (int j = 0; j < n; j++) {  // 終点
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}

int main(){
  int h,w;
  cin >> h >> w;
  rep(i,10) rep(j,10){
    cin >> d[i][j];
  }
  warshall_floyd(10);
  int ans = 0;
  rep(i,h)rep(i,w){
    int x;
    cin >> x;
    if(x != -1)ans += d[x][1];
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
# frozen_string_literal: true

s = gets.chomp.chars
b = s.chunk { |e| e == '<' }.map { |e| e[1].size }
b.push 0
b.push 0 if s[-1] == '>'
a = []
dflag = true
if s[0] == '<'
  a = (0...b[0]).to_a
  a.push [b[0], b[1]].max
else
  dflag = false
  a = (0..b[0]).to_a.reverse
end
(1...(b.size)).each do |i|
  if dflag
    (b[i] - 1).downto(0).each do |j|
      a.push j
    end
  else
    (1...b[i]).each do |j|
      a.push j
    end
    a.push [b[i], b[i + 1]].max
  end
  dflag = !dflag
end
puts a.reduce(:+)


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

int main() {
	int a, b, c, d, n[100];

	cin >> a >> b;
	for (int i = 0; i<a; i++) {
		n[i] = 0;
	}
	for (int i = 0; i<b; i++) {
		cin >> c >> d;
		n[c - 1] = n[c - 1] + 1;
		n[d - 1] = n[d - 1] + 1;
	}
	for (int i = 0; i<a; i++) {
		cout << n[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main()
{
    string s; cin >> s;
    ll d = 0;
    for(auto x : s)
    {
        if(x == '7')
        {
            d = 1;
            break;
        }
    }
    if(!d)
        cout << "No\n";
    if(d)
        cout << "Yes\n";
}


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

int main(){
  int64_t N,H;
  cin>>N>>H;
  vector<int64_t> a(N),b(N);
  for(int i=0;i<N;++i) cin>>a[i]>>b[i];

  sort(a.begin(),a.end());
  sort(b.begin(),b.end());

  int iter=b.end()-lower_bound(b.begin(),b.end(),a[N-1]);

  int64_t cnt=0;
  
  for(int i=N-1;i>N-1-iter;--i){
    H -= b[i];
    ++cnt;
    if(H<=0) break;
  }
  
  if(H>0){
    cnt += (H+a[N-1]-1)/a[N-1];
  }

  cout<<cnt<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for(int i = 0; i < n; i++)
const int INF = 1000000007;


ll return_ans(ll x);

int main() {
	ll n;
	cin >> n;
	ll ans = 0;
	for(ll i = 1; i < n; i++){
		ans += return_ans(n-i); 
	}
	
	
	cout << ans;
	return 0;
}


ll return_ans(ll x){
	ll count = 1;
	for(ll i = 2; i*i <= x; ++i){
		if(x%i != 0) continue;
		ll ex = 0;
		while(x%i == 0){
			++ex;
			x /= i;
		}
		if(ex != 0){
			count *= (ex+1);
		}	
	}
	if (x != 1) count *= 2;
	return count;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) int ab;cin>>ab;(p).push_back(ab);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
	
	int N;
	cin>>N;
	ll ans=0;
	int max=0;
	fx(N){
		int a;
		cin>>a;
		if(a>max){
			ans+=max;
			max=a;
		}else{
			ans+=a;
		}
	}
	ans+=max/2;
	ce(ans)
}


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

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

  int cnt=0;
  int maxcnt=0;
  for (long i=0; i<S.length(); i++) {
    if (S[i]=='A' || S[i]=='C' || S[i]=='G' || S[i]=='T') {
      cnt++;
    } else {
      maxcnt=max(maxcnt, cnt);
      cnt = 0;
    }
  }
  
  maxcnt=max(maxcnt, cnt);
  cout << maxcnt << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define MAXN 100005
#define MAXA 1000000005
#define pb push_back
#define INF 999999999999999LL
using namespace std;
ll n,ar[MAXN],ar1[MAXN],art[MAXN],ans,bl,br,bm,ba,st[7*MAXN],l[7*MAXN],r[7*MAXN],stx,sta;
void buil(ll i){
    if (l[i]==r[i]) return;

    l[i*2]=l[i]; r[i*2]=l[i]+(r[i]-l[i])/2;
    l[i*2+1]=r[i*2]+1; r[i*2+1]=r[i];

    buil(i*2); buil(i*2+1);
}
void add(ll i){
    st[i]++;

    if (l[i]==r[i]) return;

    if (stx<=r[i*2]) add(i*2); else add(i*2+1);
}
void ret(ll i){
    if (stx<l[i]) return;

    if (r[i]<=stx) { sta+=st[i]; return; }

    ret(i*2); ret(i*2+1);
}
int main(){
    cin>>n;
    for (int i=1; i<=n; i++) cin >> ar[i];

    l[1]=-n-3; r[1]=n+3;
    buil(1);

    bl=1; br=MAXA;
    while(bl<=br){
        bm=(bl+br)/2;
        
        sta=stx=0; add(1);

        for (int i=1; i<=n; i++){
            if (ar[i]<bm) ar1[i]=-1;
            else ar1[i]=1;

            if (i) ar1[i]+=ar1[i-1];

            stx=ar1[i]; ret(1); add(1);
        }

        for (int i=0; i<7*MAXN; i++) st[i]=0;
        
        // cout<<bm<<" - "<<sta<<endl;

        if (2ll*sta>=n*(n+1)/2){
            ans=bm;
            bl=bm+1;
        }
        else br=bm-1;
    }

    cout<<ans<<endl;
}
/*
10
5 9 5 9 8 9 3 5 4 3
*/


Measured memory_bytes: 18944
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2*1e5+10;
const int MOD = 1e9 + 7;
const int INF = 1e18 + 10;
string a;
string b;
int n;
int m;
int dp[3001][3001];
int dpp[3001][3001];
string s;
int ans = 0;

void printVector(vector<char> s){
    for(auto x:s){
        cout<<x<<"";
    }
    cout<<endl;
}
int rec(int i , int j){
//    cout<<i<<" "<<j<<endl;
    if(i==0 || j==0){
        return 0;
    }
    if(dp[i][j]!=-1){
        return dp[i][j];
    }
    if(a[i-1]==b[j-1]){
        return dp[i][j]  = 1 + rec(i-1 , j-1);
    }
    else{
        return dp[i][j]  = max(rec(i-1 , j) , rec(i,j-1));
    }
}

void f(int i , int j){
//    cout<<i<<" "<<j<<endl;
    if(i==0 || j==0){
        return;
    }

    if(a[i-1]==b[j-1]){
        s+=a[i-1];
        f(i-1 , j-1);
    }
    else{
        if (dp[i-1][j]>dp[i][j-1]){
            f(i-1,j);
        }
        else{
            f(i,j-1);
        }
    }
}

void solve(){
    cin>>a;
    cin>>b;
    for(int i = 0 ; i < 3001 ; i++) for(int j = 0 ; j < 3001 ; j++) dp[i][j] = -1,dpp[i][j]=-1;
    n = a.size();
    m = b.size();
    ans = rec(n,m);
    f(n,m);
    reverse(s.begin(),s.end());
//    cout<<ans<<endl;
    cout<<s<<endl;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
//    cin>>t;
    t = 1;
    for(int i = 0 ; i < t ; i++){
        solve();
    }
    return 0;
}


Measured memory_bytes: 144616