akhauriyash/Code-Regression huggingface dataset:
s = input()
t = "keyence"
if t in s:
    print("YES")
    exit()
if len(s) >= 7:
    if "k" in s and "eyence" in s:
        if s[0] == "k" and s[-1] == "e" and s[-2] == "c" and s[-3] == "n" and s[-4] == "e" and s[-5] == "y" and s[-6] == "e":
            print("YES")
            exit()
    if "ke" in s and "yence" in s:
        if s[0] == "k" and s[-1] == "e" and s[-2] == "c" and s[-3] == "n" and s[-4] == "e" and s[-5] == "y" and s[1] == "e":
            print("YES")
            exit()
    if "key" in s and "ence" in s:
        if s[0] == "k" and s[-1] == "e" and s[-2] == "c" and s[-3] == "n" and s[-4] == "e" and s[2] == "y" and s[1] == "e":
            print("YES")
            exit()
    if "keye" in s and "nce" in s:
        if s[0] == "k" and s[-1] == "e" and s[-2] == "c" and s[-3] == "n" and s[3] == "e" and s[2] == "y" and s[1] == "e":
            print("YES")
            exit()
    if "keyen" in s and "ce" in s:
        if s[0] == "k" and s[-1] == "e" and s[-2] == "c" and s[4] == "n" and s[3] == "e" and s[2] == "y" and s[1] == "e":
            print("YES")
            exit()
    if "keyenc" in s and "e" in s:
        if s[0] == "k" and s[-1] == "e" and s[5] == "c" and s[4] == "n" and s[3] == "e" and s[2] == "y" and s[1] == "e":
            print("YES")
            exit()
print("NO")


Measured memory_bytes: 3188
/*
@author: @sancodemonster
*/
 
#include <bits/stdc++.h>
 
#define flash ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define endl '\n'
#define ll long long int
#define ld long double
#define pb push_back 
#define mp make_pair
#define MOD 1000000007
#define f(i,a,b)  for(long long i=a;i<b;i++)
#define all(c) (c).begin(),(c).end() 
using namespace std;

ll h,w;
char a[1004][1004];	
ll dp[1004][1004];

ll rec(ll i,ll j)
{
   if(i == h && j == w)
   	return 1;
   if(a[i][j] == '#')
   	return 0;
   if(dp[i][j] != -1)
   	return dp[i][j];

   ll a = 0,b = 0;

   if(i<h)
      a = rec(i+1,j);
   if(j<w)
      b = rec(i,j+1);

   dp[i][j] = (a%MOD + b%MOD)%MOD;
   return dp[i][j];
}
int main()
{
 
     flash;
     /////////////////////////////////////////////////////////////////////////////////////////////////////
      ll i,j;

      cin>>h>>w;

      f(i,1,h+1)
       f(j,1,w+1)
         cin>>a[i][j];

      f(i,1,1004)
       f(j,1,1004)
         dp[i][j] = -1;

      ll ans = rec(1,1); 
      cout<<ans;
     /////////////////////////////////////////////////////////////////////////////////////////////////////

     return 0;
}


Measured memory_bytes: 9216
n = int(input())
l = list(map(int, input().split()))

c = 0
c_max = 0
for i in range(n-1):
  if l[i] >= l[i+1]:
    c += 1
  else:
    if c >= c_max:
      c_max = c
    c = 0

if c >= c_max:
  c_max = c

print(c_max)

Measured memory_bytes: 14252
#include<iostream>
using namespace std;
long long a[100010],T,n,tot,s,tt;
int main()
{
	cin>>n;s=n*(n+1)/2;
	for(int i=1;i<=n;i++) cin>>a[i],tot+=a[i];
	if(tot%s!=0) return puts("NO"),0;
	T=tot/s;a[n+1]=a[1];
	for(int i=1;i<=n;i++)
		if((T+a[i]-a[i+1])%n||T+a[i]-a[i+1]<0)
			return puts("NO"),0;
		else tt+=(T+a[i]-a[i+1])/n;
	tt==T?puts("YES"):puts("NO");
}


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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            var N = line[0];
            var X = line[1];
            var min = X;
            var ans = N;

            for(var i = 0; i < N; i++)
            {
                var m = int.Parse(Console.ReadLine());
                X -= m;
                if (m < min) min = m;
            }

            ans += X / min;            

            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 13396
N = int(input())
S = [input() for _ in range(N)]

XA = 0
BX = 0
BXA = 0
cnt = 0
for Si in S:
    cnt += Si.count("AB")

    tp = (Si[0] == "B")*1 + (Si[-1] == "A")*2
    if tp == 1:
        BX += 1
    elif tp == 2:
        XA += 1
    elif tp == 3:
        BXA += 1

if BXA > 0:
    cnt += BXA - 1
    BXA = 1

if BXA > 0:
    if BX > 0:
        cnt += 1
        BX -= 1
    if XA > 0:
        cnt += 1
        XA -= 1

pair = min(BX, XA)
if pair > 0:
    cnt += pair
    BX -= pair
    XA -= pair


print(cnt)

Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
    cin>>s;
    int len=s.size();
    for(int i=0;i<=len;i++)
    {
        if(s[i]=='C')
        {
            for(int j=i;j<=len;j++)
        {
                if(s[j]=='F')
                {
                    cout<<"Yes"<<endl;
                    return 0;
                }
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using  namespace  std;
int  main (){
int  d[10];
for(int  i = 0;  i<6;  i++){
scanf("%d" , &d[i] );
}
sort(d,d+6);
int ans=0;
/*int tmp=0;
int cnt=1;
for(int i=0;i<6;i++){
if(tmp==d[i])cnt++;
else{
tmp=d[i];
if(cnt>=3)ans=1;
cnt=1;
}
}*/
int a[4];
for(int ii=0;ii<4;ii++){
a[ii]=0;
}
for(int ii=0;ii<6;ii++){
a[d[ii]-1]++;
}
if(a[0]>=3||a[1]>=3||a[2]>=3||a[3]>=3)ans=1;
if(ans==1) printf("NO\n");
else printf("YES\n" );
}

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

int height(int xs[], int ys[], int hs[], int cx, int cy, int n) {
    int i = 0;
    for (; hs[i] == 0; i++) {}
    int ch = hs[i] + abs(xs[i] - cx) + abs(ys[i] - cy);
    for (i = 0; i < n; i++) {
        if (hs[i] != max(ch - abs(xs[i] - cx) - abs(ys[i] - cy), 0))
            return 0;
    }
    return ch;
}

int main() {
    int n;
    cin >> n;
    int xs[n], ys[n], hs[n];
    for (int i = 0; i < n; i++) {
        cin >> xs[i] >> ys[i] >> hs[i];
    }
    for (int cy = 0; cy <= 100; cy++) {
        for (int cx = 0; cx <= 100; cx++) {
            int ch = height(xs, ys, hs, cx, cy, n);
            if (ch > 0) {
                cout << cx << ' ' << cy << ' ' << ch << endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
#=
B:
- Julia version: 0.5.2
- Author: abap
- Date: 2019-12-29
=#
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
A,B,K = parseMap(split(readline()))
if A > K
    A -= K
else
	B -= K - A
    A = 0
end

if B < 0
	B = 0
end
println("$A $B")

Measured memory_bytes: 170176
#00:46
n,k = map(int,input().split())
raw = [[] for _ in range(n)]
for _ in range(n):
  t,d = map(int,input().split())
  t -= 1
  raw[t].append(d)
only = []
other = []
for i in range(n):
  if len(raw[i]) != 0:
    raw[i].sort(reverse = True)
    only.append(raw[i][0])
    other += raw[i][1:]
only.sort(reverse = True)
only += [-10 ** 18 for _ in range(k)]
other.sort(reverse = True)
now = sum(only[:k])
can = [now + k * k]
for j in range(k):
  try:
    now -= only[k-1-j]
    now += other[j]
    can.append(now + (k-1-j) ** 2)
  except:
    break
print(max(can))

Measured memory_bytes: 20016
#include<bits/stdc++.h>
 
using namespace std;
 
void solve(int TestCase) {
    string s;
    cin >> s;
    
    if(s.size() != 6 || s[2] != s[3] || s[4] != s[5]) {
        cout << "No" << endl;
        return;
    }
 
    cout << "Yes" << endl;
}
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 
    int t = 1;
    //cin >> t;
    for(auto i = 1; i <= t; ++i) {
        //cout << "Case #"<< i << ": ";
        solve(i);
    }
}

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

int main() {
  int N, l, r, ans;
  ans = 0;
  cin >> N;
  for (int i = 0;i < N; i++){
    cin >> l >> r;
    ans += r - l + 1;
  }
  cout << ans << endl;

  
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int[] a = new int[100001];
    long s = 0;
    for (int i = 0; i < n; i++) {
      int tmp = sc.nextInt();
      a[tmp]++;
      s += tmp;
    }

    int q = sc.nextInt();
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < q; i++) {
      int b = sc.nextInt();
      int c = sc.nextInt();

      a[c] += a[b];
      s += (c - b) * a[b];
      a[b] = 0;

      sb.append(s + "\r\n");
    }

    System.out.print(sb);
  }
}


Measured memory_bytes: 54836
K,N = map(int, input().split())
A_list = list(map(int, input().split()))

x_list = A_list[:-1]

y_list = A_list[1:]

diff_list = list(map(lambda x,y: y - x, x_list, y_list))
diff_list.append(int(K-A_list[-1] + A_list[0]))

print(K - max(diff_list))


Measured memory_bytes: 26420
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

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

    li x, k, d;
    cin >> x >> k >> d;
    x = abs(x);

    li ans = 1LL << 62;

    li mreq = x / d;
    if (k < mreq) {
        ans = min(ans, x - d * k);
    } else {
        li rem = k - mreq;
        if (rem % 2 == 0) {
            ans = min(ans, x - d * mreq);
        } else {
            ans = min(ans, abs(x - d * (mreq + 1)));
        }
    }

    cout << ans << endl;

    return 0;
}

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

#define MAX_N 25

int main(){
//	freopen("input.txt", "r", stdin);
	int N;
	scanf("%d", &N);

	int V[MAX_N], C[MAX_N];
	for(int i = 0; i < N; i++) scanf("%d", V + i);
	for(int i = 0; i < N; i++) scanf("%d", C + i);
	int res = 0;
	for(int i = 0; i < N; i++) res += max(0, V[i] - C[i]);
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;
 
template<class T> void max_self(T & a, const T & b) { if(a < b) a = b; }
template<class T> void min_self(T & a, const T & b) { if(a > b) a = b; }
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);


int main(){
	FAST_IO
	
	int N, Z, W;
	cin >> N >> Z >> W;
	int last = -1, secLast = -1;
	
	for(int rep = 0; rep < N; ++rep){
		secLast = last;
		cin >> last;
	}
	
	if(secLast == -1) cout << abs(W - last);
	else{
		cout << max(abs(W - last), abs(secLast - last));
	}
		
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
string s,ans;
int i,a,j,k;
int main() {
  cin >> s;
  a = s.size();
  for(i=0;i<a;i++) {
    if(s[i]=='B') {
      k = k+1;
      if(j!=0) {
        j = j-1;
      }
    }
    else {
      ans[j] = s[k];
      j = j+1;
      k = k+1;
    }
  }
  a = j;
  for(int l=0;l<a;l++) {
    cout << ans[l];
  }
  cout << endl;
  return(0);
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
        int s,i,a[1000];
        scanf("%d",&s);

        a[0]=s;

        for(i=1;i>0;i++){
                if(a[i-1]%2==0) a[i]=a[i-1]/2;
                else            a[i]=a[i-1]*3+1;
                for(int j=0;j<i;j++)
                        if(a[i]==a[j]) {
                                printf("%d\n",i+1);
                                return 0;
                        }
        }
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
     
    using namespace std;
     
    void __print(int x) {
        cerr << x;
    }
    void __print(long x) {
        cerr << x;
    }
    void __print(long long x) {
        cerr << x;
    }
    void __print(unsigned x) {
        cerr << x;
    }
    void __print(unsigned long x) {
        cerr << x;
    }
    void __print(unsigned long long x) {
        cerr << x;
    }
    void __print(float x) {
        cerr << x;
    }
    void __print(double x) {
        cerr << x;
    }
    void __print(long double x) {
        cerr << x;
    }
    void __print(char x) {
        cerr << '\'' << x << '\'';
    }
    void __print(const char *x) {
        cerr << '\"' << x << '\"';
    }
    void __print(const string &x) {
        cerr << '\"' << x << '\"';
    }
    void __print(bool x) {
        cerr << (x ? "true" : "false");
    }
     
    template<typename T, typename V>
    void __print(const pair<T, V> &x) {
        cerr << '{'; __print(x.first);
        cerr << ','; __print(x.second);
        cerr << '}';
    }

    template<typename T>
    void __print(const T &x) {
        int f = 0;
        cerr << '{';
        for (auto &i: x)
            cerr << (f++ ? "," : ""), __print(i);
         cerr << "}";
    }
    void _print() {
        cerr << "]\n";
    }
    template <typename T, typename... V>
    void _print(T t, V... v) {
        __print(t); 
        if (sizeof...(v))
            cerr << ", ";
        _print(v...);
    }
     
    #ifndef ONLINE_JUDGE
    #define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
    #else
    #define debug(x...)
    #endif
     
    #define forn(i, n) for(int i = 0; i < n; i++)
    #define forw(i, w) for(int i = n; i >= 0; i--)
    #define dforn(i, a, b) for(int i = a; i < b; i++)
    #define dforw(i, b, a) for(int i = b; i >= a; i--)
    #define read(v) for(auto &i:v) cin >> i;
    #define all(v) v.begin(), v.end()
     
    typedef long long ll;
    typedef vector<int> vi;
    typedef vector<double> vd;
    typedef pair<int, int> pii;
     
    int n, k;
    vi arr, dp;
     
    int main(){
    	ios_base::sync_with_stdio(0);
    	cout.tie(0);cin.tie(0);
    	
    	cin >> n >> k;
     
    	arr.assign(n, 0);
    	dp.assign(n, 999999999);
    	dp[0] = 0;
    	read(arr);
     
    	forn(i, n)
    		for(int j = i+1; j < n && j < i+k+1; j++)
    			dp[j] = min(dp[j], dp[i]+abs(arr[j]-arr[i]));
     
    	cout << dp[n-1] << endl;	
    	return 0;
    }

Measured memory_bytes: 1024
n=int(input())-1
j=26
while j<=n:
  n-=j
  j*=26
j//=26
ret = ""
while j:
  ret += "abcdefghijklmnopqrstuvwxyz"[n//j]
  #print(f'{n//j=}')
  n %= j
  j //= 26
print(ret)


Measured memory_bytes: 9160
n, m = map(int, input().split())

patterns = [list(map(int, input().split())) for _ in range(m)]
correct = list(map(int, input().split()))

ans = 0
# bit全探索
for i in range(2 ** n):
    flg = True
    # 全パターンの電球について
    for p in range(m):
        switched = 0
        # bit全探索　各スイッチを調べる
        for j in range(n):
            if (i >> j) & 1:
                if (j + 1) in patterns[p][1:]:
                    switched += 1
        if not (switched % 2) == correct[p]:
            flg = False
            break
    if flg is True:
        ans += 1

print(ans)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main(){
	int n=0;
	int ans[]={64,32,16,8,4,2,1};
	cin >> n;
	for(int i=0;;i++){
		if(n>=ans[i]){
				cout << ans[i] << endl;
				break;
		}
	}
	return 0;
}


Measured memory_bytes: 256
//piupiuplu

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>

using namespace std;

int main()
{
	int l,r;
	cin>>l>>r;
	int min1=2019;
	if(r-l>=4037)
	{
		cout<<0;
		return 0;
	}
	for(int i=l;i<r;i++)
		for(int j=i+1;j<=r;j++)
			min1=min(((i%2019)*(j%2019))%2019,min1);
	cout<<min1;
	return 0;
}

Measured memory_bytes: 256
mat = []
for _ in range(8):
    mat.append(list(input()))

mat90 = [[0 for i in range(8)] for j in range(8)]
print(90)
for i in range(8):
    for j in range(8):
        mat90[i][j] = mat[7-j][i]

for i in range(8):
    print(''.join(m for m in mat90[i]))

mat180 = [[0 for i in range(8)] for j in range(8)]
print(180)
for i in range(8):
    for j in range(8):
        mat180[i][j] = mat90[7-j][i]

for i in range(8):
    print(''.join(m for m in mat180[i]))

mat270 = [[0 for i in range(8)] for j in range(8)]
print(270)
for i in range(8):
    for j in range(8):
        mat270[i][j] = mat180[7-j][i]

for i in range(8):
    print(''.join(m for m in mat270[i]))



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

using namespace std;

int main(){
  string a;
  int n;
  cin>>n>>a;
  for(int i=0;i<n && i<a.length();i++){
    putchar(a[i]);
  }
  if(a.length()>n)printf("...");
  puts("");
}

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

int main()
{
  double x,q,n;
  for(;cin>>q,q!=-1;)
    {
      x=q/2;
      for(;abs((x*x*x)-q)>=0.000001*q;)
	{
	  x=x-(
	       ((x*x*x)-q)
	       /
	       (3*x*x)
	       );
	}
      printf("%.6f\n",x);
      //      cout<<setprecision(7)<<x<<endl;
    }
}

Measured memory_bytes: 1236
import sys

N = int(input())
A = list(map(int, sys.stdin.readline().rsplit()))
S = [0] * (N + 1)
s = sum(A)

for i in range(N):
    S[i + 1] += S[i] + A[i]

mini = 10 ** 18
for i in range(1, N + 1):
    mini = min(mini, abs(S[N] - 2 * S[i]))

print(mini)


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

#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,a,n) for(ll i=a;i<n;i++)

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tiii;
typedef pair<ll, ll> pll;

const int INF = 100000000;
const ll LINF = 1e18+5;

struct edge{
    int to, cost;
    edge(int t, int c) {to = t; cost = c;};
};

int main() {
    ll a, b, x;
    cin >> a >> b >> x;
    ld A, B, X;
    A = (ld)a;
    B = (ld)b;
    X = (ld)x;
    ld S = X / A;
    if(S < A * B / 2.0 + 0.00000001) {
        ld A2 = S * 2.0 / B;
        ld rad = atan2(A2, B);
        cout << fixed;
        cout << setprecision(8) << 90.0 - 180.0*rad/M_PI << endl;
    } else {
        ld A3 = 2.0 * S / A - B;
        ld B2 = B - A3;
        ld rad = atan2(A, B2);
        cout << fixed;
        cout << setprecision(8) << 90.0 - 180.0*rad/M_PI << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int a,b; cin >> a >> b;
    if(b==1) cout << 0 << endl;
    else cout << (b-2)/(a-1)+1 << endl;
}
//(a-1)x+a>=b == x>=(b-a)/(a-1)



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

vector<pair<int, int> > a(2010);
long dp[2010][2010];

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

int main(){
	int n, x;
	scanf("%d", &n);
	for(int i = 0; i < n; i++) {
		scanf("%d", &x);
		a.push_back(make_pair(x, i));
	}
	sort(a.begin(), a.end(), greater<pair<int, int> >());
	long ans = 0;
	for(int i = 0; i < n; i++) {
		for(int l = 0; l <= i; l++) {
			int r = i - l;
			chmax(dp[i+1][l+1], dp[i][l] + (long)a[i].first * abs(l - a[i].second));
			chmax(dp[i+1][l], dp[i][l] + (long)a[i].first * abs((n-1-r) - a[i].second));
		}
	}
	for(int i = 0; i < n; i++) chmax(ans, dp[n][i]);
	printf("%ld\n", ans);
}

Measured memory_bytes: 26528
#include <bits/stdc++.h>
using namespace std;
string a,b;
long long ans,ans1;
int main()
{
	cin>>a>>b;
	ans1=1e10;
	for(int i=0;i+b.length()-1<a.length();i++)
	{
		ans=0;
		for(int j=0;j<b.length();j++)
		{
			if(a[i+j]!=b[j])
			ans++;
		}
		ans1=min(ans,ans1);
	}
	cout<<ans1<<endl;
	return 0;
}

Measured memory_bytes: 3600
#include <iostream>

int main() {
    using namespace std;
    int sum = 0;
    for(int i = 0; i < 3; ++i)
    {
        int in = 0;
        cin >> in;
        sum += in;
    }

    if(sum >= 22) 
    {
        cout << "bust" << endl;
    }
    else
    {
        cout << "win" << endl;
    }
    return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 151

int N;
double dp[NUM][2*NUM];
int height[NUM];

int main(){

	scanf("%d",&N);

	for(int i = 1; i <= N; i++){

		scanf("%d",&height[i]);
	}

	for(int i = 0; i <= N; i++){
		for(int k = 0; k <= 300; k++){
			dp[i][k] = (double)BIG_NUM;
		}
	}

	dp[0][1] = 0;

	double A,B;

	for(int i = 1; i <= N; i++){
		for(int pre_h = 1; pre_h <= 300; pre_h += 1){

			//if(fabs(dp[i-1][pre_h]-BIG_NUM) < EPS)continue;

			for(int this_h = 1; this_h <= 300; this_h += 1){

				if(height[i] >= pre_h && height[i] >= this_h){

					A = (double)(height[i]-pre_h);
					B = (double)(height[i]-this_h);

					dp[i][this_h] = min(dp[i][this_h],dp[i-1][pre_h]+(A+B)/2.0);

				}else if(height[i] >= pre_h && height[i] < this_h){

					A = (double)(height[i]-pre_h);
					B = (double)(this_h-height[i]);

					dp[i][this_h] = min(dp[i][this_h],dp[i-1][pre_h]+A*(A/(A+B))/2+B*(B/(A+B))/2);

				}else if(height[i] < pre_h && height[i] < this_h){

					A = (double)(pre_h-height[i]);
					B = (double)(this_h-height[i]);

					dp[i][this_h] = min(dp[i][this_h],dp[i-1][pre_h]+(A+B)/2.0);

				}else if(height[i] < pre_h && height[i] >= this_h){

					A = (double)(pre_h-height[i]);
					B = (double)(height[i]-this_h);

					dp[i][this_h] = min(dp[i][this_h],dp[i-1][pre_h]+A*(A/(A+B))/2+B*(B/(A+B))/2);
				}
			}
		}
	}

	double ans = BIG_NUM;

	for(int h = 1; h <= 300; h++){

		ans = min(ans,dp[N][h]);
	}

	printf("%.10lf\n",ans);

	return 0;
}



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

int main(){
  int a,b;

  cin >> a >> b;

  int c=a+b;
  int d=a-b;
  int e=a*b;

  if(c > d)
    {
      if(c > e)cout << c << endl;
      else cout << e << endl;
    }
  else
    {
      if(d > e)cout << d << endl;
      else cout << e << endl;
    }
}

  


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<math.h>
#include<queue>
#include<cstdio>
#include<set>
#include<map>
using namespace std;

int main(){
    int N,K;
    cin >> N >> K;
    vector<int> H(N);
    for(int i=0; i<N; i++){
        cin >> H.at(i);
    }
    sort(H.begin(),H.end());
    int64_t sum=0;
    for(int i=0; i<N-K; i++){
        sum += H.at(i);
    }  
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define repC3(vari,varj,vark,n)  for(int vari=0;vari<(n)-2;++vari)for(int varj=vari+1;varj<(n)-1;++varj)for(int vark=varj+1;vark<(n);++vark)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
using namespace std;
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }


int main() {
    int N;
    double ans=0;
    cin>>N;
    int x[N],y[N];
    double xy[N][N];
    rep(i,N){
        cin>>x[i]>>y[i];

    }
    rep(i,N){
        rep(j,N){
            if(i!=j){
                xy[i][j]=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
                ans+=xy[i][j];
            }else{
                xy[i][i]=0;
            }
        }
    }
    ans/=N;
    printf("%.10f",ans);
    return 0;
}

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

int main(){
    string S;
    int n = 0;
    cin >> n;
    cin >> S;
    rep(i,S.length()){
        S[i] += n;
        if(S[i] > 'Z'){
            S[i] -= 26;
        }
    }


    cout << S << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // CODE FESTIVAL 2017 qual A C - Palindromic Matrix
  // 4 : H/2 * W/2
  // 2 : H%2 * W/2 + H/2 * W%2
  // 1 : H%2 * W%2
  int H, W; cin >> H >> W;
  vector<string> a(H);
  REP(i, H){
    cin >> a[i];
  }
  
  vector<int> res(3, 0);
  res[0] = (H/2) * (W/2);
  res[1] = (H%2) * (W/2) + (H/2) * (W%2);
  res[2] = (H%2) * (W%2);
  
  vector<int> alp(26, 0);
  REP(i, H){
    REP(j, W){
      alp[a[i][j] - 'a']++;
    }
  }

  vector<int> ans(3, 0);
  REP(i, 26){
    ans[0] += alp[i] / 4; alp[i] %= 4;
    ans[1] += alp[i] / 2; alp[i] %= 2;
    ans[2] += alp[i];
  }
  
  if(ans[0] < res[0]){
    cout << "No" << endl;
    return 0;
  }else if(ans[0] > res[0]){
    ans[1] += (ans[0] - res[0]) * 2;
  }
  if(ans[1] < res[1]){
    cout << "No" << endl;
    return 0;
  }
  
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a=sc.nextInt(),b=sc.nextInt();
        int ans=0;
        for(int i=a;i<=b;i++){
            if(iskaibun(i))ans++;
        }
        System.out.println(ans);
    }
    static boolean iskaibun(int in){
        String s=Integer.toString(in);
        boolean output=true;
        for(int i=0;i<s.length()/2;i++){
            output&=s.charAt(i)==s.charAt(s.length()-i-1);
        }
        return output;
    }
}


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

void printArray(int a[], int n){
    for(int i = 0; i < n; i++){
        if(i != n - 1)
            cout << a[i] << " ";
        else
            cout << a[i];
    }
    cout << endl;
}

void insertionSort(int a[],int n){
    int tmp, j;
    for(int i = 1; i < n;i++){
        tmp = a[i];
        j = i - 1;
        while(j >= 0 && a[j] > tmp){
            a[j+1] = a[j];
            j--;
        }
        a[j+1] = tmp;
        printArray(a,n);
    }
}

int main(){
    int n,a[200];
    cin >> n;
    for(int i = 0;i < n;i++){
        cin >> a[i];
    }
    printArray(a,n);
    insertionSort(a,n);

    return 0;
}


Measured memory_bytes: 3088
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

/*

a
aaa
//=> 3

contest
contest
//=> 7

*/

fn char_to_index(c: char) -> usize {
    (c as u8 - b'a') as usize
}

fn solve_fast(s: &[char], t: &[char]) -> Option<usize> {
    let sn = s.len();

    // s を2個つなげた文字列を w とする。
    let wn = sn * 2;

    // next[ci][si]:
    // w の位置 si (< sn) から見て次に文字 ci が出現する位置
    let mut next = vec![vec![None; sn]; 26];

    for ci in 0..26 {
        // w において最後に文字 ci が出現した位置
        let mut last = None;

        for wi in (0..wn).rev() {
            if char_to_index(s[wi % sn]) == ci {
                last = Some(wi);
            }

            next[ci][wi % sn] = last;
        }
    }

    let mut i = 0;
    for &c in t {
        let si = i % sn;
        let ni = match next[char_to_index(c)][si] {
            None => return None,
            Some(ni) => ni,
        };
        i += ni - si + 1;
    }
    Some(i)
}

fn main() {
    let s = rl().chars().collect::<Vec<_>>();
    let t = rl().chars().collect::<Vec<_>>();

    if let Some(i) = solve_fast(&s, &t) {
        println!("{}", i)
    } else {
        println!("-1")
    }
}


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

int main(){

    int n, k;
    cin >> n >> k;
    vector<int> A(n);
    for (int i=0; i<n; i++){
        cin >> A.at(i);
    }

    int cnt = 0;
    for (int j=0; j<k; j++){
        vector<int> B(n, 0);
        
        for (int i=0; i<n; i++){

            int l = max(0, i - A.at(i));
            int r = min(n-1, i + A.at(i));

            B.at(l)++;
            if (r+1<n) B.at(r+1)--;
        }
        for (int i=1; i<n; i++){
            B.at(i) += B.at(i-1);
        }
        for (int i=0; i<n; i++){
            A.at(i) = B.at(i);

            if (A.at(i) == n) cnt++;
        }

        if (cnt == n) break;
        cnt = 0;
    }

    for (auto x: A){
        cout << x << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 4780
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall

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

start = []
goal = []
cost = []
for _ in range(M):
    A, B, C = map(int, input().split())
    A -= 1
    B -= 1
    start.append(A)
    goal.append(B)
    cost.append(C)
    start.append(B)
    goal.append(A)
    cost.append(C)

graph = csr_matrix((cost, (start, goal)), shape = (N, N))
can_reach_with_L = floyd_warshall(graph, directed = False)
can_reach_with_L[can_reach_with_L > L] = 0
ans = floyd_warshall(can_reach_with_L, directed = False, unweighted = True)

Q = int(input())
for _ in range(Q):
    s, t = map(int, input().split())
    s -= 1
    t -= 1
    if ans[s][t] == float('inf'):
        print(-1)
    else:
        print(int(ans[s][t] + 0.5) - 1)


Measured memory_bytes: 45440
// Reads multiple ints in a line, separate by a space.
// It works even if the actual number of ints is smaller than n.
// WARNING: This function does not work for -2^31.
// NOTE: This function does not handle error cases.
fun fastReadInts(n: Int): IntArray {
  val xs = IntArray(n)
  val s = readLine()!!
  var currentValue = 0
  var isNegative = false
  var currentIndex = 0
  for (c in s) {
    if (c == ' ') {
      xs[currentIndex] = currentValue * if (isNegative) -1 else 1
      currentValue = 0
      isNegative = false
      currentIndex++
    } else if (c == '-') {
      isNegative = true
    } else {
      currentValue *= 10
      currentValue += c - '0'
    }
  }
  xs[currentIndex] = currentValue * if (isNegative) -1 else 1
  return xs
}

fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val xs = fastReadInts(n)
  val ys = xs.sorted()
  val m1 = ys[n / 2 - 1]
  val m2 = ys[n / 2]
  val zs = xs.map { if (it <= m1) m2 else m1 }
  println(zs.joinToString(" "))
}


Measured memory_bytes: 78048
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    ll n; cin >> n;
    int ans = 1e8;
    for(ll i = 1;i * i <= n;i++) {
        if (n % i == 0) {
            string s = to_string(max(n/i,i));
            ans = min(ans,static_cast<int>(s.size()));
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <map>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define supd 100001
#define SUPR 20
#define ZERO 1e-20


double p[supd][SUPR]; //p[d][r] = d niti me, r ko renzoku site bentou totteru kauritu
double u[supd][SUPR]; //u[d][r] = d niti me, r ko renzoku site bentou totta toki, imamade no bentou no kitaiti

int solve(){
	FOR(d,0,supd) FOR(r,0,SUPR) p[d][r]=u[d][r]=0;
	p[0][0]=1;

	FOR(d,1,supd){
		FOR(r,0,SUPR){
			if(r==0)
				FOR(k,0,SUPR)
					p[d][r] += p[d-1][k]*(1-pow(0.5,k));
			else
				p[d][r] = p[d-1][r-1]*pow(0.5,r-1);

			if(r==0){
				if(p[d][r]>ZERO)
					FOR(k,0,SUPR)
						if(p[d-1][k]>ZERO) 
							u[d][r] += u[d-1][k] * p[d-1][k]*(1-pow(0.5,k))/p[d][r]; //actually p((d,r)->(d-1,k)).   used "p(b->a) = p(a)*p(a->b)/p(b)."
			}
			else
				if(p[d-1][r-1]>ZERO)
					u[d][r] = u[d-1][r-1]+1;

			//if(p[d][r]>ZERO) cout << "d:" << d << " r:" << r << " p:" << p[d][r] << " u:" << u[d][r] << endl;
		}
	}
}

double getres(int d){
	double res = 0;
	FOR(r,0,SUPR) if(p[d][r]>ZERO) res += u[d][r]*p[d][r];
	return res;
}

int main(){
	solve();
	while(true){
		int d;
		scanf("%d",&d);				if(d==0) return 0;
		printf("%.8f\n", getres(d));
	}
}

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

int main(){
        ll n, k, r, s, p;
        scanf("%lld %lld %lld %lld %lld", &n, &k, &r, &s, &p);
        string t; cin>>t;

        vector<string> ss(k);
        for(ll i=0; i<k; i++) ss[i] = "";
        for(ll i=0; i<n; i++) ss[i%k] += t[i];

        ll ans = 0;
        for(ll i=0; i<k; i++){
                auto prev = ss[i][0];
                ll cnt = 0;
                for(auto c: ss[i]){
                        if(c==prev) cnt++;
                        else{
                                ll tmp = (cnt+1)/2;
                                if(prev=='r') ans += tmp*p;
                                else if(prev=='s') ans += tmp*r;
                                else ans += tmp*s;
                                cnt = 1;
                        }
                        prev = c;
                }
                ll tmp = (cnt+1)/2;
                if(prev=='r') ans += tmp*p;
                else if(prev=='s') ans += tmp*r;
                else ans += tmp*s;
        }
        printf("%lld\n", ans);
        return 0;
}

Measured memory_bytes: 5120
#include<iostream>
#include<algorithm>
#include<cstdlib>
using namespace std;

int n;
int p[30], l[30], r[30];

void dfs(int depth, int n, int i){
  if(p[n] == -1){
    cout << "depth = " << depth << ", ";
    return ;
  }

  dfs(depth + 1, p[n], i);
  return ;
}

int height(int i, int h){
  int hl = 0, hr = 0;

  if(l[i] == -1 && r[i] == -1) return h;
  if(l[i] != -1) hl = height(l[i], h + 1);
  if(r[i] != -1) hr = height(r[i], h + 1);

  return max(hl, hr);
}

void searchsibling(int i){
  if(p[i] == -1) cout << "sibling = " << -1 << ", ";
  else if(l[p[i]] == i) cout << "sibling = " << r[p[i]] << ", ";
  else cout << "sibling = " << l[p[i]] << ", ";
}

void searchdegree(int i){
  if(l[i] == r[i]) cout << "degree = " << 0 << ", ";
  else if(l[i] == -1 || r[i] == -1) cout << "degree = " << 1 << ", ";
  else cout << "degree = " << 2 << ", ";
}

void searchtype(int i){
  if(p[i] == -1) cout << "root";
  else if(l[i] == -1 && r[i] == -1) cout << "leaf";
  else cout << "internal node";
}

void solve(){
  for(int i = 0;i < n;i++){
    cout << "node " << i << ": ";
    cout << "parent = " << p[i] << ", ";
    searchsibling(i);
    searchdegree(i);
    dfs(0, i, i);
    cout << "height = " << height(i, 0) << ", ";
    searchtype(i);
    cout << endl;
  }
}

int main(){
  cin >> n;
  for(int i = 0;i < n;i++) p[i] = l[i] = r[i] = -1;
  for(int i = 0;i < n;i++){
    int id, left, right;

    cin >> id >> left >> right;
    l[id] = left;
    r[id] = right;
    p[left] = p[right] = id;
  }

  solve();

  return 0;
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
  
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
typedef long long ll;

const ll MOD=1000000007ll;
const int MAX=5100000;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

ll fact[MAX], fact_inv[MAX];

ll power(ll a, ll b){
	ll res=1;
	while(b>0){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

// nCr
ll comb(ll n, ll r){
	ll t=1000000;
	fact[0]=1;
	REP(i, t) fact[i+1]=fact[i]*(i+1)%MOD;
	fact_inv[t]=power(fact[t], MOD-2);
	FORR(i, 0, t) fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;
	return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}
  
int main()
{
  int R; cin >> R;

  cout << (double)R * 2 * 3.1415926535 << endl;

  return 0;
}


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

int main() {

	int n;
	string s;
	int r=0;
	cin>>n;
	cin>>s;

	for (int i=0;i<n-1;++i) {
		if (s[i]!=s[i+1]) {
			r++;
		}
	}

	if (!r) {
		cout<<1;
	} else {
		cout<<++r;
	}

	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#define F first
#define S second

using namespace std;

typedef long long ll;

ll n;
ll a, b;
ll ans;
pair<ll, ll> x[105];

bool cmp(pair<ll, ll> p, pair<ll, ll> q)
{
    return atan2((double)p.S, (double)p.F) < atan2((double)q.S, (double)q.F);
}

int main()
{
    //freopen("input.txt", "r", stdin);
    scanf("%lld", &n);
    for(ll i = 0; i < n; i++)
    {
        scanf("%lld%lld", &x[i].F, &x[i].S);
    }
    sort(x, x + n, cmp);
    for(ll j = 0; j < n; j++)
    {
        a = b = 0;
        for(ll i = 0; i < n; i++)
        {
            a += x[(i + j) % n].F;
            b += x[(i + j) % n].S;
            ans = max(ans, a * a + b * b);
        }
    }
    printf("%.15f", sqrt((double)ans));
    return 0;
}


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

using namespace std;


void solve() {
    int n; cin >> n;
    vector<pair<int, int>> a(n), b(n);
    for (int i = 0; i < n; i++) {
        int x,y;
        cin >> x >> y;
        a[i]={x,y};
    }
    for (int i = 0; i < n; i++) {
        int x,y;
        cin >> x >> y;
        b[i]={x,y};
    }
    vector<vector<int>> g(n);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (a[i].first<b[j].first && a[i].second<b[j].second)
                g[i].emplace_back(j);
        }
    }
    vector<bool> trk(n, false);
    vector<int> left(n, -1);
    function<bool(int)> dfs = [&](int l){
        if (trk[l]) return false;
        trk[l] = true;
        for (int r: g[l]) {
            if (left[r] == -1 || dfs(left[r])) {
                left[r] = l;
                return true;
            }
        }
        return false;
    };
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        fill(trk.begin(), trk.end(), false);
        if (dfs(i)) cnt++;
    }
    cout << cnt;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 256
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readM(T)(size_t r,size_t c,ref T[][]t){t=new T[][](r);foreach(ref v;t)readA(c,v);}

void main()
{
  int h, w; readV(h, w);
  int[][] c; readM(10, 10, c);
  int[][] a; readM(h, w, a);

  auto g = GraphM!()(10).init;
  foreach (i; 0..10)
    foreach (j; 0..10)
      g[i][j] = c[i][j];

  auto d = g.floydWarshal;

  auto r = 0;
  foreach (i; 0..h)
    foreach (j; 0..w)
      if (a[i][j] != -1)
        r += d[a[i][j]][1];

  writeln(r);
}

struct GraphM(W = int, W i = 10^^9)
{
  alias Wt = W, inf = i;
  int n;
  Wt[][] g;
  alias g this;
  this(int n) { this.n = n; g = new Wt[][](n, n); }
  ref auto init() { foreach (i; 0..n) { g[i][] = inf; g[i][i] = 0; } return this; }
}

template FloydWarshal(Graph)
{
  import std.algorithm, std.array, std.traits;
  alias Wt = TemplateArgsOf!Graph[0];

  Wt[][] floydWarshal(ref Graph g)
  {
    Wt[][] dist;
    int[][] inter;
    floydWarshal(g, dist, inter);
    return dist;
  }

  void floydWarshal(ref Graph g, out Wt[][] dist, out int[][] inter)
  {
    auto n = g.n, sent = n;
    dist = g.g.map!(i => i.dup).array;

    inter = new int[][](n, n);
    foreach (i; 0..n) inter[i][] = sent;

    foreach (k; 0..n)
      foreach (i; 0..n)
        foreach (j; 0..n)
          if (dist[i][j] > dist[i][k] + dist[k][j]) {
            dist[i][j] = dist[i][k] + dist[k][j];
            inter[i][j] = k;
          }
  }
}
auto floydWarshal(G)(G g) { return FloydWarshal!(typeof(g)).floydWarshal(g); }


Measured memory_bytes: 636
// header {{{
// header {{{
using namespace std;
#include <bits/stdc++.h>
 
#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

#define ASSERT(expr...) assert((expr))
 
using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
 
using f32 = float;
using f64 = double;
// }}}
 
constexpr i64 INF = 1'010'000'000'000'000'017LL;
 
constexpr i64 MOD = 1'000'000'007LL;
 
constexpr f64 EPS = 1e-12;
 
constexpr f64 PI = 3.14159265358979323846;

#define M5 100007
#define M9 1000000000

 
// util {{{
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
 
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define ll long long int
#define VI vector <int>
template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
 
template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }
 
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
 
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}
// }}}
 
// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;
 
    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}
 
//--------------------------------------------------------------------
 
bool isOK(int mid, double key){
 
    if((double)mid*mid > key) {
             return true;
     } else {
              return false;
     }
}

 int binary_search(double key) {
    int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    int right = 2000000000;
    /* どんな二分探索でもここの書き方を変えずにできる！ */
    while (right - left > 1) {
        int mid = left + (right - left) / 2;

        if (isOK(mid, key)) right = mid;
        else left = mid;
    }

    /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
    return right;
}


bool isKaibun(string st){
    bool ans = true;
    int n = st.length();
    REP(i,n/2){
        if(st[i] != st[n-i-1]){
            return false;
        }
    }
    return true;
}

int toInt(char a){
    return a-'0';
}

int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

int lcm(int a, int b)
{
   return a * b / gcd(a, b);
}

void solve() {
    string S;
    cin >> S;
    if(S[0]==S[1] || S[1] == S[2] || S[2] == S[3]){
        cout << "Bad" << endl;
    }else{
        cout << "Good" << endl;
    }

}



signed main() {
 
    solve();
 
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,a[234567],A[234567];
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		A[i]=a[i];
	}
	sort(a,a+n);
	for(int i=0;i<n;i++){
		if(A[i]!=a[(n-1)])cout<<a[(n-1)]<<endl;
		else cout<<a[(n-2)]<<endl;
	}
}


Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
int n,a,hsh1[100005],hsh2[100005],pow_2[100005],type=0;
int main()
{
	pow_2[0]=1;
	for(int i=1;i<=100000;i++)
	{
		pow_2[i]=pow_2[i-1]*2;
		pow_2[i]%=1000000007;
	}
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a);
		++hsh2[a];
		++hsh1[abs((i-1)-(n-i))];
	}
	for(int i=0;i<=100000;i++)
	{
		if(hsh1[i]!=hsh2[i])
		{
			type=-1;
		}
	}
	if(type==-1)
	{
		printf("0\n");
	}else
	{
		printf("%d\n",pow_2[n/2]);
	}
}

Measured memory_bytes: 5004
#include <iostream>
#include <cmath>
using namespace std;
int a[20][20];

int main(){
	
	//printf("%f",sqrt((1-5)^2)+((2-5)^2));
	
	int n,d;
	double EPS=1e-10;
	cin>>n>>d;
	
	for(int i=0;i<n;i++){
		for(int j=0;j<d;j++){
			cin>>a[i][j];
		}
	}
	
	int sum=0;
	
	for(int k=0;k<n;k++){
		for(int i=k+1;i<n;i++){
			double ans=0;
			for(int j=0;j<d;j++){
				ans+=(a[i][j]-a[k][j])*(a[i][j]-a[k][j]);
				//printf("%f\n",ans);
			}
			double ans1=sqrt(ans);
			//printf("%f\t%f\t%f\n",ans,ans1-floor(ans1),ans1-floor(ans1));
			if(ans1-floor(ans1)<EPS){
				sum++;
				//printf("%f\t\t%f\n",ans,ans1-floor(ans1));
			}
		}
	}
	cout<<sum<<endl;
	return 0;
}





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

int main()
{
    long long H, N,sum=0;
    cin >> H >> N;
    vector<int> a(N);
    for (int i = 0; i < N;i++){
        cin >> a.at(i);
        sum += a.at(i);
    }
    if(H>sum){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }

}


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

int main(){
  char b;
  cin >> b;
  if(b == 'A') cout << 'T' << endl;
  if(b == 'T') cout << 'A' << endl;
  if(b == 'G') cout << 'C' << endl;
  if(b == 'C') cout << 'G' << endl;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  int l[n];
  for(int i=0; i<n; i++)
    cin >> l[i];

  sort(l, l+n, greater<>());
  int sum = 0;
  for(int i=0; i<k; i++)
    sum += l[i];

  cout << sum << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		int N = Integer.parseInt(sc.next());
		int[] A = new int[N + 1];
		int[] B = new int[N];
		int idx;
		for (idx = 0; idx < N + 1; idx++) {
			A[idx] = Integer.parseInt(sc.next());
		}
		for (idx = 0; idx < N; idx++) {
			B[idx] = Integer.parseInt(sc.next());
		}

		long defeated = 0;
		// 勇者は手前から全力を尽くす
		for (idx = 0; idx < N; idx++) {
			// 手前の街
			if (A[idx] < B[idx]) {
				defeated += A[idx];
				B[idx] = B[idx] - A[idx];
				// 次の街
				if (A[idx + 1] < B[idx]) {
					defeated += A[idx + 1];
					A[idx + 1] = 0;
				} else {
					defeated += B[idx];
					A[idx + 1] = A[idx + 1] - B[idx];
				}
			} else {
				defeated += B[idx];
			}
		}

		System.out.println(defeated);
	}

}


Measured memory_bytes: 51312
#include <iostream>
using namespace std;
int main(){
    int N;
    cin >> N;
    int W[N];
    for(int i=0;i<N;i++)W[i] = 0;
    for(int i=0;i<N-1;i++){
        int A;
        cin >> A;
        W[A-1] += 1;
    }
    for(int i=0;i<N;i++){
        cout << W[i] << '\n';
    }
    return 0;
}

Measured memory_bytes: 4376