akhauriyash/Code-Regression huggingface dataset:
n,k=map(int,input().split())
X=list(map(int,input().split()))
m=10**9
for i in range(n-k+1):
  m=min(m,abs(X[i])+abs(X[i+k-1]-X[i]),abs(X[i+k-1])+abs(X[i]-X[i+k-1]))
print(m)

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

int main() {
  int a,b,c,d,e;
  cin >> a >> b >> c >> d >> e;
  if(a==0) cout << 1 << endl;
  if(b==0) cout << 2 << endl;
  if(c==0) cout << 3 << endl;
  if(d==0) cout << 4 << endl;
  if(e==0) cout << 5 << endl;

}


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

int CountOfDigits(int64_t n) {
  int sum = 0;
  while (n > 0) {
    sum ++;
    n /= 10;
  }
  return sum;
}

int main() {
  int64_t N;
  cin >> N;
  
  int ans = CountOfDigits(N);
  
  for(int64_t i = 1ll; i*i <= N; i++){
    if(N%i!=0) continue;
    const int64_t j = N/i;
 	const int cur = max(CountOfDigits(i), CountOfDigits(j));

 	if(ans>cur){
 	ans = cur;
 	}
 }
  cout << ans << endl;
}


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

int main(){
  int n;
  cin>>n;
  map<string,int>mp;
  rep(i,n){
    string s;
    cin>>s;
    mp[s]++;
  }
  int mx=0;
  for(auto p:mp)mx=max(mx,p.second);
  for(auto p:mp){
    if(p.second!=mx)continue;
    else cout<<p.first<<endl;
  }
  
}


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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if( a+b == c || a+c == b || b+c == a ){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
//	tmp = input[1].split(" ");
	//文字列から10進数に変換するときはparseIntを使います
	var n = parseInt(input[0], 10);
	var s = input[1];
	
    var alp = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
   
   var aa='';
    for(i = 0;i<s.length;i++){
     var p = s[i]
     var r = alp.indexOf(p);
     var rr =( r +n)%26;
     aa += alp[rr];
   
    }
    console.log(aa);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
#include <stdio.h>
#include <stdlib.h>
struct pt {
    int x;
    int y;
};
int n, m;
struct pt checkpoints[300];
struct pt students[300];
int manhattan(struct pt a, struct pt b) {
    return abs(a.x - b.x) + abs(a.y - b.y);
}
int getmincheckpt(struct pt student) {
    int idx = 0;
    int dist = manhattan(student, checkpoints[idx]);
    for(int i = 1; i < m; i++) {
        if(dist > manhattan(student, checkpoints[i])) {
            idx = i;
            dist = manhattan(student, checkpoints[i]);
        }
    }
    return idx + 1;
}
int main(void) {
    scanf("%d%d", &n, &m);
    for(int i = 0; i < n; i++)
        scanf("%d%d", &students[i].x, &students[i].y);
    for(int i = 0; i < m; i++)
        scanf("%d%d", &checkpoints[i].x, &checkpoints[i].y);
    for(int i = 0; i < n - 1; i++)
        printf("%d\n", getmincheckpt(students[i]));
    printf("%d", getmincheckpt(students[n - 1]));
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int xe[125];
int main()
{
    int cnt=0,i;
    char data[1000]="";
    scanf("%s",data);
    for(i=0;i<1000;i++)
    {
        xe[(int)data[i]]++;
    }
    for(i=97;i<123;i++)
    {
        if(xe[i]%2!=0)
        {
            cnt++;
            break;
        }
    }
    if(cnt==0)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }
    return 0;
}


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

typedef long long ll;
// const int INF = 1e8;
const ll INF = 1LL << 60;
typedef pair<int, int> P;

struct edge { ll to, cost; };

ll N;
vector<vector<edge>> G;
ll dp[100100]; 

void dfs(ll v, ll par = -1, ll d = 0) {
    dp[v] = d;
    for (ll i = 0; i < G[v].size(); i++) {
        ll next = G[v][i].to, next_cost = G[v][i].cost;

        if (next != par) {
            dfs(next, v, d + next_cost);
        }
    }
}

int main() {
    cin >> N;
    G.resize(N);
    rep(i, N - 1) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--; b--;

        G[a].push_back({b, c});
        G[b].push_back({a, c});
    }

    ll Q, K;
    cin >> Q >> K;

    K--;
    dfs(K);

    // rep(i, N) {
    //     cout << i << " " << dp[i] << endl;
    // }
    // return 0;

    // x -> K -> y の最短路
    rep(i, Q) {
        ll x, y;
        cin >> x >> y;
        x--; y--;

        cout << dp[x] + dp[y] << endl;
    }
}

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

int main(){
	// sengen
	int n,m;
	// nyuryoku
	cin >> n >> m;
	int s[m][n];
	int k[m];
	int p[m];
	for(int i=0;i<m;i++){
		cin >> k[i];
		for(int j=0;j<k[i];j++){
			cin >> s[i][j];
		}
	}
	for(int i=0;i<m;i++){
		cin >> p[i];
	}
	// keisan
	int sum=0;
	for(int bit=0;bit<(1<<n);bit++){
		for(int i=0;i<m;i++){
			int check=0;
			for(int j=0;j<k[i];j++){
				if(bit & (1<<s[i][j]-1)){
					check++;
				}
			}
			if(check%2 != p[i]){
				break;
			}
			if(i == m-1){
				sum++;
			}
		}
	}
	cout << sum;
}

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

typedef long long ll;
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define all(x) (x).begin(), (x).end()
#define en '\n'
#define FILL(x, v) memset(x, v, sizeof(x))
#define pb push_back
#define fast                     \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(NULL);
#define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...)       \
	F_ORC(__VA_ARGS__) \
	(__VA_ARGS__)

#define E_ACH2(x, a) for (auto &x : a)
#define E_ACH3(x, y, a) for (auto &[x, y] : a)
#define E_ACH4(x, y, z, a) for (auto &[x, y, z] : a)
#define E_ACHC(...) GET5(__VA_ARGS__, E_ACH4, E_ACH3, E_ACH2)
#define EACH(...)       \
	E_ACHC(__VA_ARGS__) \
	(__VA_ARGS__)

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

// const int mxN = 1e9 + 7;
const int M = 1e9 + 7;

ll pw(ll b, ll e)
{
	ll res = 1;
	while (e)
	{
		if (e % 2)
			res = (res * b) % M;
		b = (b * b) % M;
		e >>= 1; // e/=2;
	}
	return res;
}

// ll fact[mxN + 1], inv[mxN + 1];
// ll C(ll n, ll k)
// {
// 	return (((fact[n] * inv[k]) % M) * inv[n - k]) % M;
// }
// ll f1[M + 1], f2[M + 1];
// ll C(int n, int k)
// {
// 	return (((f1[n] * f2[k]) % M) * f2[n - k]) % M;
// }

int main()
{
	fast;
	int n, k;
	cin >> n >> k;
	if (n % k)
		cout << n / k + 1;
	else
		cout << n / k;
}

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  int ans = n;
  vector<int> white_sum(n+1, 0);
  vector<int> black_sum(n+1, 0);
  rep(i, n){
    if(s[i] == '#'){
      black_sum[i + 1] = black_sum[i] + 1;
    }else{
      black_sum[i + 1] = black_sum[i];
    }
  }
  for (int i = n - 1; i >= 0; i--){
    if(s[i] == '.'){
      white_sum[i] = white_sum[i + 1] + 1;
    }else {
      white_sum[i] = white_sum[i + 1];
    }
  }
  rep(i, n+1){
    ans = min(ans, white_sum[i] + black_sum[i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 2180
import sys

sys.setrecursionlimit(10**9)

n , m = map(int,input().split())

g = [[] for i in range(n)]

dp = [-1] *n
for _ in range(m):
  v1 , v2 = map(int,input().split())
  v1 -=1; v2 -=1
  g[v1].append(v2)
  
# finding longest path for vertice i
def dfs(i):
  if dp[i]!=-1:
    return dp[i]
  temp = 0
  for nv in g[i]:
    temp = max(temp, dfs(nv)+1)
  
  dp[i]=temp
  return temp
  
# finding overall longest path  
res = 0  
for i in range(n):
  res = max(res, dfs(i))
  
print(res)

Measured memory_bytes: 154060
#include<stdio.h>

int sum=0;
int amount=0;

int avrg(int am,int m){
  int ama=10*am;
  int a=ama/m+5;
  return a/10;
}

void sanda(n){
  int a,b;
  if(scanf("%d,%d",&a,&b)!=EOF){
    sum=sum+a*b;
    amount=amount+b;
    sanda(n+1);
  }
  else{
    printf("%d\n%d\n",sum,avrg(amount,n));
  }
}

int main(){
  sanda(0);
  return 0;
}

Measured memory_bytes: 592
class Edge():
    def __init__(self, to, cap, rev=None):
        self.to = to
        self.cap = cap
        self.rev = rev

from collections import deque

class Dinic():
    def __init__(self, n):
        self.n = n
        self.inf = 10**18
        self.graph = [[] for _ in range(self.n)]

    def add(self, fr, to, cap):
        edge = Edge(to, cap)
        rev = Edge(fr, 0)
        edge.rev, rev.rev = rev, edge
        self.graph[fr].append(edge)
        self.graph[to].append(rev)

    def max_flow(self, source, sink):
        flow = 0
        while True:
            queue = deque([source])
            level = [None for _ in range(self.n)]
            level[source] = 0
            while queue:
                node = queue.popleft()
                for edge in self.graph[node]:
                    to = edge.to
                    if edge.cap and level[to] is None:
                        level[to] = level[node] + 1
                        queue.append(to)
            if level[sink] is None: break
            stack = [source]
            par = [None for _ in range(self.n)]
            par[source] = source
            cap = [self.inf for _ in range(self.n)]
            while stack:
                node = stack.pop()
                if node == sink:
                    break
                for edge in self.graph[node]:
                    to = edge.to
                    if edge.cap and level[node] < level[to]:
                        par[to] = node
                        cap[to] = min(edge.cap, cap[node])
                        stack.append(to)
            node = sink
            prev = par[sink]
            delta = cap[sink]
            while node != source:
                for edge in self.graph[prev]:
                    if edge.to == node:
                        edge.cap -= delta
                        edge.rev.cap += delta
                node = prev
                prev = par[node]
            flow += delta
        return flow

import sys
input = sys.stdin.readline

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

d = Dinic(N)

for _ in range(M):
    u, v, c = map(int, input().split())
    d.add(u, v, c)

print(d.max_flow(0, N - 1))


Measured memory_bytes: 6332
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define INF 110000000000
#define MAX 100000
typedef long long ll;
typedef pair<ll,int> P;

int main(){
  ll A,B;
  cin>>A>>B;
  if(A>B){
    swap(A,B);
  }
  if((B-A)%2==1) cout<<"IMPOSSIBLE"<<endl;
  else cout<<(A+B)/2<<endl;
  
}


Measured memory_bytes: 256
n, k = map(int, input().split())

a = map(int, input().split())
f = map(int, input().split())

a = sorted(a)
f = sorted(f, reverse=True)

def judge(n):
    s = 0
    for x, y in zip(a, f):
        s += max(0, x - n // y)
    if s <= k:
        return True
    else:
        return False

low = 0
high = a[-1] * f[0]
while high - low > 0:
    mid = (high + low) // 2
    if judge(mid):
        high = mid
    else:
        low = mid + 1
print(high)

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

int main()
{
string s;
int i=0,j=0,k=0;
cin>>s;
for(;s[i]!='A';++i){}
for(j=s.length();s[j]!='Z';j--)
{

}
j++;
cout<<j-i<<"\n";
    return 0;
}


Measured memory_bytes: 640
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner input1 = new Scanner(System.in);
        String input2 = input1.nextLine();
        String[] fac = input2.split("\\s+");
        int a = Integer.parseInt(fac[0]);
        int b = Integer.parseInt(fac[1]);
        int ab = a * b;
        int syu = 2 * (a + b);
        System.out.println(ab+" "+syu);

        }
    }



Measured memory_bytes: 26172
#include <iostream>

using namespace std;

int main()
{
   int a ,b;
   a,b<13;
   cin>>a>>b;

   if(a>b&&b!=1)
    cout<<"Alice"<<endl;
    else if(b>a&&a!=1)
        cout<<"Bob"<<endl;
        else if(a==1&&b!=1)
            cout<<"Alice"<<endl;
        else if(b==1&&a!=1)
            cout<<"Bob"<<endl;
    else cout<<"Draw"<<endl;
       return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int[] A = new int[N];
        int[] B = new int[N];
        for(int i = 0; i < N; i++){
            A[i] = sc.nextInt();
            B[i] = A[i] - i - 1;
        }
        sc.close();
        Arrays.sort(B);
        int b;
        if(N%2 == 1){
            b = B[N/2];
        } else {
            b = (B[N/2] + B[N/2-1]) / 2;
        }
        long sum = 0;
        for(int i = 0; i < N; i++){
            sum += Math.abs(B[i] - b);
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 65004
<?php
$n=trim(fgets(STDIN));
$input=explode(' ',trim(fgets(STDIN)));
$inputInt = null;
foreach($input as $i) {
    $inputInt[] = intval($i);
}
$couter = 0;
// 条件1が全てtrueならすべての数値を割る
while(evencheck($inputInt)){
    $kari = [];
    foreach($inputInt as $item){
        $kari[] = $item / 2;
  }
    $inputInt = $kari;
    $couter++;
}
echo $couter;
function evencheck($checks) {
    $evenFlg = true;
    foreach($checks as $checkItem){
        intval($checkItem);
        if($checkItem % 2){
            $evenFlg = false;
        }
    }
    return $evenFlg;
}
?>





Measured memory_bytes: 3828
x, n = map(int, input().split())
p = list(map(int, input().split()))
ls1 = []
if x not in p:
    print(x)
else:
    for i in range(100):
        y = x - (i + 1)
        z = x + i + 1
        if y not in p:
            print(y)
            break
        if z not in p:
            print(z)
            break


Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
typedef vector<int> vi;
typedef long long lint;
typedef unsigned int uint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef unsigned long long ulint;
#define endl '\n'
#define fst first
#define sed second
#define pb push_back
#define mp make_pair
#define rint register int
#define SZ(x) (int((x).size()))
#define all(x) (x).begin(), (x).end()
#define reveal(x) cerr << #x << " = " << (x) << endl
#define rep(it, f, e) for (rint it = (f); it <= (e); ++it)
#define per(it, f, e) for (rint it = (f); it >= (e); --it)
#define repe(it, x) for (auto it = (x).begin(); it != (x).end(); ++it)
const lint INF = 4e18;
int A, B, C, D;
unordered_map<lint, lint> dp;
inline lint dfs(lint n) {
	if (n <= 1) return n * D;
	if (dp.count(n)) return dp[n];
	lint & dpv = dp[n]; dpv = INF;
	{
		int k = n % 2;
		if (k == 0) {
			dpv = min(dpv, dfs(n / 2) + A);
		} else {
			dpv = min(dpv, dfs(n / 2) + A + D);
			dpv = min(dpv, dfs(n / 2 + 1) + A + D);
		}
	}
	{
		int k = n % 3;
		if (k == 0) {
			dpv = min(dpv, dfs(n / 3) + B);
		} else {
			if (k == 1) {
				dpv = min(dpv, dfs(n / 3) + B + D);
			} else {
				dpv = min(dpv, dfs(n / 3 + 1) + B + D);
			}
		}
	}
	{
		int k = n % 5;
		if (k == 0) {
			dpv = min(dpv, dfs(n / 5) + C);
		} else {
			if (k <= 2) {
				dpv = min(dpv, dfs(n / 5) + C + D * k);
			} else {
				dpv = min(dpv, dfs(n / 5 + 1) + C + D * (5 - k));
			}
		}
	}
	if (n <= INF / D) {
		dpv = min(dpv, n * D);
	}
	return dpv;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	int T;
	cin >> T;
	while (T--) {
		dp.clear();
		lint N;
		cin >> N >> A >> B >> C >> D;
		cout << dfs(N) << endl;
	}
	return 0;
}

Measured memory_bytes: 4104
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <array>
#include <random>
#include <complex>
#include <regex>
#include <iomanip>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define fcout cout << fixed << setprecision(10)
#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define all(x) x.begin(), x.end()
#define F first
#define S second
const ll inf = 1e18;
const ll mod = 1e9 + 7;

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

// mod. m での a の逆元 a^(-1) を計算する。
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll modpow(ll a, ll n){
    ll res = 1;
    while(n>0){
        if(n&1){
            res = res * a % mod;
        }
        a = a * a % mod;
        n >>=1;
    }
    return res;
}



int main(){
    int x, n;
    cin >> x >> n;
    vint p(110, 1);
    rep(i,n){
        int tmp;
        cin >> tmp;
        p[tmp]= 0;
    }
    int ans = 110;
    for(int i=-2; i<110; i++){
        // cout << p[i] << " ";
        if( i < 0 ||  p[i] == 1){
            if(abs(x-i) < abs(x-ans)){
                ans = i;
            }
        }
    }
    cout << ans << endl;
}



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

Measured memory_bytes: 2580
#include<bits/stdc++.h>
using namespace std;
int gcd(int,int);
int main(){
  int x,y,ans;
  cin >> x >> y;
  ans = gcd(x,y);
  cout << ans << endl;
}

int gcd(int x,int y){
  if(y>x) swap(x,y);
  int tmp;
  while(1){
    tmp = x%y;
    if(tmp==0) return y;
    else{
      x = y;
      y = tmp;
    }
  }
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define all(x) x.begin(), x.end()

int main() {
  double n, ans = 0;
  cin >> n;
  vector<double> x(n), y(n);
  for (ll i = 0; i < n; i++) {
    cin >> x.at(i) >> y.at(i);
  }
  for (ll i = 0; i < n; i++) {
    for (ll j = 0; j < n; j++) {
      ans += sqrt(pow(x.at(i) - x.at(j), 2) + pow(y.at(i) - y.at(j), 2));
    }
  }
  printf("%.12f\n", ans / n);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int n,m,c;
  vector<int> b;
  vector<vector<int>> a;
  cin>>n>>m>>c;
  b.resize(m);
  for(auto& x:b){
    cin>>x;
  }
  a.resize(n);
  for(auto& x:a){
    x.resize(m);
    for(auto& y:x){
      cin>>y;
    }
  }
  int r=0;
  int sum=0;
  for(auto& x:a){
    for(int i=0;i<m;i++){
      sum+=x[i]*b[i];
    }
    sum+=c;
    if(sum>0)r++;
    sum=0;
  }
  cout<<r<<endl;
  return 0;
}

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

msum = 0
for i in range(N):
    if A[i] <= B[i]:
        msum += A[i]
        B[i] -= A[i]
        A[i] = 0
        if A[i+1] <= B[i]:
            msum += A[i+1]
            B[i] = A[i+1]
            A[i+1] = 0
        else:
            msum += B[i]
            A[i+1] -= B[i]
            B[i] = 0
    else:
        msum += B[i]
        A[i] -= B[i]
        B[i] = 0
print(msum)


Measured memory_bytes: 19004
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define PI 2 * acos(0.0)
#define MAX 1000000
#define INF 1000000 
#define M 1000000007
using namespace std;
int main(){
    FAST
    string s,t;
    cin>>s>>t;
    ll ans= 0;
    bool ok = true;
    for(ll i = 0;i<s.length();i++){
        for(ll j = i;j<s.length();j++){
            ll y = j-i+1;
            string g = s.substr(i,y);
            if(g.length() == t.length()){
                ll x = 0;
               for(ll k = 0;k<g.length();k++){
                   if(g[k] == t[k]){
                       x++;
                   }
               }
               ans = max(ans,x);
            }
        }
    }
    ll u = t.length() - ans;
    cout<<u<<endl;
}


Measured memory_bytes: 3676
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll K, X;

int main() {
  std::cin >> K >> X;

  repi( i, X-(K-1), X+K )
    std::cout << i << (i==X+K-1 ? '\n': ' ');

  return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=acos(-1);
const ll MOD=1e9+7;
const ll INF=(1LL<<60);

int n,m;
int c[17],x[20010];
int dp[20010][256];

int main() {
    while (1){
        cin>>n>>m;
        if (n==0 && m==0)return 0;
        memset(c,0,sizeof(c));
        memset(x,0,sizeof(x));
        rep(i,m)cin>>c[i];
        rep(i,n)cin>>x[i+1];
        vvi dp(n+1,vi(256,1e9*2));
        //cout<<dp[1][1]<<endl;
        dp[0][128]=0;
        for (int i=0;i<n;i++){
            for (int j=0;j<256;j++){
                if (dp[i][j]==1e12*2)continue;
                else {
                    rep(k,m){
                        int num=j+c[k];
                        if (num<0)num=0;
                        if (num>255)num=255;
                        int dx=num-x[i+1];
                        dp[i+1][num]=min(dp[i+1][num],dp[i][j]+dx*dx);
                    }
                }
            }
        }
        int ans=1e9*2;
        rep(i,256)ans=min(ans,dp[n][i]);
        cout<<ans<<endl;

    }
    

    return 0;
}


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

typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define ARR(array) for(int i=0;i<array.size();i++)
#define all(in) in.begin(),in.end()
#define ALL(in,K) (in),(in)+(K)

#define INF 1e18
#define MOD 1000000007
#define SIZE 10005
#define PI 	3.14159265358979323846

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a, b)*b; } //最小公倍数

ll input(){
  ll a;
  cin >> a;
  return a;
}

int main(){
    cout << lcm(input(),input()) << endl;
}


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

typedef pair<int, int> P;
#define INF (1LL<<60)
#define int long long
#define ll long long
#define mod 1000000007



signed main(){

	int n; cin>>n;
	string s;
	cin >> s;
	
	int diff=0, add=0;
	for(int i=0; i<n; i++){
		if(s[i]=='(') diff++;
		else diff--;
		if(diff<0){
			add++;
			diff++;
		}
	}
	s = string(add,'(')+s;
	if(diff>0)
		s = s + string(diff,')');
	cout << s << endl; 

	return 0;
}


Measured memory_bytes: 380
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int[] nk = Stream.of(sc.nextLine().split("\\s")).mapToInt(Integer::parseInt).toArray();
    int n = nk[0];
    int k = nk[1];
    int[] h = Stream.of(sc.nextLine().split("\\s")).mapToInt(Integer::parseInt).toArray();
    sc.close();
    int counter = 0;
    for (int hi: h) {
      if (hi >= k) {
        counter++;
      }
    }
    System.out.println(counter);
  }
}

Measured memory_bytes: 39168
n,m=map(int,input().split())
x = [0 for _ in range(m)]
for _ in range(n):
  t = input().split()
  k = t[0]
  a = list(map(int,t[1:]))
  for aa in a:
    aa -= 1
    x[aa] += 1
x = list(filter(lambda s: 1 if s == n else 0, x))
print(len(x))
  

Measured memory_bytes: 3060
from itertools import product
n,m,k = map(int,input().split())
l = list(list(map(int,input().split())) for i in range(n))

a = [0,1]
mi = 10**8
for i in product(a,repeat=n):
  money = 0
  tishiki = list(0 for i in range(m))
  for j in range(n):
    q = i[j]
    if q==1:
      money += l[j][0]
      for e in range(m):
        tishiki[e] += l[j][e+1]
  for v in tishiki:
    if v<k:
      break
  else:
    mi = min(mi,money)
if mi==10**8:
  print(-1)
else:
  print(mi)

Measured memory_bytes: 9228
#include<bits/stdc++.h>
#define int long long
#define ll long long
#define ld long double
#define mod ((ll)1e9+7)
#define maxx ((ll)1e6+5)
#define pb push_back
#define ins insert
#define usefile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
ll exp(ll x,ll y,ll p){ ll res=1; while(y) {if(y%2) res=(res*x%p)%p; x=(x*x)%p; y/=2; } return res;}
ll expo(ll x,ll y){ ll res=1; while(y) {if(y%2) res=(res*x%mod)%mod; x=(x*x)%mod; y/=2; } return res;}
/*int sv[1000000]={0};
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%mod;}
void sve() {sv[0]=1;sv[1]=1;for(int i=2;i*i<=maxx;i++){if(!sv[i]){for(int j=2*i;j<=maxx;j+=i)sv[j]=1;}}}//0 hai to prime
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(expo(fact[r],mod-2)))%mod; res=(res*(expo(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(expo(fact[n-r],mod-2)))%mod; return res;}*/
int d[1003][1003];
using namespace std;
signed main()
{
    string s,t;
    cin >> s >> t;
    int n = s.size();
    int m = t.size();
    int i,j,k;
    int d[n+1][m+1];
    for(i=0 ; i<=n ; i++)
    	for(j=0 ; j<=m ; j++)
    		d[i][j] = 0;
    for(i=1 ; i<=n ; i++)
    {
    	for(j=1 ; j<=m ; j++)
		{
			d[i][j] = max(d[i-1][j] , d[i][j-1]);
			if(s[i-1] == t[j-1])
				d[i][j] = max(d[i][j] , d[i-1][j-1]+1);
		}
    }
    int x=0,y=0,mm=0;
    string ans;
    for(i=1 ; i<=n ; i++)
    	for(j=1 ; j<=m ; j++)
    		if(d[i][j] > mm)
    		{
    			x = i;
    			y = j;
    			mm = d[i][j];
    		}
    while(1)//idk watmidoinmaybeitwlwrk
    {
    	if(x==0 || y==0) break;
    	while(d[x][y-1] == d[x][y] && y>0)
    		y = y-1;
    	while(d[x-1][y] == d[x][y] && x>0)
    		x = x-1;
    	if(x<=0 || y<=0) break;
    	if(d[x][y] == 0) break;
    	ans.pb(s[x-1]);
    	x = x-1;
    	y = y-1;
    	
    }
    reverse(ans.begin() , ans.end());
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 70656
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		// スペース区切りの整数の入力
		long b = 0;
		long c = 0;
		// 文字列の入力
		long[] d = new long[a];
		for(int i = 0; i < a; i++){
			d[i] = sc.nextInt();
			b += d[i];
			b = b % 1000000007;
          //System.out.println(b);
			c += d[i] * d[i];
			c = c % 1000000007;
          //System.out.println(c);
		}
      long e = (b * b - c) % 1000000007;
      //System.out.println(e);
		if(e % 2 == 0){
			System.out.println(e / 2);
		}else{
			System.out.println(( e + 1000000007) / 2);
		}
		
		
	}
}

Measured memory_bytes: 60888
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include <sstream>
#include<map>


using namespace std;

int main() {

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

	double kakuritu = 0;
	for (int i = 1; i <= a; i++)
	{
		double tmp = 1.0 / (double)a;
		int num = i;
		while (true)
		{
			if (num < b)
			{
				num *= 2.0f;
				tmp /= 2.0f;
			}
			else
			{
				break;
			}
		}

		kakuritu += tmp;
	}

	printf("%.12f", kakuritu);

	return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h> 
#define ll                 long long                            
#define ra                 return a;                                          
#define pb                 push_back                                                     
#define sti                stack<ll>
#define spi                stack<pair<ll,ll>>
#define S                  second
#define msi                map<string,ll >
#define msi                map<string,ll >
#define mii                map<ll ,ll >
#define dbg(x)             { cerr<<#x<<": "<<x<< endl; }
#define dbg2(x,y)          { cerr<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }
#define dbg3(x,y,z)        { cerr<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }
#define mis                map<ll , string>
#define rep(i,a,b)         for(ll  i=a;i<b;i++)
#define mpi                map<pair<ll ,ll >,ll >                                                
#define pii                pair<ll ,ll >
#define ppb                pop_back
#define F                  first 
#define vi                 vector<ll >
#define vii                vector<pair<ll , ll >>
#define si                 set <ll>
#define vs                 vector<string>
#define all(a)             (a).begin(),(a).end()
#define sz(x)              (ll )x.size()
#define hell               1000000007
#define bs                 binary_search
#define mp                 make_pair
#define qi                 queue<ll>
#define qs                 queue<string>
#define qpi                queue<pair<ll,ll>>
#define qps                queue<pair<ll,string>> 
#define endl               '\n' 
#define itr(a,it)          for(typeof(a.begin()) it=a.begin();it!=a.end();it++)// This will produce const_iterator for const object and normal iterator for non-const object
#define ss                 set<string>
using namespace std;
#define N  300005
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
//    cin>>t;
    while(t--)
{
	string s;
	cin>>s;
	ll n=sz(s),ans=0,j;
	ll cnt=0;
	rep(i,0,n-1)
	{
		if(s[i]=='A')cnt++;
		else if(s[i]=='B')
		{
			if(s[i+1]=='C')
			{
				ans+=cnt;
				i+=1;
			}
			else cnt=0;
		}
		else cnt=0;
//		dbg2(i,cnt);
	} 	
	cout<<ans;
}
    return 0;
}


Measured memory_bytes: 720
n, m = map(int,input().split())
hole = [int(input()) for _ in range(m)]
k = 0
a, b = 0, 0
x = (10 ** 9 + 7)
for i in range(n):
    if m >= 1:
        if i + 1 == hole[k]:
            a, b = 0, a
        else:
            if i == 0:
                a = 1
            elif i == 1:
                a, b = (a + 1) % x, a % x
            else:
                a, b = (a + b) % x, a % x
        if i + 1 >= hole[k] and k < m - 1:
            k += 1
    else:
        if i == 0:
                a = 1
        elif i == 1:
            a, b = (a + 1) % x, a % x
        else:
            a, b = (a + b) % x, a % x
    
print(a)


Measured memory_bytes: 7076
#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <utility>
#include <math.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define maxn 23
int a[maxn],b[maxn],c[maxn];
int main()
{

    int n;
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
        scanf("%d",&a[i]);
    for(int i=1; i<=n; i++)
        scanf("%d",&b[i]);
    for(int i=1; i<n; i++)
        scanf("%d",&c[i]);
    int sum=0;
    for(int i=1; i<=n; i++)
        sum+=b[i];
        for(int i=1; i<n; i++)
        {
            if(a[i]+1==a[i+1])
                sum+=c[a[i]];
        }
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 256
def is_palind(str)
  str == str.reverse
end

def is_strong_palind(str)
  n = str.length
  str2 = str[0...((n - 1) / 2)]
  str3 = str[((n + 3) / 2 - 1)...n]
  is_palind(str) && is_palind(str2) && is_palind(str3)
end

str = gets.chomp

if is_strong_palind(str)
  puts "Yes"
else
  puts "No"
end


Measured memory_bytes: 14360
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cstdlib>
#include <iomanip>
#define rep(i,x) for(ll i=0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 10010010010;
typedef pair<ll, ll> P;
using graph = vector<vector<ll>>;
const ll mod = 1000000007;
ll gcd(ll a, ll b) {//a>b
    if (a < b)swap(a, b);
    if (a % b == 0) return b;
    else return gcd(b, a % b);
}

ld dist(ll x1, ll y1, ll x2, ll y2) {
    ll X = x1 - x2;
    ll Y = y1 - y2;
    return pow(pow(X, 2) + pow(Y, 2), 0.5);
}
int main() {
    ll N;
    cin >> N;
    vector<ll> vec(N);
    vector<vector<ll>> num(N, vector<ll>(2));
    ll kazu = 1;
    rep(i, N) {
        cin >> num[i][0] >> num[i][1];
        vec[i] = i;
        kazu *= (i + 1);
    }
    ld ans = 0;
    do{
        ld cnt = 0;
        rep(i, N - 1) {
            cnt += dist(num[vec[i]][0], num[vec[i]][1], num[vec[i + 1]][0], num[vec[i + 1]][1]);
        }
        ans += cnt / kazu;
    } while (next_permutation(all(vec)));
    cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
const ll MOD = 1e9+7;
#define N 100010
ll powmod(ll a,ll b,ll mod){
    ll P=1;
    a=a%mod;
    while(b){
        if(b&1) P=(P*(a%mod))%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return P; 
}

namespace lucas {
    ll p = MOD;
    inline ll qpow(ll a,ll b){
    if(b==1) return a;
    ll t=qpow(a,b/2);
    t=t*t%p;
    if(b&1) t=t*a%p;
    return t;
}
inline ll C(ll n,ll m){
    if(n<m) return 0;
    if(m>n-m) m=n-m;
    ll a=1,b=1;
    for(int i=0;i<m;i++){
        a=(a*(n-i))%p;
        b=(b*(i+1))%p;
    }
    return a*qpow(b,p-2)%p;
}
inline ll Lucas(ll n,ll m){
    if(m==0) return 1;
    return Lucas(n/p,m/p)*C(n%p,m%p)%p;
}
}


int main() {
    ll n, a, b; scanf("%lld%lld%lld", &n, &a, &b);
    ll res = powmod(2, n, MOD);
    // printf("%lld\n", res);
    res -= 1; res = (res + MOD) % MOD;
    // lucas::p = MOD;
    res -= lucas::Lucas(n, a); res -= lucas::Lucas(n, b);
    // printf("%lld %lld\n", lucas::Lucas(n, a), lucas::Lucas(n, b));
    while(res < 0) res += MOD;
    printf("%lld\n", res);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <algorithm>
#include <cctype>
#include <iostream>
#include <string>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)

// vector<tuple<long,long>> items; // (value, weight)
// auto item = items[i];
// long v = get<0>(item);
// long w = get<1>(item);
// long v, w;
//   for( int i = 0; i < N; i++ ){
//     cin >> v >> w;
//     items.push_back( make_tuple(v, w) ); // item : (value, weight)
//   }

// 1 << 3 : int "3" change to bit "100"
// rep(pattern, 1 << N) if (pattern & (1 << x)) cnt++

const ll MOD = 1e9+7;

void comb(vector<vector<ll>> &v){
    for(int i = 0; i < v.size(); i++){
        v[i][0] = 1;
        v[i][i] = 1;
    }
    for(int k = 1; k < v.size(); k++){
        for(int j = 1; j < k; j++){
            v[k][j] = (v[k-1][j-1] + v[k-1][j]) % MOD;
        }
    }
}

int main(){
    ll N,K;
    cin >> N >> K;
    
    vector<vector<ll>> v(N+1, vector<ll>(N+1, 0));
    comb(v);

    ll blue_split_pattern = 0;
    ll red_insert_pattern = 0;
    for(int i=1; i<K+1; i++){
        blue_split_pattern = v[K-1][i-1];
        red_insert_pattern = v[N-K+1][i];
        // cout << blue_split_pattern << " * " << red_insert_pattern << endl;
        cout << (blue_split_pattern * red_insert_pattern) % MOD << endl;
    }

    return 0;
}


Measured memory_bytes: 31616
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
const int N=100000;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u];i;i=sq[i].nxt)
#define fir first
#define sec second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define maxd 998244353
#define eps 1e-8
int n,k,m;

int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

int main()
{
	n=read();m=read();
	n=max(n,m);
	k=read();
	cout << (k-1)/n+1;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define int long long
#define P pair<long,long>
#define all(a) a.begin(),a.end()
using namespace std;
signed main(){
    int n; cin>>n;
    int ans=0;
    while(n>0){
        ans+=n%10;
        n/=10;
    }
    cout<<(ans==1?10:ans)<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define bug1( x ) {cerr << (#x) <<"="<< x << endl;}
#define bug2( x , y ) {cerr << (#x) <<"="<< (x) << "    " << (#y) << "="<< (y) << endl;}
#define bug3( x , y , z ) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << endl;}
#define bug4( x , y , z , w) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << endl;}
#define bug5( x , y , z , w ,p) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << endl;}
#define bug6( x , y , z , w ,p , q) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << "    " << (#q) <<"="<< q << endl;}
#define bugn( x , n ) {cerr << (#x) <<":";for(int i=0;i<n;i++)cerr << x[i] <<"  "; cerr << endl;}
#define bugnm( x , n , m ) {cerr << (#x)<<endl;for(int i=0;i<n;i++){cerr << "Row #" << i<< ":";for(int j=0;j<m;j++)cerr << x[i][j] << "   ";cerr << endl;}}
typedef long long ll;
typedef long double ld;
using namespace std;


int32_t main(){
	IOS
	int n,m;cin>>n>>m;
	int d[10][10];
	for(int i=0;i<10;i++){
		for(int j=0;j<10;j++){
			cin>>d[i][j];
		}
	}
	for(int i=0;i<10;i++){
		for(int j=0;j<10;j++){
			for(int k=0;k<10;k++){
				d[j][k]=min(d[j][k],d[j][i]+d[i][k]);
			}
		}
	}
	int ans = 0;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			int x;cin>>x;
			if( x!= -1 ){
				ans += d[x][1];
			}
		}
	}
	cout << ans;
}
/*
 * long long or int?
 * index out of bound? 
 * Tested on own test case?corner?
 * Make more general solution.
 * Read Read Read Read ....
 */


Measured memory_bytes: 3656
using System;
using System.Collections.Generic;
using static System.Console;

class Program {
	static void Main() {
		var D = NextInt();
		var N = NextInt();

		if (N == 100) {
			N++;
		}
		WriteLine(N * Math.Pow(100, D));
	}

	static int NextInt() {
		return int.Parse(NextString());
	}

	static string NextString() {
		var result = new List<char>();
		while (true) {
			int next = Read();
			if (next < 0)
				break;
			var nextChar = (char)next;
			if (!char.IsWhiteSpace(nextChar))
				result.Add(nextChar);
			else if (nextChar != '\r')
				break;
		}
		return string.Join("", result);
	}
}

Measured memory_bytes: 11220
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	double n, k, ans = 0; cin >> n >> k;
	for (int h = 1; h <= n; h++) {
		double sum = 1 / n, b = h, c = 0;
		while (c == 0) {
			if (b < k) {
				b = b * 2;
				sum = sum / 2;
			}
			else {
				ans += sum; c++;
			}
		}
	}
	printf("%.10f\n", ans);
	cin >> n;
}

Measured memory_bytes: 256
#include <stdio.h>
int main (void){
    int max;
    int sum;
    scanf("%d %d",&max,&sum);
    //経験上、3値のうち、2値は同じだ
    //1値固定で2値を決定させるながれ
    int count=0;
    int loop1,loop2,loop3,temp;
    if(max*3==sum){//例外、これは1パターンのみ
        printf("1\n");
        return 0;
    }
    for(loop1=0;loop1<=max;loop1++){//x=loop1なら？
        for(loop2=0;loop2<=max;loop2++){
            if(sum-(loop1+loop2)<=max && sum-(loop1+loop2)>=0){
                count++;
                //printf("%d %d %d\n",loop1,loop2,(sum-(loop1+loop2)));
            }
        }
    }
    printf("%d\n",count);
    return 0;
    
}

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


int main() {
    int N,M,i,j;
    cin >> N >> M;

    vector<int> k(M);
    vector<vector<int>> s(M);
    vector<int> p(M);
    bool flag = true;
    for(i=0;i<M;i++){
        cin >> k.at(i);
        for(j=0;j<k.at(i);j++){
            int a;
            cin >> a;
            s.at(i).push_back(a);
        }
    }
    for(i=0;i<M;i++){
        cin >> p.at(i);
    }
    int bit,count=0,ans=0;
    for(bit=0;bit<(1<<N);bit++){
        flag = true;
        for(j=0;j<M;j++){
            count = 0;
            for(i=0;i<k.at(j);i++){
                if(bit & (1<<s.at(j).at(i)-1)){
                    count++;
                }
            }
            if(count % 2 != p.at(j)){
                flag = false;
                break;
            }
        }
        if(flag){
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3632
n = gets.chomp.to_i
h = Hash.new(0)
n.times do
    name = gets.chomp
    if name[0] == "M" || name[0] == "A" || \
        name[0] == "R" || name[0] == "C"|| \
        name[0] == "H" then
        h[name[0]] += 1
    end
end

ans = 0
ans += h["M"] * h["A"] * h["R"]
ans += h["M"] * h["A"] * h["C"]
ans += h["M"] * h["A"] * h["H"]
ans += h["M"] * h["R"] * h["C"]
ans += h["M"] * h["R"] * h["H"]
ans += h["M"] * h["C"] * h["H"]
ans += h["A"] * h["R"] * h["C"]
ans += h["A"] * h["R"] * h["H"]
ans += h["A"] * h["C"] * h["H"]
ans += h["R"] * h["C"] * h["H"]

puts ans


Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc1 = new Scanner(System.in);

		long a = sc1.nextLong();
		long b = sc1.nextLong();
		long c = sc1.nextLong();
		long k = sc1.nextLong();
		long ans = 0;

		if (k%2 ==0) {
			ans = a - b;
		}
		else
		{
			ans = b - a;
		}

		if(ans >= 1000000000000000000L | ans <= -1000000000000000000L) {
			System.out.println("Unfair");
		}
		else
		{
		System.out.println(ans);
		}

		sc1.close();

	}

}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 998244353LL
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 1000000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<i64, i64> pii;

#define maxn 300005

map<int,int> Map ;

int a[maxn] ;

int main()
{
    int n , k ;

    scanf("%d %d",&n,&k) ;

    for(int i=1 ; i<=n ; i++) scanf("%d",&a[i]) ;

    Map[0] = 1 ;

    i64 ans = 0 ;

    for( int i=1 ; i<=n ; i++)
    {
        if( i-k >= 0 )
        {
            int val = ( (a[i-k] - (i-k) )%k + k )%k ;
            Map[ val ] = Map[val] - 1 ;
        }
        a[i] = ( a[i-1] + a[i] )%k ;
        int val = ( (a[i] - i)%k + k )%k ;

        if( Map.find( val ) == Map.end() ) Map[val] = 0 ;
        ans += Map[val] ;
        Map[val] = Map[val] +  1 ;
   //     printf("-- %lld\n",ans) ;
    }

    printf("%lld\n",ans) ;

    return 0 ;
}


Measured memory_bytes: 10368
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int t = sc.nextInt();
		for(int i=0;i<t;i++) {
			if (i > 0) {
				System.out.println();
			}
			new Main().solve();
		}
	}

	int g;
	char[] con;
	ArrayList<Character>[] op;
	char[] s;
	int i;
	
	@SuppressWarnings("unchecked")
	void solve() {
		g = sc.nextInt();
		con = new char[g];
		op = new ArrayList[g];
		for(int i=0;i<g;i++) {
			op[i] = new ArrayList<Character>();
			con[i] = sc.next().charAt(0);
			int m = sc.nextInt();
			for(int j=0;j<m;j++) {
				op[i].add(sc.next().charAt(0));
			}
		}
		int n = sc.nextInt();
		for(int i=0;i<n;i++) {
			s = sc.next().toCharArray();
			this.i = 0;
			System.out.println(parse(0));
		}
	}
	
	String parse(int level) {
		if (level == g) {
			return parseAtom();
		}
		ArrayList<String> terms = new ArrayList<String>();
		ArrayList<Character> ops = new ArrayList<Character>();
		terms.add(parse(level+1));
		LOOP: while(i < s.length) {
			char c = s[i];
			for(char d:op[level]) {
				if (c == d) {
					i++;
					ops.add(c);
					terms.add(parse(level+1));
					continue LOOP;
				}
			}
			break;
		}
		if (con[level] == 'L') {
			String ret = terms.get(0);
			for(int i=1;i<terms.size();i++) {
				ret = "(" + ret + ops.get(i-1) + terms.get(i) + ")";
			}
			return ret;
		}else{
			int k = terms.size();
			String ret = terms.get(k-1);
			for(int i=k-2;i>=0;i--) {
				ret = "(" + terms.get(i) + ops.get(i) + ret + ")";
			}
			return ret;
		}
		
	}
	
	String parseAtom() {
		if (s[i] == '(') {
			i++;
			String s = parse(0);
			i++;
			return s;
		}else{
			String ss = String.valueOf(s[i]);
			i++;
			return ss;
		}
	}
}

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

using namespace std;

int main()
{
    int arr[3];
    cin>>arr[0]>>arr[1]>>arr[2];
    sort(arr, arr+3);
    if(arr[0]==5 && arr[1]==5 && arr[2]==7) cout<<"YES\n";
    else cout<<"NO\n";

    return 0;
}

Measured memory_bytes: 256
/*
17D8101031C 杉山　祥吾 ID:keisei334 java
*/

import java.util.Scanner;

class Main{
    public static void main(String[] av){
	Scanner sc=new Scanner(System.in);
	int q=sc.nextInt();
	int[] ans=new int[q];

	for(int p=0;p<q;p++){
	    String s1=sc.next();
	    String s2=sc.next();
	    int m=s1.length();
	    int n=s2.length();
	    int[][] len=new int[m+1][n+1];

	    for(int i=0;i<=m;i++) len[i][0]=0;
	    for(int j=0;j<=n;j++) len[0][j]=0;

	    for(int i=1;i<=m;i++){
		for(int j=1;j<=n;j++){
		    if(s1.charAt(i-1)==s2.charAt(j-1)){
			len[i][j]=len[i-1][j-1]+1;
		    }else{
			len[i][j]=Math.max(len[i][j-1],len[i-1][j]);
		    }
		}
	    }

	    ans[p]=len[m][n];
	}

	for(int p=0;p<q;p++){
	    System.out.println(ans[p]);
	}
    }
}

/*実行結果

*/



Measured memory_bytes: 64100