akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
using namespace std;

int Hs[100005];

int main() {
  int N,H;
  cin >> N;
  rep(i, N) {
    scanf("%d", &Hs[i]);
  }
  for(int i=1; i<N; i++) {
    Hs[i] -= (Hs[i-1] < Hs[i] ? 1 : 0);
    if(Hs[i-1] > Hs[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

string s;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> s;
  int l = 0, r = s.size() - 1;
  int ans = 0;
  while (l < r) {
    if (s[l] == 'x') {
      if (s[r] == 'x') {
        l++; r--;
      } else {
        l++; ans++;
      }
    } else {
      if (s[r] == 'x') {
        r--; ans++;
      } else {
        if (s[l] == s[r]) {
          l++; r--;
        } else {
          cout << -1 << endl;
          return 0;
        }
      }
    }
  } 
  cout << ans << endl; 

  return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#define SENTINEL (1<<30)
#define MAX_LENGTH 500001

int count = 0, A[MAX_LENGTH];
void Merge(left, mid, right){
    int n1 = mid - left;
    int n2 = right - mid;
    int L[n1], R[n2];
    for (int ix = 0; ix < n1; ix++)
        L[ix] = A[left + ix];
    for (int ix = 0; ix < n2; ix++)
        R[ix] = A[mid + ix];
    L[n1] = SENTINEL;
    R[n2] = SENTINEL;
    int i = 0, j = 0;
    for (int kx = left; kx < right; kx++){
        if ( R[j] > L[i] ){
            A[kx] = L[i];
            i++;
        }
        else {
            A[kx] = R[j];
            j++;
        }
        count++;
    }
}

void MergeSort(left, right){
    if ( left+1 < right ){
        int mid = (left + right)/2;
        MergeSort(left, mid);
        MergeSort(mid, right);
        Merge(left, mid, right);
    }
}

int main(){
    int n;
    scanf("%d\n",&n);
    for (int ix = 0; ix < n; ix++)
        scanf("%d",&A[ix]);
        
    MergeSort(0,n);
    for (int ix = 0; ix < n; ix++){
        if (ix != n-1) printf("%d ",A[ix]);
        else printf("%d\n",A[ix]);
    }
    printf("%d\n",count);
    return 0;
}


Measured memory_bytes: 5564
#include<bits/stdc++.h>
using namespace std;
string s1,s2;
int dp[3009][3009];

int lcs(int i,int j)
{
    if(i==s1.size()||j==s2.size()) return 0;
    if(dp[i][j]!=-1) return dp[i][j];
    if(s1[i]==s2[j]) return dp[i][j] = 1+lcs(i+1,j+1);
    else return dp[i][j] = max(lcs(i+1,j),lcs(i,j+1));
}

void print(int i,int j)
{
    if(i==s1.size()||j==s2.size()) return;
    if(s1[i]==s2[j])
    {
        cout<<s1[i];
        print(i+1,j+1);
    }
    else
    {
        if(dp[i+1][j]>dp[i][j+1]) print(i+1,j);
        else print(i,j+1);
    }
}


int main()
{
    memset(dp,-1,sizeof(dp));
    cin>>s1>>s2;
    lcs(0,0);
    print(0,0);
    cout<<endl;
}


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

int main(){

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

    if((a+b)%2==0){
        cout << (a+b)/2 << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
// template
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<long long, long long> LP;
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP_AB(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)), v.end());
#define SIZE(x) ((ll)(x).size())
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a / gcd(a, b)) * b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define out cout
#define in cin
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
// template end


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    in >> s;
    out << s[0] << s.size() - 2 << s[s.size()-1] << endl;
}


Measured memory_bytes: 256
// package app;

import java.util.Scanner;

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

        int N = sc.nextInt();
        int K = sc.nextInt();

        System.out.println(N % K != 0 ? 1 : 0);
    }
}

Measured memory_bytes: 21844
#include<stdio.h>
int main() {
    int a,b,c,d,e;

    scanf("%d", &a);
    b=a%10;
    e=a/10;
    c=e%10;
    d=e/10;
    if(b==7||c==7||d==7){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }

    return 0;


}

Measured memory_bytes: 1616
#include <iostream>
using namespace std;
int nrp,nri;
int P;
int N;
long long rez;
long long C[55][55];
int main()
{
    cin>>N>>P;
    for(int i=1;i<=N;i++)
    {
        int val;cin>>val;
        if(val%2==0)nrp++;
        else        nri++;
    }
    for(int i=0;i<=nri;i++)
    {
        C[i][0]=C[i][i]=1;
        for(int j=1;j<i;j++)C[i][j]=C[i-1][j-1]+C[i-1][j];
    }
    for(int k=0;2*k+P<=nri;k++)
        rez=rez+(1LL<<nrp)*C[nri][2*k+P];
    cout<<rez;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define for0(n) for(i=0; i<(n); i++)
#define for1(n) for(i=1; i<=(n); i++)
#define M 1000000007


int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll _,i,j,n,a,b,e,k,u,t,x=1,m,y,q,f=1,c=0,d=0,l,p,z,o,r,g;
    string ss,s;
    double mm,nn,xx,rr;
    cin>>nn>>mm>>xx;
    rr=nn/xx;
    cout<<(rr<=mm?"Yes":"No")<<endl;
}



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

const int N = 2e5 + 5;
typedef long long ll;

int n, cnt, first[N], ans[N], t[N<<2], sum[N], tot;
struct Edge {
	int to, next;
} e[N<<1];
struct node {
	int w, num, val;
} a[N];
map <int, int> s;

void add(int u, int v) {
	e[++cnt] = (Edge) {v, first[u]};
	first[u] = cnt;
}

void update(int o, int l, int r, int x, int k) {
	if(l == r) {
		t[o] = k;
		return;
	}
	int mid = (l + r)>>1;
	if(x <= mid) update(o<<1, l, mid, x, k);
	else update(o<<1|1, mid + 1, r, x, k);
	t[o] = max(t[o<<1], t[o<<1|1]);
}

int query(int o, int l, int r, int x, int y) {
	if(y < x) return 0;
	if(x <= l && r <= y) return t[o];
	int mid = (l + r)>>1, res = 0;
	if(x <= mid) res = max(res, query(o<<1, l, mid, x, y));
	if(mid < y) res = max(res, query(o<<1|1, mid + 1, r, x, y));
	return res;
}

bool cmp1(node a, node b) { 
	return a.val < b.val;
}

bool cmp2(node a, node b) {
	return a.num < b.num;
}

void Dfs(int u, int fa) {
	ans[u] = ans[fa];
	ans[u] = max(ans[u], query(1, 1, n, 1, s[a[u].val] - 1) + 1);
	update(1, 1, n, a[u].w, query(1, 1, n, 1, s[a[u].val] - 1) + 1);
	for(int i = first[u]; i; i = e[i].next) {
		int v = e[i].to;
		if(v == fa) continue;
		Dfs(v, u);
	}
	update(1, 1, n, a[u].w, 0);
}

int main() {
	cin>>n;
	for(int i = 1; i <= n; i++) {
		a[i].num = i;
		cin>>a[i].val;
	}
	sort(a + 1, a + n + 1, cmp1);
	for(int i = 1; i <= n; i++) {
		a[i].w = i;
		if(!s[a[i].val]) s[a[i].val] = i;
	}
	sort(a + 1, a + n + 1, cmp2);
	for(int i = 1; i < n; i++) {
		int u, v;
		cin>>u>>v;
		add(u, v);
		add(v, u);
	}
	Dfs(1, 0);
	for(int i = 1; i <= n; i++)
		cout<<ans[i]<<endl;
}

Measured memory_bytes: 37420
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <set>

int main(){
  
  long long int N, tmp;
  std::vector<long long int> H;
  
  scanf("%d", &N);
  for(int i = 0; i < N; i++){
    scanf("%d", &tmp);
    H.push_back(tmp);
  }
  
  // solve problem
  int possible_flag = 1;
  
  H[0]--;
  
  for(int i = 1; i < N; i++){
    // shift down
    if(H[i] > H[i-1]){
      H[i]--;
    }
    // unable to shift down, but there is no problem
    else if(H[i] == H[i-1]){
      continue;
    }
    // possible flag = 0
    else{ // if(H[i] < H[i-1])
      possible_flag = 0;
      break;
    }
  }
  
  if(possible_flag == 1) std::cout << "Yes" << std::endl;
  else std::cout << "No" << std::endl;
  
  return 0;
}


Measured memory_bytes: 1400
n = int(input())
A = list(map(int, input().split()))
num_minus = 0
minimum = 10 ** 6
ans = 0

for a in A:
    if a < 0:
        num_minus += 1
    minimum = min(minimum, abs(a))
    ans += abs(a)

if num_minus % 2 == 0:
    print(ans)
else:
    print(ans - minimum * 2)


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

using namespace std;

using ll = long long;

int main() {
    int N;cin >> N;
    set<pair<int, int>> e;
    for(int i = 0;i < N-1;i++){
        for(int j = i + 1;j < N;j++){
            e.insert({i + 1 , j + 1});
        }
    }
    if(N % 2 == 0){
        for(int i = 0;i < N / 2;i++){
            e.erase({i + 1, N - i});
        }
    }else{
        for(int i = 0;i < N / 2;i++){
            e.erase({i + 1, N - i - 1});
        }
    }
    cout<<e.size()<<endl;
    for(auto a : e){
        cout<<a.first<<" "<<a.second<<endl;
    }
    return 0;
}

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

using namespace std;

int func(int k) {
    return (k*(k-1))/2;
}

bool isPalindrome(string s) 
{ 
    int l = 0; 
    int h = s.length() - 1; 
    while (h > l) 
    { 
        if (s[l++] != s[h--]) 
        { 
            return 0;
        } 
    } 
   return 1;
} 


int main() {
    
   float l;
   
   cin>>l;
   
   float p;
   
   p=(l*l*l)/27;
   
   printf("%.6f", p);
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
char a[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
bool b[26] = {};
int main() {
    string s;
    cin >> s;
    int len = s.length();
    for(int i = 0; i < len; i++) {
        for(int j = 0; j < 26; j++) {
            if(s[i] == a[j]) {
                b[j] = true;
            }
        }
    }
    for(int i = 0; i < 26; i++) {
        if(!b[i]) {
            cout << a[i] << endl;
            return 0;
        }
    }
    cout << "None" << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long lli;

int main() {
  lli a, b, c;
  int re, hi;
  re = hi = 0;
  while(scanf("%lld,%lld,%lld", &a, &b, &c) != EOF) {
    if(a*a+b*b == c*c) ++re;
    if(a == b) ++hi;
  }
  cout << re << endl;
  cout << hi << endl;
  return 0;
}

Measured memory_bytes: 1208
#include <iostream>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <math.h>
//#include <vector>
#include <string>
//typedef long long LL;
using namespace std;

int main(){
    int n;
    int ans;
    string s;
    cin >> n;
    cin >> s;
    ans = n;
    for(int i=0; i<n-1; i++){
        if(s[i]==s[i+1]){
            ans--;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll a,b,c,d;cin>>a>>b>>c>>d;
    ll arr[4];
    arr[0]=a*c;
    arr[1]=a*d;
    arr[2]=b*c;
    arr[3]=b*d;
    cout<<max(arr[0],max(arr[1],max(arr[2],arr[3])))<<endl;
    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
int n;
int h[200005];
long long a[200005];
long long bit[200005],dp[200005];
inline void modify(int p,long long v){
	for(int i=p+1;i<=200003;i+=(i&-i)){
		bit[i]=max(bit[i],v);
	}
}
inline long long query(int p){
	long long res=0;
	for(int i=p;i;i-=(i&-i)){
		res=max(res,bit[i]);
	}
	return res;
}
int main(){
	cin>>n;
	for(int i=1;i<=n;++i){
		cin>>h[i];
	}
	for(int i=1;i<=n;++i){
		cin>>a[i];
	}
	for(int i=1;i<=200003;++i){
		bit[i]=-2e15;
		dp[i]=-2e15;
	}
	modify(0,0);
	dp[0]=0;
	for(int i=1;i<=n;++i){
		dp[h[i]]=max(dp[h[i]],query(h[i])+a[i]);
		modify(h[i],dp[h[i]]);
	}
	cout<<query(n+1)<<'\n';
	return 0;
}

Measured memory_bytes: 5760
use text_io::*;
use std::collections::HashMap;
use std::process::exit;

fn main() {
    let n:usize = read!();
    let m:usize = read!();
    let mut v:Vec<usize> = Vec::new();
    let mut sum:usize = 0;
    for i in 0..n {
        let a:usize = read!();
        v.push(a);
        sum += a;
    }
    v.sort();
    v.reverse();
    for i in 0..m {
        if v[i]*4*m < sum {
            println!("No");
            exit(0);
        }
    }
    println!("Yes");
}

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

using namespace std;

typedef long long ll;

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

	int a, b;
	cin >> a >> b;
	cout << (a - 1) * (b - 1) << endl;
}


Measured memory_bytes: 256
#include<iostream>//A
#include<cstdio>
using namespace std;
int main()
{
    const int maxn=1e5+10;
    int n;
    scanf("%d",&n);
    long long height[maxn];
    for(int i=0;i<n;i++) scanf("%lld",&height[i]);
    for(int i=1;i<n;i++)
    {
        if(height[i]>height[i-1])
        {
            height[i]--;
            continue;
        }
        if(height[i]<height[i-1])
        {
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define M 100005
vector<int>d[M];
int dis[3][M];
struct hh{
	int p,md,w;
	bool operator<(hh a)const{
		return w>a.w;
	}
};
priority_queue<hh>q;
int main(){
	memset(dis,127,sizeof(dis));
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1,a,b;i<=m;++i){
		scanf("%d%d",&a,&b);
		d[a].push_back(b);
	}
	int s,t;
	scanf("%d%d",&s,&t);
	dis[0][s]=0;
	q.push((hh){s,0,0});
	while(!q.empty()){
		hh st=q.top();q.pop();
		if(dis[st.md][st.p]<st.w)continue;
		for(int i=0;i<(int)d[st.p].size();++i){
			int v=d[st.p][i];
			if((st.w+(st.md==2))<dis[(st.md+1)%3][v]){
				dis[(st.md+1)%3][v]=st.w+(st.md==2);
				q.push((hh){v,(st.md+1)%3,st.w+(st.md==2)});
			}
		}
	}
	if(dis[0][t]>1e9)dis[0][t]=-1;
	printf("%d",dis[0][t]);
}

Measured memory_bytes: 7156
import scala.io.StdIn.{readInt,readLine}

object Main {

  def insert(l:List[Int],b:Int,c:Int):Boolean =
    l match {
      case Nil => true
      case hd::tl =>
        if(b<hd) insert(tl,hd,c)
        else if(c<hd) insert(tl,b,hd)
        else false
    }

  def main(args:Array[String]) =
    println {
      {
        for(i<-0 until readInt) yield if(insert(readLine.split(" ").map(_.toInt).toList,0,0)) "YES" else "NO"
      }.mkString("\n")
    }
}

Measured memory_bytes: 43784
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define nt _int128
#define mod 1000000007
int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    // cin >> t;
    t  = 1;
    while(t--)
    {
        ll n;
        cin>>n;
        ll arr[n+1]={0};
        for(ll i=1;i<=100;i++)
        {
            for(ll j=1;j<=100;j++)
            {
                for(ll k=1;k<=100;k++)
                {
                    ll z=i*i+j*j+k*k+i*j+k*j+k*i;
                    if(z<=n)
                        arr[z]++;
                }
            }
        }
        for(ll i=1;i<=n;i++)
        {
            cout<<arr[i]<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3668
W, H, x, y, r = map(int, input().split())

if x - r < 0 or x + r > W or y - r < 0 or y + r > H:
    print("No")
else:
    print("Yes")
#a = input().split()
#a_int = [int(s) for s in a]
#a_sorted = sorted(a_int)
#print(' '.join(map(str, a_sorted)))



Measured memory_bytes: 5596
#include <iostream>
#include <cstdio>
#define N 105
using namespace std;

int h, w, d[N][N];
char a[N][N];
int main()
{
	int i, j;
	cin >> h >> w;
	for (i = 1; i <= h; i++) {
		scanf("%s", &a[i][1]);
	}
	for (i = 1; i <= h; i++) d[i][0] = 1e9;
	for (i = 1; i <= w; i++) d[0][i] = 1e9;
	d[0][1] = 0;
	for (i = 1; i <= h; i++) {
		for (j = 1; j <= w; j++) {
			if (a[i][j] == '.') {
				d[i][j] = min(d[i - 1][j], d[i][j - 1]);
			} else {
				d[i][j] = 1e9;
				if (a[i - 1][j] == '#') d[i][j] = min(d[i][j], d[i - 1][j]);
				else d[i][j] = min(d[i][j], d[i - 1][j] + 1);
				if (a[i][j - 1] == '#') d[i][j] = min(d[i][j], d[i][j - 1]);
				else d[i][j] = min(d[i][j], d[i][j - 1] + 1);
			}
		}
	}
    cout << d[h][w] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

ll sum(ll num) {
  if (num <= 1) {
    return 1;
  }

  return num + sum(num - 1);
}

int fact(int n) {
  int res = 1;

  for (int i = 2; i <= n; i++) {
    res = res * i;
  }

  return res;
}

int nCr(int n, int r) { return fact(n) / (fact(r) * fact(n - r)); }

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

  int n, p;
  cin >> n >> p;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  int ecnt = count_if(all(a), [](int num) { return num % 2 == 0; });
  bool alleven = n == ecnt;
  ll ans = pow(2, n);
  if (alleven) {
    if (p) ans = 0;
  } else {
    ans = pow(2, n - 1);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
N = int(input())
H = list(map(int,input().split()))

def lower(i, H):
  cnt = 0
  while H[i] >= H[i+1]:
    cnt += 1; i += 1;
    if i+1 > N-1:
      break
  return cnt

ans, i = 0, 0
while i < N - 1:
  tmp = lower(i, H)
  ans = max(ans, tmp)
  i += tmp+1

print(ans)

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

int main() {

  bool flg = true;
  int x, y;
  
  while(flg) {
  
    cin >> x >> y;
    
    if (x == 0 && y == 0) {
    	flg = false;
    } else {
      if (x >= y) {
        cout << y << " " << x << endl; 
      } else {
        cout << x << " " << y << endl; 
      }
    }
  }

  return 0;
}


Measured memory_bytes: 3000
h, w = map(int,input().split())
pic = []

kabe_up_down = []
for i in range(w+2):
    kabe_up_down.append('.')
pic.append(kabe_up_down)

for i in range(h):
    onelist = ['.']
    inp = list(str(input()))
    for mm in range(len(inp)):
        onelist.append(inp[mm])
    onelist.append('.')
    pic.append(onelist)
    
pic.append(kabe_up_down)    


flag = 1
a = 'a'
for i in range(1,h+1):
    for j in range(1,w+1):
        here = pic[i][j]
        if here =='#' and pic[i+1][j] == '#':
            pic[i][j] = a
            pic[i+1][j] = a
        elif here =='#' and pic[i][j+1] == '#':
            pic[i][j] = a
            pic[i][j+1] = a
        elif here =='#' and pic[i-1][j] == '#':
            pic[i][j] = a
            pic[i-1][j] = a
        elif here =='#' and pic[i][j+1] == '#':
            pic[i][j] = a
            pic[i][j+1] = a    
            
for i in range(1,h+1):
    for j in range(1,w+1):
        here = pic[i][j]
        if here == '#' and pic[i+1][j] == 'a':
            pic[i][j] = a
            pic[i+1][j] = a
        elif here =='#' and pic[i][j+1] == 'a':
            pic[i][j] = a
            pic[i][j+1] = a
        elif here =='#' and pic[i-1][j] == 'a':
            pic[i][j] = a
            pic[i-1][j] = a
        elif here =='#' and pic[i][j+1] == 'a':
            pic[i][j] = a
            pic[i][j+1] = a    
        
for i in range(1,h+1):
    for j in range(1,w+1):
        here = pic[i][j]
        if here == a and pic[i+1][j] == '#':
            pic[i][j] = a
            pic[i+1][j] = a
        elif here =='a' and pic[i][j+1] == '#':
            pic[i][j] = a
            pic[i][j+1] = a
        elif here =='a' and pic[i-1][j] == '#':
            pic[i][j] = a
            pic[i-1][j] = a
        elif here =='a' and pic[i][j+1] == '#':
            pic[i][j] = a
            pic[i][j+1] = a            
            
for i in range(1,h+1):
    for j in range(1,w+1):
        if pic[i][j] == '#':
            flag = 0
            

if flag == 0:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 3192
a,b,c,d = gets.strip.split.map(&:to_i)
if a>=0 && d<0
  p a*d
elsif b<0 && c>=0
  p b*c
else
  p [b*d,a*c].max
end
=begin
    0ab a0b ab0
0cd bd  bd  bc
c0d bd  ac,bd ac
cd0 ad  ac  ac
=end

Measured memory_bytes: 14396
/************************************************
   Start coding only after you have clear idea. 
*************************************************/

#include <bits/stdc++.h>

#define x first
#define y second
#define pii pair<int,int>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
const int maxm = 2e3+23;
const int maxn = 2e5+35;
int dp[maxn][2],pre[maxn][2];
int main(){
	string s; cin >> s;
	for(int i = 1;i <= sz(s); ++i){
		if(s[i-1] == 'P'){
			if(dp[i-1][0] > dp[i-1][1]){
				pre[i][0] = 0;
			}
			else pre[i][0] = 1;
			dp[i][0] = max(dp[i-1][0],dp[i-1][1]);
		}
		else if(s[i-1] == 'D'){
			if(dp[i-1][0]+1 > dp[i-1][1]){
				pre[i][1] = 0;
			}
			else pre[i][1] = 1;
			dp[i][1] = max(dp[i-1][0]+1,dp[i-1][1])+1;
		}
		else{
			if(dp[i-1][0] > dp[i-1][1]){
				pre[i][0] = 0;
			}
			else pre[i][0] = 1;
			if(dp[i-1][0]+1 > dp[i-1][1]){
				pre[i][1] = 0;
			}
			else pre[i][1] = 1;
			dp[i][1] = max(dp[i-1][0]+1,dp[i-1][1])+1;
			dp[i][0] = max(dp[i-1][0],dp[i-1][1]);
		}
	}
	int t = dp[sz(s)][0]>dp[sz(s)][1]?0:1;
	for(int i = sz(s);i > 0; --i){
		if(t == 0) s[i-1] = 'P';
		else s[i-1] = 'D';
		t = pre[i][t];
	}
	cout << s<< endl;
    return 0;
}

Measured memory_bytes: 6880
#include<iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int* a = new int[n];
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	///////////////////////////////////////////////////////////
	int t = 0;
	while (true)
	{
		int end = n;
		int lastsort = 1;
		for (int i = 0; i < end - 1; i++)
		{
			if (a[i] > a[i + 1])
			{
				int temp = a[i];
				a[i] = a[i + 1];
				a[i + 1] = temp;
				t++;
				lastsort = i + 1;
			}
		}
		if (lastsort == 1)
			break;
		end = lastsort;

	}















	/////////////////////////////////////////////////////////////////


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

	cout << t << endl;

















	delete[] a;
	return 0;
}


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

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  string s; cin >> s;
  long long n = s.size();
  long long res = n * (n - 1) / 2 + 1;
  long long c[26]; memset(c, 0, sizeof(c));
  for (int i = 0; i < n; i++) {
    c[s[i] - 'a']++;
  }
  for (int i = 0; i < 26; i++) res -= c[i] * (c[i] - 1) / 2;
  cout << res << "\n";
  return 0;
}

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

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

    int N, M;
    cin >> N >> M;
    for (int i = 0; i < M; ++i) {
        int A;
        cin >> A;
        N -= A;
    }
    cout << ((N < 0) ? -1 : N) << endl;

    return 0;
}

Measured memory_bytes: 3652
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <cmath>

using namespace std;

long long  a,b,c,k;

void change()
{
    long long tmpa,tmpb,tmpc;
	tmpa=a;
	tmpb=b;
	tmpc=c;
	a=tmpb+tmpc;
	b=tmpa+tmpc;
	c=tmpa+tmpb;
}

int main()
{
	scanf("%lld %lld %lld %lld",&a,&b,&c,&k);
	long long ans;
	if(k%2==0) ans=a-b;
	else ans=b-a;
	
/*	while(k--)
	{
	    if(a==b && b==c) break;
		
		if((b-a) >(long long)pow(10,18)||(a-b) >(long long)pow(10,18) || c>)
		{
			printf("Unfair\n");	
			return 0;
		}
		change();
	}*/
	
	
	//cout<<a<<" "<<b<<" "<<c<<endl;
	//cout<<b-a<<" "<<a-b<<endl;
	

	
	if(ans*(-1) >(long long)pow(10,18)||ans >(long long)pow(10,18))
	{
		printf("Unfair\n");	
	}
	else printf("%lld\n",ans);
}

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

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

signed main() {
    ll N,K;
    cin>>N>>K;
    vector<ll> A(N);
    rep(i,0,N){
        cin>>A[i];
    }
    ll len = 0;
    for (ll b=1; b<=K; b*=2){
        len++;
    }
    //cout<<"len="<<len<<endl;

    ll X = 0;
    for (ll b=len-1; b>=0; b--){
        ll nZero=0, nOne=0;
        rep(i,0,N){
            if (((A[i]>>b)&1) == 1){
                nOne++;
            }else{
                nZero++;
            }
        }
        if (nZero > nOne && (X | (1LL<<b)) <= K){
            X |= 1LL << b;
        }
        //cout<<"b="<<b<<",nZero="<<nZero<<endl;
    }
    //cout<<X<<endl;
    ll ans=0;
    rep(i,0,N){
        ans += X^A[i];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn dfs(l: usize, r: usize, dp: &mut Vec<Vec<Option<usize>>>, a: &Vec<usize>, sums: &Vec<usize>) -> usize { //[l,r)
    if let Some(res) = dp[l][r] {
        return res;
    } else if l+1 == r {
        return 0;
    }
    let mut mn = std::usize::MAX;
    for i in (l+1)..r {
        mn = min!(mn, dfs(l,i,dp,a,sums)+dfs(i,r,dp,a,sums)+sums[r]-sums[l]);
    }
    dp[l][r] = Some(mn);
    mn
}

fn solve() {
    let n = get!(usize);
    let a = get!([usize]);
    let mut sums = vec![0; n+1];
    for i in 0..n {
        sums[i+1] = sums[i] + a[i];
    }
    
    let mut dp = vec![vec![None; n+1];n+1];
    println!("{}", dfs(0,n,&mut dp, &a, &sums));
}


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

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

Measured memory_bytes: 256
import java.io.*;
import java.util.StringTokenizer;

public class Main {
  private static PrintWriter out;

  public static void main(String[] args) {
    Main main = new Main();
    Runtime.getRuntime().addShutdownHook(new Thread(() -> out.close()));
    try {
      main.run(args);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  private void run(String[] arguments) throws Exception {
    MyScanner sc = new MyScanner();
    out = new PrintWriter(new BufferedOutputStream(System.out));

    double A = sc.nextDouble();
    double B = sc.nextDouble();
    double H = sc.nextDouble();
    double M = sc.nextDouble();

    double radH = (360.0 / 12.0) * H + (30.0 / 60.0) * M;
    double radM = (360.0 / 60.0) * M;

    double diff = Math.abs(radH -radM);
    double min = Math.min(diff, 360-diff);


    double AA = Math.pow(A, 2.0);
    double BB = Math.pow(B, 2.0);
    double cos = Math.cos(Math.toRadians(min));
    double ab2 = 2.0 * A * B * cos;



    double sqrtX = AA + BB - ab2;
    double ans = Math.sqrt(sqrtX);

    out.println(ans);
    out.close();
  }

  /*          
   * Form: http://codeforces.com/blog/entry/7018
   */
  private class MyScanner {
    BufferedReader br;
    StringTokenizer st;

    MyScanner() {
      br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

    int nextInt() {
      return Integer.parseInt(next());
    }

    long nextLong() {
      return Long.parseLong(next());
    }

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

    String nextLine() {
      String str = "";
      try {
        str = br.readLine();
      } catch (IOException e) {
        e.printStackTrace();
      }
      return str;
    }
  }
}


Measured memory_bytes: 34136
s[50],j,p,q;
main(i){for(;j=i=atoi(gets(s));printf("%d\n",i)){
for(;i;s[j-i--]=strlen(gets(s+j)));
for(;q>0||j&&(p=i++,q=j=117933);j/=9)for(q=j%9;q>1;)q-=s[p++];
}}

Measured memory_bytes: 532
#include<stdio.h>
int main(){
  int n,q,i,c=0;
  int l=0,r=0,m=0;
  int key,v;
  scanf("%d",&n);
  
  int S[n];
  
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  
  int T[q];
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
  }    l=0;
    r=n;

  for(i=0;i<q;i++){
    l=0;
    r=n;
    while(l<r){
      	m=(l+r)/2;
      if(S[m]>T[i]){
	r=m;
      }else if(S[m]<T[i]){
	l=m+1;
      }else if(S[m]==T[i]){
	break;
      }
    }
    if(S[m]==T[i])c++;
  }
  printf("%d\n",c);
  
  return 0;
}
    
      

  



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

namespace ABC114A
{
	class Program
	{
		static void Main(string[] args)
		{
			int x;
			x = int.Parse(Console.ReadLine());
			if (x == 7 || x == 3 || x == 5)
				Console.WriteLine("YES");
			else
				Console.WriteLine("NO");
			Console.ReadKey();
				
		
		
	
		

		}
	}
}


Measured memory_bytes: 11220
function Main( input ){
	input = input.split( '\n' )
  num = input[0].split( ' ' )
  var a = Number( num[0] )
  var b = Number( num[1] )
  if( a + b >= 10 ) console.log( 'error' )
  else console.log( a + b )
}

Main( require( 'fs' ).readFileSync( '/dev/stdin', 'utf8' ) )


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

int main() {
int d;
cin >> d;
vector<int> c(26);
rep(i,26) cin >> c.at(i);
vector<vector<int>> s(d,vector<int>(26));
rep(i,d)rep(j,26) cin >> s.at(i).at(j);

rep(i,d){
  int a = -1;
  int ans;
  rep(j,26){
    if(s.at(i).at(j) > a){
      a = s.at(i).at(j);
      ans = j;
    }
  }
  cout << ans+1 << endl;
}
 }


Measured memory_bytes: 3644
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int N;
	cin >> N;
	vector<ll> A(N+2, 0);
	vector<ll> T(N+2, 0);
	vector<ll> nax(N, INF);
	vector<bool> decided(N, false);
	REP(i,N)cin >> T[i];
	REP(i,N)cin >> A[i];
	rep(i,N){
		if(T[i+1] > T[i])decided[i] = true;
		nax[i] = T[i+1];
		nax[i] = min(nax[i], T[i+1]);
	}
	for(int i = N-1; i >= 0; --i){
		if(A[i+1] > A[i+2]){
			if((decided[i] && nax[i] != A[i+1]) || (!decided[i] && nax[i] < A[i+1])){
				cout << 0 << endl;
				return 0;
			}
			decided[i] = true;
		}
		nax[i] = min(nax[i], A[i+1]);
	}
	ll ans = 1;
	rep(i,N){
		if(decided[i] == false)ans *= nax[i];
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}


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

#define maxv 100000

using namespace std;

int n, len, in[maxv], out[maxv], up[100][maxv];
vector<int> tree[maxv];

void dfs(int u, int p, int &k){
  in[u] = k++;
  up[0][u] = p;
  for(int i = 1; i < len; i++)
    up[i][u] = up[i - 1][up[i - 1][u]];

  for(int i = 0; i < tree[u].size(); i++){
    if(tree[u][i] != p)dfs(tree[u][i],u,k);
  }
  out[u] = k++;
}

void init(int root){
  while((1 << len) <= n)len++;
  int k=0;
  dfs(root,root,k);
}

bool isParent(int parent, int child){
  return in[parent] <= in[child] && out[child] <= out[parent];
}

int lca(int a, int b){
  if(isParent(a,b))return a;
  if(isParent(b,a))return b;
  for(int i = len - 1; i >= 0; i--){
    if(!isParent(up[i][a],b))a = up[i][a];
  }
  return up[0][a];
}

int main(void){
  int k,c,q,u,v;

  cin >> n;
  for(int i=0;i<n;i++){
    cin >> k;
    for(int j=0;j<k;j++){
      cin >> c;
      tree[i].push_back(c);
    }
  }

  init(0);

  cin >> q;
  while(q--){
    cin >> u >> v;
    cout << lca(u,v) << endl;
  }
  return 0;
}

Measured memory_bytes: 21584
#include <stdio.h>

int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    int memo[10]={};
    memo[a]++;memo[b]++;memo[c]++;
    for(int i=0;i<10;i++)if(memo[i]==2)
    {
        printf("Yes\n");
        return 0;
    }
    printf("No\n");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <list>
#include <cctype>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)

locale l = locale::classic();

int main(){
    ll a[26]={0};
    while(1){
        string s;
        cin >> s;
        if(cin.eof()) break;
        rep(k,s.size()){
        rep(i,26){
            char c = 'a' + i;
            if(s[k] == c) a[i]++;
            c = 'A' + i;
            if(s[k] == c) a[i]++;
        }
        }
    }
    rep(i,26){
        char c = 'a' + i;
        cout << c << " : " << a[i] << endl;
    }
}


Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100010;


int main()
{
	int n,s[N];
	cin>>n;
	bool flag=1;
	for(int i=0;i<n;i++)
	{
		cin>>s[i];
		if(s[i]%2==0)
		{
			if(s[i]%3!=0&&s[i]%5!=0) flag=0;
		}
	}
	if(flag) puts("APPROVED");
	else puts("DENIED");
	return 0;
 } 

Measured memory_bytes: 256
def main():
    n = int(input())
    a = list()
    a.append(list(map(int, input().split())))
    a.append(list(map(int, input().split())))

    for i in range(1, n):
        a[0][i] += a[0][i-1]
    for i in range(n):
        if i:
            a[1][i] += max(a[0][i], a[1][i-1])
        else:
            a[1][i] += a[0][0]
    print(a[1][n-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<vector>
#include<stack>
#include<queue>

using namespace std;

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


		for (int i = 0; i < n - 1; i++) {
			cout << a[i] << " ";
		}
		cout << a[n - 1] << endl;
	}
}

int main()
{
	int n;
	cin >> n;
	int a[105];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n - 1; i++) {
		cout << a[i] << " ";
	}
	cout << a[n - 1] << endl;

	insertion_sort(a, n);

	return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)
using namespace std;

string str;

int main(){ 
	//IO("input.txt", "output.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> str;
	for(int i = 0; i < 3; i++)
		for(int j = i + 1; j < 3; j++)
			if(str[i] != str[j]){
				cout << "Yes\n";
				return 0;
			}
	cout << "No\n";
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <utility>
#include <algorithm>
#include <set>
#include <cmath>
#include <array>
#include <bitset>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b+1;i++)
#define Per(i,b,a) for(int i=b;i>=a;i--)
int main(){
    int K;
    cin>>K;
    vector<int> hoge={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    // sort(hoge.begin(),hoge.end());
    cout<<hoge[K-1]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<stdio.h>
using namespace std;
#define MAX 100000

int A[MAX];
int n;

int partition(int p,int r){
    int i,j,x;
    x=A[r];
    i=p-1;
    for(j=p;j<r;j++){
        if(A[j]<=x){
            i++;
            swap(A[j],A[i]);
        }
    }
    swap(A[i+1],A[r]);
    return i+1;
}

int main(){
    int i,q;
    scanf("%d",&n);
    for(i=0;i<n;i++)scanf("%d",&A[i]);
    
    q=partition(0,n-1);
    
    for(i=0;i<n;i++){
        if(i)printf(" ");
        if(i==q)printf("[");
        printf("%d",A[i]);
        if(i==q)printf("]");
    }
    
    printf("\n");
    
    return 0;
}



Measured memory_bytes: 3512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,-1,sizeof(x))
const int INF = 1000000001;

int main(){
  int a, b;
  cin >> a >> b;
  cout << a+b/2 <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<int> g[2];
int n ;
int dfs(int x,int y,int cost){
    if ( x >=2 || y >= n ) return 0 ;
    if ( x == 1 && y == n-1 ){
        cost+=g[x][y] ;
        return cost ;
    }
    int first = dfs(x,y+1,cost+g[x][y]);
    int second = dfs(x+1,y,cost+g[x][y]);
    return max(first,second) ;
}

int main(){

    cin >> n ;
    for(int i=0;i<n;i++){
        int x ;
        cin >> x ;
        g[0].push_back(x);
    }
    for(int i=0;i<n;i++){
        int x ;
        cin >> x ;
        g[1].push_back(x);
    }
    cout << dfs(0,0,0) << endl;

    return 0 ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 0X3f3f3f3f
#define M 1000000007
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define mp make_pair
#define pb push_back 
#define fi first
#define se second
#define endl "\n"
#define PI acos(-1)
#define fastcin ios_base::sync_with_stdio(false)
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<int,int> ii;
typedef complex<double> base;

// ll c[12][12];
ll a[12][12];
int n, m;

void floyd_warshall(){
    for(int k = 0; k <= 9; k++)
        for(int i = 0; i <= 9; i++)
            for(int j = 0; j <= 9; j++)
                if(a[i][j]>a[i][k]+a[k][j])
                    a[i][j]=a[i][k]+a[k][j];
}

// void dijkstra(int u){
// 	d[u] = 0;
// 	priority_queue(pair<ll,int>) pq;
// 	pq.push(mp(0,u));

// 	while(!pq.empty()){
// 		u = pq.top().se;
// 		ll dist = -pq.top().fi;
// 		pq.pop();

// 		for(int v = 0; v <= 9; v++){
// 			ll w = c[u][v];
// 			if(dist + w < d[v]){
// 				d[v] = dist+w;
// 				pq.push(mp(-d[v], v));
// 			}
// 		}
// 	}
// }

int main(void){
	scanf("%d%d", &n, &m);

	for(int i = 0; i < 10; i++){
		for(int j = 0; j < 10; j++){
			scanf("%lld", &a[i][j]);
		}
	}
	
	floyd_warshall();

	ll x;
	ll ans = 0;
	for(int i = 0; i < n*m; i++){
		scanf("%lld", &x);
		if(x != -1){
			ans += a[x][1];
		}
	}

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

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)



int main() {
	ll A, B, N;
	std::cin >> A >> B >> N;

	ll x = min(N, B - 1);
	std::cout << (A * x) / B - A * (x / B) << endl;

	return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<map>
using namespace std;
string s;
map<char,string>A;
map<string,char>B;
main()
{
	A[' ']="101";
	A['\'']="000000";
	A[',']="000011";
	A['-']="10010001";
	A['.']="010001";
	A['?']="000001";
	A['A']="100101";
	A['B']="10011010";
	A['C']="0101";
	A['D']="0001";
	A['E']="110";
	A['F']="01001";
	A['G']="10011011";
	A['H']="010000";
	A['I']="0111";
	A['J']="10011000";
	A['K']="0110";
	A['L']="00100";
	A['M']="10011001";
	A['N']="10011110";
	A['O']="00101";
	A['P']="111";
	A['Q']="10011111";
	A['R']="1000";
	A['S']="00110";
	A['T']="00111";
	A['U']="10011100";
	A['V']="10011101";
	A['W']="000010";
	A['X']="10010010";
	A['Y']="10010011";
	A['Z']="10010000";
	B["00000"]='A';
	B["00001"]='B';
	B["00010"]='C';
	B["00011"]='D';
	B["00100"]='E';
	B["00101"]='F';
	B["00110"]='G';
	B["00111"]='H';
	B["01000"]='I';
	B["01001"]='J';
	B["01010"]='K';
	B["01011"]='L';
	B["01100"]='M';
	B["01101"]='N';
	B["01110"]='O';
	B["01111"]='P';
	B["10000"]='Q';
	B["10001"]='R';
	B["10010"]='S';
	B["10011"]='T';
	B["10100"]='U';
	B["10101"]='V';
	B["10110"]='W';
	B["10111"]='X';
	B["11000"]='Y';
	B["11001"]='Z';
	B["11010"]=' ';
	B["11011"]='.';
	B["11100"]=',';
	B["11101"]='-';
	B["11110"]='\'';
	B["11111"]='?';
	while(getline(cin,s))
	{
		string t="";
		for(int i=0;i<s.size();i++)t+=A[s[i]];
		if(t.size()%5)t+=string(5-t.size()%5,'0');
		for(int i=0;i<t.size();i+=5)cout<<B[t.substr(i,5)];
		cout<<endl;
	}
}


Measured memory_bytes: 3152
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF (1LL<<60)
#define MOD1 1000000007
#define MAX_N (1 << 17)


void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{
    ll aa;
    ll bb;
}frequent;

int main(void){
    // char ;
    ll h,w,ans=0;
    scanf("%lld%lld",&h,&w);
    // ll [n];
    // rep(i,0,n){
    //     scanf("%lld",&[i]);
    // }
    if(h==1 || w==1){
        printf("1\n");
        return 0;
    } 
    if(w%2 && h%2){
        ans=h*w/2+1;
    }else{
        ans=h*w/2;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 128
// 2011/01/07 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int H, W;
		cin >> H >> W;
		if(H==0&&W==0)
			break;

		char til[101][101];
		for(int i=0; i<H; i++)
			for(int j=0; j<W; j++){
				char tmp;
				do{
					cin >> tmp;
				}while(tmp!='>'&&tmp!='<'&&tmp!='v'&&tmp!='^'&&tmp!='.');
				til[i][j] = tmp;
			}

		bool flg[101][101];
		for(int i=0; i<H; i++)
			for(int j=0; j<W; j++)
				flg[i][j] = false;

		int x = 0;
		int y = 0;
		while(true){
			if(flg[y][x]){
				cout << "LOOP" << endl;
				break;
			}

			flg[y][x] = true;

			if(til[y][x]=='>')
				x++;
			else if(til[y][x]=='<')
				x--;
			else if(til[y][x]=='v')
				y++;
			else if(til[y][x]=='^')
				y--;
			else{
				cout << x << ' ' << y << endl;
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dup(x,y) (((x)+(y)-1)/(y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e15;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int main() {
	int n;
	cin >> n;
	vector<ll> v(n);
	rep(i,n) cin >> v[i];
	rep(i,n) {
		if (v[i] == 0) {
			cout << 0 << endl;
			return 0;
		}
	}
	ll t = v[0];
	rep(i,n-1) {
		if (v[i+1] > 1000000000000000000 / t) {
			cout << -1 << endl;
			return 0;
		}
		t *= v[i+1];
	}
	cout << t << endl;
}

Measured memory_bytes: 4052
def read_list(t): return [t(x) for x in input().split()]
def read_line(t): return t(input())
def read_lines(t, N): return [t(input()) for _ in range(N)]

def rec(state, v):
    if dp[state][v] >= 0:
        return dp[state][v]
    if (1 << V) - 1 == state and v == 0:
        dp[state][0] = 0
        return 0

    ret = INF
    for to in range(V):
        if not (state >> to & 1):
            ret = min(ret, rec(state | 1 << to, to) + mat[v][to])
    dp[state][v] = ret
    return ret

INF = 1<<27
V, E = read_list(int)
#edge = [[] for _ in range(V)]
mat = [[INF] * V for _ in range(V)]
for _ in range(E):
    fr, to, cost = map(int, input().split())
    mat[fr][to] = cost
#    edge[fr].append((to, cost))


dp = [[-1] * V for _ in range(1<<V)]
print(dp[0][0] if rec(0, 0) != INF else -1)

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

using namespace std;

int main() {
	int n; long long int sum = 0; bool b = false;
	cin >> n;
	vector<long long int>num(n);

	for (int i = 0; i < n; i++) {
		long long int a;
		cin >> a;
		num[i] = a;
	}
	
	for (int i = 0; i < n-1; i++) {
		if (num[i] < 0) {
			num[i] = num[i] * -1;
			num[i + 1] = num[i + 1] * -1;
		}
	}

	if (num[n - 1] < 0) {
		b = true;
	}

	for (int i = 0; i < n; i++) {
		num[i] = abs(num[i]);
	}

	sort(num.begin(), num.end());

	if (b) {
		for (int i = 1; i < n; i++) {
			sum = sum + num[i];
		}
		cout << sum - num[0];

	}
	else {
		for (int i = 0; i < n; i++) {
			sum = sum + num[i];
		}
		cout << sum;
	}
	
	
	


}

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

count = [1]*n

for i in range(k):
  m = int(input())
  lst = list(map(int, input().split()))
  for j in range(m):
    if count[lst[j]-1] == 1:
      count[lst[j]-1] = 0

print(sum(count))

Measured memory_bytes: 9072
#include <bits/stdc++.h>
using namespace std;
int main(){
int K;
cin >> K;
int ans = 0;
for (int i=1; i<=K; i++){
  for (int j=1; j<=K; j++){
    for (int k=1; k<=K; k++){
      ans += gcd(i, gcd(j, k));
    }
  }
}
cout << ans;
}

Measured memory_bytes: 3636