akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int n;
int a[1444][1444];
int p[1444][1444];
int l[1444],r[1444];
int main(){
	cin.tie(0);
	int n,m;cin>>n>>m;
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)cin>>a[i][j];
	for(int j=1;j<=m;j++){
		int k=0;
		for(int i=1;i<=n;i++){
			if(a[i][j]==0)k++;
			else k=0;
			p[i][j]=k;
		}
	}
	int res=0;
	for(int i=1;i<=n;i++){
		stack<pair<int,int> >s;// (h,jb)最小单增队列 
		s.push({-1,0});// 作为左最小界 
		int ll=0;
		for(int j=1;j<=m;j++){
			while(s.top().first>p[i][j]){// 不用判空，因为留着最小的呢不会空 
				int h=s.top().first;
				int jb=s.top().second;
				s.pop();
				r[jb]=j;
			}
			if(s.top().first<p[i][j])ll=s.top().second;
			l[j]=ll;
			s.push({p[i][j],j});
		}
		while(!s.empty()){
			int h=s.top().first;
			int jb=s.top().second;
			s.pop();
			r[jb]=m+1;
		}
		for(int j=1;j<=m;j++)
			res=max(res,(r[j]-l[j]-1)*p[i][j]);
	}
	cout<<res<<endl;
	return 0;
}



Measured memory_bytes: 18884
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'

int modify(int a){
  if (a % 10 == 0) return a;
  else return (a / 10 * 10 + 10);
}

int amari(int a){
  if (a % 10 == 0) return 0;
  else return (10 - a % 10);
}

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

  int a[5]; rep(i, 5) cin >> a[i];

  int b[5]; rep(i, 5) b[i] = modify(a[i]);
  int sum = accumulate(b, b + 5, int());
  print(min({sum - amari(a[0]), sum - amari(a[1]), sum - amari(a[2]), sum - amari(a[3]), sum - amari(a[4])}));

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N,M;
    int p[1000001];
    int accnt=0;
    int pncnt=0;
    int ac[100001]={0};
    int wa[100001]={0};
    string S[100001];
    cin >>N>>M;
    for(int i=0;i<M;i++){
        cin >>p[i]>>S[i];
        
    }
    for(int i=0;i<M;i++){
        
        if(S[i]=="WA"){
            wa[p[i]-1]++;
        }
        if(S[i]=="AC"&&ac[p[i]-1]==0){
            accnt++;
            ac[p[i]-1]=1;
            pncnt+=wa[p[i]-1];
            continue;
        }
    }
    cout <<accnt<<" "<<pncnt<<endl;
    return 0;
}

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

const int N=5005,inf=1e9;
int p[N],q[N],n,A,B,ans=1e9;
char s[N],t[N];

int solve(int k){
	int res=0;
	rep(i,1,k-1)
		res+=p[i];
	rep(i,1,B){
		if(k<=0)res+=q[i];
		else if(k<=A)res+=abs(p[k]-q[i]);
		else res+=n-q[i];
		k++;
	}
	if(k<=0)k=1;
	while(k<=A)res+=n-p[k++];
	return res;
}

int main(){
	scanf("%d",&n);
	scanf("%s",s+1);
	scanf("%s",t+1);
	rep(i,1,n-1)
		if(s[i]!=s[i+1])p[++A]=i;
	rep(i,1,n-1)
		if(t[i]!=t[i+1])q[++B]=i;
	if(!A&&!B&&s[1]!=t[1])return printf("%d",n),0;
	int o=(s[1]==t[1]?1:0);
	rep(i,-B-1,A+1)if(!((i+inf-o)&1))
		ans=min(ans,solve(i));
	cout<<ans<<endl;
	return 0;
}

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

int main() {
    int a,b;
    cin >> a >> b;
    if(a+b == 15) {
        cout << '+' << endl;
    }
    else if(a*b == 15) {
        cout << '*' << endl;
    }
    else {
        cout<< 'x' << endl;
    }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
	long long n, k;
	cin >> n >> k;
	vector<long long> a(n), f(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> f[i];
	}
	sort(a.begin(), a.end());sort(f.begin(), f.end());
	long long high = a[n-1]*f[n-1];
	long long low = -1;
	while (high - low > 1) {
		long long mid = (high + low)/2;
		long long kk = k;
		for (int i=0; i < n; i++) {
			// すごい食べ物はすごい人が食べる。
			long long o = n-1-i;
			long long g = mid / f[o]; // g以下の力
			if (g >= a[i]) {

			}
			else {
				kk -= a[i] - g;
			}
		}
		if (kk >= 0) {
			high = mid;
		}
		else {
			low = mid;
		}
	}
	cout << high << endl;
}

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

const int MOD=1e9+7;

long long dp[110][10]={};

int main(){
    int H,W,K; cin >> H >> W >> K;
    dp[0][0]=1;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            for(int mask=0;mask<(1<<(W-1));mask++){
                bool flag=true;
                for(int k=0;k<W-2;k++){
                    if((mask&(1<<k))&&(mask&(1<<(k+1)))){
                        flag=false;
                    }
                }
                if(!flag) continue;
                if(mask&(1<<j)){
                    dp[i+1][j+1]+=dp[i][j]%MOD;
                    dp[i+1][j+1]%=MOD;
                }else if(j>0&&(mask&(1<<(j-1)))){
                    dp[i+1][j-1]+=dp[i][j]%MOD;
                    dp[i+1][j-1]%=MOD;
                }else{
                    dp[i+1][j]+=dp[i][j]%MOD;
                    dp[i+1][j]%=MOD;
                }
            }
        }
    }
    /*
    for(int i=0;i<=H;i++){
        for(int j=0;j<=W;j++){
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
    */
    cout << dp[H][K-1] << endl;
}

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

#define ll long long
#define ld long double

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rrep(i, a, b) for(ll i = a; i >= b; --i)

#define pii pair<int, int>
#define pll pair<ll, ll>

#define fi first
#define se second

#define pb push_back
#define eb emplace_back

#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>

#define all(a) a.begin(), a.end()

#define endl '\n'
using namespace std;
using namespace atcoder;

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

const ll MOD=10000007;//998244353
const ll INF=1e18;
const int inf=1e9;
const double PI=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
 
const int MAX=3e5+10;

//mapping (f,x)=f(x);
//composition 関数合成
//id 恒等写像（単位元）
using mint = modint998244353;
const mint inv9= mint(1)/9;
struct S{
  mint x, w;
  S(mint x=0, mint w=1):x(x),w(w) {}//単位元的なのを事前に入れるやつ
};
S op(S a, S b){
  return S(a.x*b.w+b.x, a.w*b.w);
}
S e(){ return S();}
S mapping(int f,S a){
  if(f == 0) return a;
  return S((a.w-1)*inv9*f,a.w);
}
int composition(int f,int g){
  if(f == 0) return g;
  return f;
}
int id(){ return 0;}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n,q;
  cin >> n >> q;
  
  lazy_segtree<S,op,e,int,mapping,composition,id> tree(n);
  rep(i,n) tree.set(i,S(1,10));
  
  while(q--){
    int l,r,d;
    cin >> l >> r >> d;
    l--;
    tree.apply(l,r,d);
    S ans = tree.all_prod();
    cout << ans.x.val() << endl;
  }
                       
  return 0;
}


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

typedef long long ll;
const int N = 301, mod = 1000000007;
int n, k, ans = 0;
char s[N];
int fac[N], inv[N];

int f[N], m = 0, r[N], b[N], visit[N];
inline void solve() {
  for (int i = 1; i <= k; i++) visit[i] = 0;
  for (int i = 1, j = 1; i <= m; i++, j++) {
    while (j <= k && s[j] != 'r') j++;
    if (j > k) return;
    r[i] = j;
    visit[j] = 1;
  }
  for (int i = 1, j = 1; i <= m; i++, j++) if (f[i] >= 2) {
    j = max(j, r[i]);
    while (j <= k && s[j] != 'b') j++;
    if (j > k) return;
    b[i] = j;
    visit[j] = 1;
  }
  for (int i = 1, j = 1; i <= m; i++) if (f[i] >= 3) {
    int x = f[i] - 2;
    j = max(j, b[i]);
    while (x--) {
      while (j <= k && visit[j]) j++;
      if (j > k) return;
      visit[j] = 1;
      j++;
    }
  }
  int coef = fac[m];
  for (int i = 1, j = 0; i <= m; i++) {
    j = f[i] != f[i - 1] ? 1 : j + 1;
    coef = (ll) coef * fac[j - 1] % mod * inv[j] % mod;
  }
  int upper = n + 1, lower = 0;
  for (int i = 1; i <= m; i++) {
    if (f[i] >= 2) upper += 2;
    lower += f[i] * 2;
  }
  if (upper < lower) return;
  coef = (ll) coef * fac[upper] % mod * inv[lower] % mod * inv[upper - lower] % mod;
  ans = (ans + coef) % mod;
}
void dfs(int x, int last) {
  solve();
  for (int i = last; i; i--) {
    int y = (i == 1 ? 1 : 2 * i - 3) + 1;
    if (x >= y) {
      f[++m] = i;
      dfs(x - y, i);
      --m;
    }
  }
}

int main() {
  scanf("%d%d%s", &n, &k, s + 1);
  fac[0] = fac[1] = 1;
  inv[0] = inv[1] = 1;
  for (int i = 2; i < N; i++) {
    fac[i] = (ll) fac[i - 1] * i % mod;
    inv[i] = mod - (ll) mod / i * inv[mod % i] % mod;
  }
  for (int i = 2; i < N; i++) {
    inv[i] = (ll) inv[i] * inv[i - 1] % mod;
  }
  dfs(n + 1, n + 1);
  printf("%d\n", ans);
}


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

int main(void){
    int n, tmp;
    vector<int> s;
    cin >> n;
    for (int i=0; i<n; i++){
        cin >> tmp;
        s.emplace_back(tmp);
    }
    int sum = accumulate(s.begin(), s.end(), 0);
    if (sum % 10 != 0){
        cout << sum << endl;
    } else{
        sort(s.begin(), s.end());
        bool flag = true;
        for (int i=0; i<s.size(); i++){
            if ((sum - s[i]) % 10 != 0){
                sum -= s[i];
                flag = false;
                break;
            }
        }
        if (flag){
            cout << 0 << endl;
        } else{
            cout << sum << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#pragma GCC optimize ("O3,unroll-loops")
#define f first
#define s second
#define ri register int
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;
#define MAXN 100000
int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int n, k, h[MAXN], dp[MAXN];
	cin >> n >> k;
	for(ri k = 0; k < n; ++k) 
		cin >> h[k];
	dp[0] = 0;
	for(ri i = 1; i < n; ++i) {
		int minV = INT_MAX;
		for(ri j = max(0, i - k); j < i; ++j)
			minV = min(minV, abs(h[i] - h[j]) + dp[j]);
		dp[i] = minV;
	}
	cout << dp[n - 1] << '\n';
    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL) x = x->left;
  return x;
}

Node treeMaximum(Node x){
  while(x->right != NIL) x = x->right;
  return x;
}

Node treeSearch(Node u, int k){
  while(u != NIL && k != u->key){
    if(k < u->key) u = u->left;
    else u = u->right;
  }
  return u;
}

Node treeSuccessor(Node x){
  if(x->right != NIL) return treeMinimum(x->right);
  Node y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left == NIL || z->right == NIL) y= z;
  else y = treeSuccessor(z);

  if(y->left != NIL) x = y->left;
  else x = y->right;

  if(x != NIL) x->parent = y->parent;

  if(y->parent == NIL) root = x;
  else{
    if(y == y->parent->left) y->parent->left = x;
    else y->parent->right = x;
  }

  if(y != z) z->key = y->key;

  free(y);
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }

  z->parent = y;
  if(y == NIL) root = z;
  else{
    if(z->key < y->key) y->left = z;
    else y->right = z;
  }
}

void inorder(Node u){
  if(u == NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(Node u){
  if(u == NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



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

int N,K;

bool check(int x,vector<int> d){
  int tmp;
  while (x > 0) {
    tmp = x % 10;
    for (int i = 0; i < K; i++) {
      if (tmp == d.at(i)) return false;
    }
    x /= 10;
  }
  return true;
}

int main() {

  cin >> N >> K;
  std::vector<int> d(K);//キライな数字

  for (int i = 0; i < K; i++) {
    cin >> d.at(i);
  }

  int i = N;
  while (1) {
    if (check(i,d)) {
      cout << i << endl;
      return 0;
    }
    i++;
  }

}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
from math import floor, sqrt, factorial, hypot, log  # log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter, defaultdict, deque
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
import difflib


def ceil(a, b): return (a + b - 1) // b


inf = float('inf')
mod = 10 ** 9 + 7


def pprint(*A):
    for a in A:     print(*a, sep='\n')


def INT_(n): return int(n) - 1


def MI(): return map(int, input().split())


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [I() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')


def main():
    S = ST()
    T = ST()
    m = 0
    for i in range(len(S)-len(T)+1):
        mn = 0
        for j in range(len(T)):
            if S[i+j] == T[j]:
                mn += 1
        m = max(m, mn)
    print(len(T) - m)


if __name__ == '__main__':
    main()

Measured memory_bytes: 78048
K, A, B = map(int, input().split())
st = 1
hit = 0
if K <= A - 1:
  print(K + 1)
else:
  if B - A <= 1:
    print(K + 1)
  else:
    K -= A - 1
    print(A + (K // 2) * (B - A) + K % 2)

Measured memory_bytes: 3060
/*
    https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/1/ALDS1_1_B
*/
#include <bits/stdc++.h>
using namespace std;

long gcd(long x, long y) {
    if (y == 0)
        return x;
    return gcd(y, x % y);
}

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

    long x, y;
    cin >> x >> y;
    cout << gcd(x, y) << endl;
}


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

int main() {
  int k;
  string s;
  cin>>k>>s;
  if(s.size()<=k)
    cout<<s<<endl;
  else{
    for(int i=0;i<k;i++){
      cout << s.at(i);
    }
    cout<<"..."<<endl;
  }
}

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

using namespace std;

#define LL long long
#define reg register
#define debug(x) cerr<<#x<<" = "<<x<<endl;
#define rep(a,b,c) for(reg int a=(b),a##_end_=(c); a<=a##_end_; ++a)
#define ret(a,b,c) for(reg int a=(b),a##_end_=(c); a<a##_end_; ++a)
#define drep(a,b,c) for(reg int a=(b),a##_end_=(c); a>=a##_end_; --a)

inline int Read() {
	int res=0,f=1;
	char c;
	while(c=getchar(),c<48||c>57)if(c=='-')f=0;
	do res=(res<<3)+(res<<1)+(c^48);
	while(c=getchar(),c>=48&&c<=57);
	return f?res:-res;
}

template<class T>inline bool Min(T &a,T const&b) {
	return a>b?a=b,1:0;
}
template<class T>inline bool Max(T &a,T const&b) {
	return a<b?a=b,1:0;
}

const int N=1e5+5;

int n,flag=1,t,A[N];

int main() {
	n=Read();
	rep(i,1,n)A[i]=Read();
	sort(A+1,A+n+1);
	printf("%d",A[(n/2)+1]-A[n/2]);
}

Measured memory_bytes: 640
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

H, W = lr()
S = [list(sr()) for _ in range(H)]
S = np.array([[1 if x == '.' else 0 for x in row] for row in S], np.bool)
up = np.zeros((H, W), np.int32)
down = np.zeros((H, W), np.int32)
right = np.zeros((H, W), np.int32)
left = np.zeros((H, W), np.int32)
for i in range(H-1):
    up[i+1] = (1+up[i]) * S[i]
for i in range(H-1, 0, -1):
    down[i-1] = (1+down[i]) * S[i]
for i in range(W-1):
    left[:, i+1] = (1+left[:, i]) * S[:, i]
    #行列の列を取り出す時の記法
for i in range(W-1, 0, -1):
    right[:, i-1] = (1+right[:, i]) * S[:, i]


answer = ((up + down + left + right) * S).max() + 1
#自身を数えないことで特殊な場合をなくしている
print(answer)


Measured memory_bytes: 116348
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>

#define int long long
#define REP(i,l,r) REPEAT(i,l,r,true) //[l, r)
#define rep(i,n) REP(i,0,n)           //[0, n)
#define REPEAT(i,l,r,condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl
#define showslr(n,l,r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i];}cerr<<endl //[l, r))

#define yes puts("Yes")
#define no puts("No")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

inline void io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}

void _DEBUG(){cerr<<endl;}
template<typename H,typename... T> void _DEBUG(H a,T...b){cerr<<a<<",";_DEBUG(b...);}

template<typename T> inline void in(T &e){cin>>e;}
template<typename H,typename... T>void in(H &a, T&... b){in(a);in(b...);}
template<typename T> inline void out(T e){cout<<e<<endl;}
template<typename H,typename... T> void out(H a, T... b){out(a);out(b...);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;

int n,k;

vi vec;
int ans=INF;

signed main(){
    io();
    in(n,k);
    vec.resize(n);
    rep(i,n) in(vec[i]);

    rep(i,n-k+1){
        //show(vec[i],vec[i+k-1]);
        if((vec[i] xor vec[i+k-1])<0){ //異符号
            ans=min({ans,abs(vec[i+k-1]*2+abs(vec[i])),abs(vec[i+k-1])+abs(vec[i])*2});
        }else{
            ans=min(ans,max(abs(vec[i]),abs(vec[i+k-1])));
        }
    }

    out(ans);

    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(){
    int n,m,i;
    int task=0;
    scanf("%d%d",&n,&m);
    int a[m];
    for (i = 0; i <m ; ++i) {
        scanf("%d",&a[i]);
    }
    for (i = 0; i <m ; ++i) {
        task+=a[i];
    }
    if(n<task)
        printf("-1");
    else
        printf("%d",n-task);
}

Measured memory_bytes: 1728
#include<stdio.h>
#include<stdlib.h>

int main(){
	int N, A, B;
	int t[1000];
	int loop;
	int ans = 0;

	scanf("%d %d %d", &N, &A, &B);
	for (loop = 0; loop < N; loop++)scanf("%d", &t[loop]);

	for (loop = 0; loop < N; loop++){
		if (t[loop] < A || t[loop] >= B)ans++;
	}

	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>

int cmpnum(const void * n1, const void * n2)
{
	if (*(long *)n1 > *(long *)n2)
	{
		return 1;
	}
	else if (*(long *)n1 < *(long *)n2)
	{
		return -1;
	}
	else
	{
		return 0;
	}
}

int main(void){

  long n,k;
  scanf("%ld %ld", &n, &k);
  long h[n];
  for (long i = 0; i < n; i++) {
    scanf("%ld", &h[i]);
  }
  qsort(h, n, sizeof(long), cmpnum);
  long min = h[n-1]-h[0];
  for (long i = k-1; i < n; i++) {
    if (h[i]-h[i-k+1] < min) {
      min = h[i]-h[i-k+1];
    }
  }
  printf("%ld\n", min);

  return 0;
}

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
string s;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin>>s;
    ll sum=0;
    ll now;
    for(int bit=0;bit<(1<<s.size()-1);++bit){
        now=0;
        rep(i,s.size()){
            now=now*10+s[i]-'0';
            if(bit&(1<<i)){
                sum+=now;
                now=0;
            }
        }
        sum+=now;
    }
    cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 3520
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<iomanip>
#include<stack>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define sz(a) (int)a.size()
using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	cout << a * b << endl;
}

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

using namespace std;
const int N = 1e3 + 3;
char s[N];
int main() {
#ifndef ONLINE_JUDGE
//	freopen("input.in", "r", stdin);
//	freopen("output.out", "w", stdout);
#endif
	priority_queue<long double, vector<long double>, greater<long double>> q;
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		int a;
		scanf("%d", &a);
		q.push(a);
	}
	for (int i = 1; i < n; ++i) {
		auto a = q.top();
		q.pop();
		auto b = q.top();
		q.pop();
		q.push((a + b) / 2);
	}
	printf("%.9Lf\n", q.top());
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fr(i,j,n)   for(int i=j;i<(n);++i)
#define bk(i,j,n)   for(int i=j;i>n;--i)
#define mset(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define pop pop_back
#define mod 1000000007
#define all(x) x.begin(),x.end()
#define inf 1e18
#define iosbase ios_base::sync_with_stdio(false); cin.tie(NULL);
#define F first
#define S second
#define bye return

int main()
{
    ll K,N,i,a1,ans=0,a;
    cin>>K>>N;
    ll A[N];
    vector<ll>V;
    fr(i,0,N)
    {
        cin>>A[i];
    }
    a=A[0];
    for(i=1;i<N;i++)
    {
        a1=A[i]-a;
        a=A[i];
        V.pb(a1);
    }
    V.pb(K-A[N-1]+A[0]);
    sort(V.begin(),V.end());
    
   /* for(i=0;i<V.size();i++)
    {
        cout<<V[i]<<" ";
    }
    cout<<endl;*/
    for(i=0;i<V.size()-1;i++)
    {
        ans+=V[i];
    }

    cout<<ans<<endl;
    bye 0;
}


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

int H, W;
char dp[105][105];
int ddp[105][105];

int c = 0;
int main() {
  cin >> H >> W;
  for (int i = 0; i < 105; i++) {
    for (int j = 0; j < 105; j++) {
      ddp[i][j] = 0;
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> dp[i][j];
    }
  }

  for (int i = 0; i < W - 1; i++) {
    if (dp[0][i + 1] != dp[0][i] && dp[0][i + 1] == '#') {
      ddp[0][i + 1] += ddp[0][i] + 1;
    } else {
      ddp[0][i + 1] += ddp[0][i];
    }
  }
  for (int i = 0; i < H - 1; i++) {
    if (dp[i + 1][0] != dp[i][0] && dp[i + 1][0] == '#') {
      ddp[i + 1][0] += ddp[i][0] + 1;
    } else {
      ddp[i + 1][0] += ddp[i][0];
    }
  }

  for (int i = 1; i < H; i++) {
    for (int j = 1; j < W; j++) {
      if (dp[i][j] == '#') {
        ddp[i][j] += min(ddp[i - 1][j] + (dp[i - 1][j] != dp[i][j]),
                         ddp[i][j - 1] + (dp[i][j - 1] != dp[i][j]));
      } else {
        ddp[i][j] += min(ddp[i - 1][j], ddp[i][j - 1]);
      }
    }
  }

  if (dp[0][0] == dp[H - 1][W - 1]) {
    if (dp[0][0] == '#') {
      c++;
    }
  } else if (dp[0][0] != dp[H - 1][W - 1]) {
    if (dp[0][0] == '#') {
      c++;
    }
  }
  /*for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cout << ddp[i][j] << "  ";
    }
    cout << endl;
  }*/
  cout << ddp[H - 1][W - 1] + c << endl;
}

Measured memory_bytes: 256
N, A, B = gets.split.map( &:to_i )
V = gets.split.map( &:to_i ).sort.reverse

binom = Array.new( 64 ) do ||
	Array.new( 64, 0 )
end
binom[0][0] = 1
51.times do |i|
	51.times do |j|
		binom[ i + 1 ][j] += binom[i][j]
		binom[ i + 1 ][ j + 1 ] += binom[i][j]
	end
end

S = V[ 0 ... A ]
printf( "%.10f\n", S.inject( :+ ).to_f / A )

K = V.count( V[ A - 1 ] )
k = S.count( V[ A - 1 ] )
res = 0
if V[0] != V[ A - 1 ] then
	res = binom[K][k]
else
	( A .. [ B, K ].min ).each do |i|
		res += binom[K][i]
	end
end
puts res


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vi  = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(int i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
const ll INF = 1000000000000000;
const ll MOD = 1000000007;
const double PI = acos(-1);
//||
#define DBG(a,b,c,d) //cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl
//DBG("","","","");

signed main(){
	IO_STREAM;
	string S;	cin>>S;
	string T;	cin>>T;
	ll ans=0;
	rep(i,0,S.size()){
		if(S[i]!=T[i]){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3776
#include <bits/stdc++.h>
//#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod_) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod_;
		}
		x = x * x % mod_;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}
/*--------Library Zone!--------*/

int n, a[114], ans;
signed main() {
	cin >> n;
	rep(i, n)cin >> a[i];
	int cnt = 1;
	rep(i, n) {
		if (a[i] == a[i + 1])cnt++;
		else {
			ans += cnt / 2;
			cnt = 1;
		}
	}
	ans += cnt / 2;
	cout << ans << endl;
}


Measured memory_bytes: 256
"""
the condition is straightforward.
each element of A and B must multiply to the same value.
to minimise the total of B, simply make that value as small
as possible (since A is fixed).

lcm(2, 3, 4) = 12
therefore B is
12/2, 12/3, 12/4
and the sum of B is
12/2 + 12/3 + 12/4

lcd of a list is loop: lcd(partial, new_value)
lcd(a, b) = ab / gcd(a, b)
"""

from fractions import gcd


def lcm(list_ints):
    lcm_ongoing = 1
    for val in list_ints:
        lcm_ongoing = val*lcm_ongoing//gcd(val, lcm_ongoing)
    return lcm_ongoing


def flatten(N, A):
    # get lcm
    lcm_of_A = lcm(A)
    # get sum of lcm/values
    ans = sum(lcm_of_A//value for value in A)
    modulo_value = int(int(1e9)+7)
    return ans % modulo_value


if __name__ == "__main__":
    test1 = \
"""3
2 3 4"""
    test2 = \
"""5
12 12 12 12 12"""
    test3 = \
"""3
1000000 999999 999998"""
    test = test3
    # N = int(test.split("\n")[0])
    # A = list(map(int, test.split("\n")[1].split()))
    N = int(input())
    A = list(map(int, input().split()))
    print(flatten(N, A))

Measured memory_bytes: 6148
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N =2e5+10 , M = 5e5+10, OO = 0x3f3f3f3f ,  MOD = 1e9+7;
const double EPS = 1e-3;
#define M_PI 3.14159265358979323846
#define clr(arr,val) memset(arr , val , sizeof (arr))
#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n)-1;i >= 0;i--)
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define pb push_back
#define F first
#define S second
#define all(v) ((v).begin()) , ((v).end())
#define sz(v)  ((int)((v).size()))
typedef pair <int,int> pii ;
typedef vector < pii > vii ;
int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
 
 
ll a, b , k;

 
 
int main(){
 
 
    //ios_base::sync_with_stdio(0);
    //cin.tie(0);cout.tie(0);
    
    scanf("%lld %lld %lld",&a,&b,&k);
    
    if(k <= a)
        printf("%lld %lld\n", a-k , b);
    else if(k <= a+b)
        printf("%lld %lld\n",0 , b-(k-a));
    else 
        printf("%lld %lld\n",0 , 0);
    



 
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
using namespace std;
int n;
long long t;
long long a[100005];
long long b[100005];
int main(){
	cin>>n;
	for (int i=1;i<=n;i++){
		cin>>a[i]>>b[i];
	}
	for (int i=n;i>=1;i--){
		if (a[i]==0){
			continue;
		}
		if (a[i]<=b[i]){
			if (t<=b[i]-a[i]){
				t=b[i]-a[i];
			}
			else{
				long long T=t+a[i];
				if (T%b[i]!=0){
					T=(T/b[i]+1)*b[i]-a[i];
				}
				else{
					T=t;
				}
				t=T;
			}
		}
		else{
			long long T=t+a[i];
			if (T%b[i]!=0){
				T=(T/b[i]+1)*b[i]-a[i];
			}
			else{
				T=t;
			}
			t=T;
		}
	}
	cout<<t;
	return 0;
}


Measured memory_bytes: 1792
import numpy as np
a = np.array([input().split() for _ in range(3)])
n = int(input())
b = [int(input()) for _ in range(n)]

def bingo(sheet, called):
    sheet = np.where(sheet == called, 0, sheet)
    return sheet

for i in range(n):
    a = bingo(a, str(b[i]))

#print(a)
check = 0
for j in range(3):
    if a[j][0] == a[j][1] and a[j][2] == a[j][0] == '0':
        check += 1
    if a[0][j] == a[1][j] and a[2][j] == a[0][j] == '0':
        check += 1
if a[0][0] == a[1][1] and a[2][2] == a[0][0] == '0':
    check += 1
if a[0][2] == a[1][1] and a[2][0] == a[0][2] == '0':
    check += 1

print('No' if check == 0 else 'Yes')    

Measured memory_bytes: 12256
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define loop3(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)
#define loop4(i,j,k,l,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)for(int l=0; l<a; l++)if(i!=l&&j!=l&&k!=l)
#define rep1(i,a) for(int i=1; i<=a; i++)

#define scnd1(a) scanf("%d", &a)
#define scnd2(a,b) scanf("%d%d", &a,&b)
#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)

#define cin1(a) cin >> a;
#define cin2(a,b) cin >> a >> b;
#define cin3(a,b,c) cin >> a >> b >> c;
#define cin4(a,b,c,d) cin >> a >> b >> c >> d;
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define prtd1(a) printf("%d\n", a)
#define prtd2(a,b) printf("%d %d\n", a,b)
#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)
#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)

#define mem(a,n) memset( a, n, sizeof(a))
#define INF 1000000000
typedef long long ll;

int main() {
    ll N;
    cin>>N;
    int cnt=0;
    for(ll i=sqrt(N); i>=0; i--){
        if(N%i==0){
            ll x=max(i,N/i);
            while(x>0){
                x/=10;
                cnt++;
            }
            break;
        }
    }
    cout1(cnt);
}

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

using namespace std;

struct dice{
	int q1,q2,q3,q4,q5,q6;
};

void mN(dice &d){
	int tmp=d.q1;
	d.q1=d.q2;
	d.q2=d.q6;
	d.q6=d.q5;
	d.q5=tmp;
}

void mE(dice &d){
	int tmp=d.q1;
	d.q1=d.q4;
	d.q4=d.q6;
	d.q6=d.q3;
	d.q3=tmp;
}
void mW(dice &d){
	int tmp=d.q1;
	d.q1=d.q3;
	d.q3=d.q6;
	d.q6=d.q4;
	d.q4=tmp;
}
void mS(dice &d){
	int tmp=d.q1;
	d.q1=d.q5;
	d.q5=d.q6;
	d.q6=d.q2;
	d.q2=tmp;
}

void spin(dice &d){
	int tmp=d.q2;
	d.q2=d.q3;
	d.q3=d.q5;
	d.q5=d.q4;
	d.q4=tmp;
}

int main(){
	dice y, z;
	bool flag = false;
	
	scanf(" %d %d %d %d %d %d", &y.q1, &y.q2, &y.q3, &y.q4, &y.q5, &y.q6);
	scanf(" %d %d %d %d %d %d", &z.q1, &z.q2, &z.q3, &z.q4, &z.q5, &z.q6);
	
	for(int i=0; i<4; ++i){
		for(int j=0; j<4; ++j){
			//printf("now: %d %d %d %d %d %d\n", y.q1, y.q2, y.q3, y.q4, y.q5, y.q6);
		
			if(y.q1==z.q1 && y.q2==z.q2 && y.q3==z.q3 && y.q4==z.q4 && y.q5==z.q5 && y.q6==z.q6) {
				flag = true;
				break;
			}
			spin(y);	
		}
		if(flag) break;
		mN(y);
	}
	
	mE(y);
	
	//printf("now: %d %d %d %d %d %d\n", y.q1, y.q2, y.q3, y.q4, y.q5, y.q6);
	
	for(int i=0; i<4; ++i){
		for(int j=0; j<4; ++j){
			//printf("now: %d %d %d %d %d %d\n", y.q1, y.q2, y.q3, y.q4, y.q5, y.q6);
		
			if(y.q1==z.q1 && y.q2==z.q2 && y.q3==z.q3 && y.q4==z.q4 && y.q5==z.q5 && y.q6==z.q6) {
				flag = true;
				break;
			}
			spin(y);	
		}
		if(flag) break;
		mN(y);
	}	
			
	if(flag)printf("Yes\n");
	else printf("No\n");
		
	return 0;
}


Measured memory_bytes: 3168
S = input()
S = list(map(int, list(S)))
t1 = [x % 2 for x in range(len(S))]
t2 = [abs(x % 2 - 1) for x in range(len(S))]

t1c = sum([abs(S[i] - t1[i]) for i in range(len(S))])
t2c = sum([abs(S[i] - t2[i]) for i in range(len(S))])

print(min(t1c, t2c))

Measured memory_bytes: 7652
import sys

[N, M] = [int(i) for i in input().split()]

steps = [0, 1, 2]
for i in range(3, N+1):
    steps.append(steps[i-1] + steps[i-2])
  
if M == 0:
    print(steps[N] % 1000000007)
    sys.exit()
    
As = []
for i in range(M):
    As.append(int(input()))
    
deffs = []

if As[0] != 1:
    deffs.append(As[0] - 1)
else:
    deffs.append(1)

for i in range(1, M):
    d = As[i] - As[i-1] -2
    if d == 0:
        deffs.append(1)
    elif d == -1:
        deffs.append(0)
    else:
        deffs.append(d)

if N - As[M-1] - 1 != 0:
    deffs.append(N - As[M-1] - 1)
else:
    deffs.append(1)

ans = 1

for i in range(len(deffs)):
    ans *= steps[deffs[i]]
    
print(ans % 1000000007)


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

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    int neg_cnt = 0;
    ll min_abs = 1e10;
    ll sum = 0;
    rep(i, n) {
        if (a[i] < 0) neg_cnt++;
        min_abs = min(min_abs, abs(a[i]));
        sum += abs(a[i]);
    }
    if (neg_cnt % 2 == 1) {
        sum -= min_abs * 2;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

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

			if (10 <= a + b) {
				System.out.println("error");
			} else {
				System.out.println(a + b);
			}
		}
	}
}

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

// (i, j) => x : sのi文字目より前、tのj文字目より前で作った共通部分文字列の最大長
int dp[3001][3001];

int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    string s, t;
    cin >> s >> t;
    for(int i = 0; i < s.size(); i++) {
        for(int j = 0; j < t.size(); j++) {
            dp[i][j] = 0;
        }
    }
    for (int i = 1; i <= s.size(); i++) {
        for (int j = 1; j <= t.size(); j++) {
            dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
            if(s[i - 1] == t[j - 1]) {
                dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
            }
        }
    }
    int l = dp[s.size()][t.size()] - 1;
    string ans = "";
    for(int i = s.size() - 1; i >= 0; i--) {
        for(int j = t.size() - 1; j >= 0; j--) {
            if( dp[i][j] == l && s[i] == t[j] ) {
                l--;
                ans.push_back(s[i]);
                break;
            }
        }
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}

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

long long k, ans[100005], idx = 1;
queue <long long> q;

int main(){
    cin >> k;
    for (int i = 1; i < 10; i++){
        q.push(i);
    }
    while (ans[k] == 0){
        long long now = q.front();
        q.pop();
        int n = now % 10;
        if (n != 0) q.push(now * 10 + n - 1);
        q.push(now * 10 + n);
        if (n != 9) q.push(now * 10 + n + 1);
        ans[idx] = now;
        idx++;
    }
    cout << ans[k] << "\n";
}

Measured memory_bytes: 2560
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderB
{
    static void Main()
    {
        var sc = new Scanner();

        long h = sc.NextLong();
        long w = sc.NextLong();

        int[,] dist = new int[10, 10];
        for (int i = 0; i < 10; i++)
        {
            for (int j = 0; j < 10; j++)
            {
                dist[i, j] = sc.NextInt();
            }
        }

        for (int k = 0; k < 10; k++)
        {
            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    dist[i, j] = Math.Min(dist[i, j], dist[i, k] + dist[k, j]);
                }
            }
        }

        long answer = 0;
        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w; j++)
            {
                int num = sc.NextInt();
                if (num == -1)
                {
                    continue;
                }
                answer += dist[num, 1];
            }
        }

        Console.Write(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


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

int main(){
    int N;
    cin >> N;

    vector<int> vec(N);

    rep(i, N){
        cin >> vec.at(i);
    }

    sort(vec.begin(), vec.end());
    reverse(vec.begin(), vec.end());

    int alice = 0;
    int bob = 0;
    rep(i, N){
        if (i % 2 == 0){
            alice += vec.at(i);
        }
        else
        {
            bob += vec.at(i);
        }
        
    }
    cout << alice - bob << endl;
}

Measured memory_bytes: 3516
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#define MAX 100005
#define NIL -1

/*
p: parent
l: left-child
r: right sibling
*/
struct Node{ int p, l, r; };
struct Node T[MAX]; // Tree

int depth(int u){
	int d = 0;
	if (T[u].p == -1){ return 0; }
	return 1 + depth(T[u].p);
}

int height(int u){
	int l = 0, r = 0;
	if (T[u].l != -1){
		l += height(T[u].l);
		l++;
	}
	if (T[u].r != -1){
		r += height(T[u].r);
		r++;
	}
	return l <= r ? r:l;
}

void print(int u){
	printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s\n"
		, u
		, T[u].p
		, T[u].p == -1 || T[T[u].p].l == -1 || T[T[u].p].r == -1 ? -1 : (T[T[u].p].l != -1 && T[T[u].p].l != u ? T[T[u].p].l : T[T[u].p].r)
		, T[u].l == -1 && T[u].r == -1 ? 0 : (T[u].l != -1 && T[u].r != -1 ? 2 : 1)
		, depth(u)
		, height(u)
		, T[u].p == -1 ? "root" : (T[u].l == -1 && T[u].r == -1 ? "leaf" : "internal node")
		);
}

main(){
	int i, d, v, c, n;

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		T[i].p = T[i].l = T[i].r = NIL;
	}

	for (i = 0; i < n; i++){
		scanf("%d %d %d", &v, &d, &c);
		T[v].l = d;
		T[v].r = c;
		T[d].p = T[c].p = v;
	}
	for (i = 0; i < n; i++) print(i);
	return 0;
}

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

#define ll long long
#define ull unsigned long long
#define vii vector<int>
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pdd pair<double,double>
#define pldld pair<long long double, long long double>
#define ff first
#define ss second
#define pb push_back
#define read freopen("alu.txt","r",stdin);
#define write freopen("vorta.txt","w",stdout);
#define fastio ios::sync_with_stdio(false); cin.tie(NULL);
#define PI 2*acos(0.0)
#define DEBUG(x) cerr << #x << " = " << x << endl

const int MAX = 2e6 + 5, MOD = 1e9 + 7  , MAXLG = log2(MAX)+1;
const ll inf = 1e18 + 5;

int arr[MAX];
int main(){

    fastio;
    ll n,k;
    cin>>n>>k;
    if(n == k || !n) cout<<0<<"\n";
    else{
        if(n > k) n %= k;
        cout<<min(n, abs(n-k))<<"\n";
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e15+7;
const ll MOD=1e9+7;

ll minlen(ll s,ll t,ll x){
	if(s<=x&&t<=x){
		return max(abs(s-x),abs(t-x));
	}else if(s>=x&&t>=x){
		return max(abs(s-x),abs(t-x));
	}else{
		return min(abs(s-x),abs(t-x))*2+max(abs(s-x),abs(t-x));
	}
}


int main(){
	ll A,B,Q;
	cin >> A >> B >> Q;
	vector<ll> s(A),t(B);
	FOR(i,0,A)cin>>s[i];
	FOR(i,0,B)cin>>t[i];
	FOR(i,0,Q){
		ll x;
		cin >> x;
		ll s1,s2,t1,t2;
		s2 = POSL(s,x);
		t2 = POSL(t,x);
		s1 = s2-1;
		t1 = t2-1;
		if(s2<A)s2=s[s2];
		else s2 = INF;
		if(s1>=0)s1=s[s1];
		else s1 = -INF;
		if(t2<B)t2=t[t2];
		else t2 = INF;
		if(t1>=0)t1=t[t1];
		else t1 = -INF;
		ll ans = INF;
		ans = min(ans,minlen(s1,t1,x));
		ans = min(ans,minlen(s1,t2,x));
		ans = min(ans,minlen(s2,t1,x));
		ans = min(ans,minlen(s2,t2,x));
		cout << ans << endl;
	}
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template<class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template<class T> using ordered_multiset = tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;

typedef long long  ll;
typedef unsigned long long  ull;
#define lp(i,n)      for(int i=0;i<n;i++)
#define lpi(i,j,n)   for(int i=j;i<n;i++)
#define lpd(i,j,n)   for(int i=j;i>=n;i--)
#define MP           make_pair
#define clr(v, d)    (memset(v, d, sizeof(v)))
#define all(v)     (v.begin()),(v.end())
#define N 100005
const double pi = acos(-1);

ll n,t,m,k;

ll ans;
ll mod = 1e9 +7;
vector<int>adj[N];
int dis[N],vis[N][3];

queue<int>q;
void dfs(int node, int num, int reach){
  if(num==3){
    if(dis[node]==-1){
      dis[node]=reach;
      q.push(node);
    }
    return;
  }
  if(vis[node][num])return;
  vis[node][num]=1;
  for(auto& u:adj[node])dfs(u,num+1,reach);
}


int main() {
 
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
// freopen("e.txt","r",stdin); 
// freopen("e_out.txt","w",stdout); 
cout.precision(7);

cin>>n>>m;
lp(i,m){
  int x,y;
  cin>>x>>y;
  adj[x].push_back(y);
}
int S,T;
cin>>S>>T;
lp(i,n+1)dis[i]=-1;
q.push(S);
dis[S]=0;
while(!q.empty()){
  int node = q.front();
  q.pop();
  dfs(node,0,dis[node]+1);
}
cout<<dis[T];





  
}
  
 



// bool isPrime(ll h){
//      for(ll i=0;primes[i]*primes[i]<= h;i++)
//      if (h%primes[i]==0)
//      	return 0;
//      return h!=1;
//  }
 bool isPrime(ll g){
   if((g%2==0 && g>2) || g==1)return 0;
   for(ll i=3;i*i<=g;i+=2)if(g%i==0)return 0;
   return 1;   
 
 }

Measured memory_bytes: 10560
#include <iostream>
#include <algorithm>
#include <iomanip>

using namespace std;

const int INF = 100000000;


int d[10][10];
int ans1, ans2;
bool town[10];


main(){
   int n;
   while(cin >> n && n){
      fill(d[0], d[10], INF);
      fill(town, town+10, false);
      for(int i=0;i<n;i++){
         int a, b, c;
         cin >> a >> b >> c;
         town[a] = true;
         town[b] = true;
         d[a][b] = d[b][a] = c;
      }
      for(int k=0;k<10;k++){
         for(int i=0;i<10;i++){
            for(int j=0;j<10;j++){
               d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
         }
      }
      ans2 = INF;
      for(int i=0;i<10;i++){
         if(!town[i]) continue;
         int sum = 0;
         for(int j=0;j<10;j++){
            if(i == j) continue;
            if(!town[j]) continue;
            sum += d[i][j];
         }
         if(ans2 > sum){
            ans2 = sum;
            ans1 = i;
         }
      }
      cout << ans1 << ' ' << ans2 << endl;
   }
   return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void){

	int a[1000001]={};
	int s;
	cin >> s;

	for(int i = 1; i < 1000001; i++){
		if(a[s] == 1){
			cout << i << endl;
			break;
		}
		a[s] = 1;
		if(s%2 == 0){	//偶数
			s = s/2;
		}else{			//奇数
			s = 3*s+1;
		}
	}

	return 0;

}

Measured memory_bytes: 4096