akhauriyash/Code-Regression huggingface dataset:
//coding on smartphone
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
using namespace std;
#define inRange(x,a,b) (a <= x && x < b)

int di[2][4] = {{0, 0, 1, -1}, {0, 0, 1, -1}};
int dj[2][4] = {{1, -1, 0, 0}, {-1, 1, 0, 0}};

struct data{
    int li, lj, ri, rj;
};

int main(){
    int w, h;
    char c;
    while(cin >> w >> h, w+h){
        bool dp[h][w][h][w];
        int li, lj, ri, rj;
        memset(dp, 0, sizeof(dp));
        char mat[2][h][w];
        for(int i = 0; i < h; i++){
            for(int k = 0; k < 2; k++){
                for(int j = 0; j < w; j++){
                    cin >> mat[k][i][j];
                    if(mat[k][i][j]=='L')   li = i, lj = j;
                    if(mat[k][i][j]=='R')   ri = i, rj = j;
                }
                //if(k == 0) cin >> c;   // space
            }
        }
        bool valid = false;
        queue<data> q;
        q.push(data({li,lj,ri,rj}));
        dp[li][lj][ri][rj] = true;
        while(!q.empty()){
            data d = q.front(); q.pop();
            for(int k = 0; k < 4; k++){
                int nli = d.li+di[0][k], nlj = d.lj+dj[0][k];
                int nri = d.ri+di[1][k], nrj = d.rj+dj[1][k];
                if(!inRange(nli,0,h)||!inRange(nlj,0,w)||mat[0][nli][nlj]=='#') nli = d.li, nlj = d.lj;
                if(!inRange(nri,0,h)||!inRange(nrj,0,w)||mat[1][nri][nrj]=='#') nri = d.ri, nrj = d.rj;
                int target = (mat[0][nli][nlj]=='%') + (mat[1][nri][nrj]=='%');
                if(target == 2){
                    valid = true;
                    break;
                }
                if(target == 0 && !dp[nli][nlj][nri][nrj]){
                    dp[nli][nlj][nri][nrj] = true;
                    q.push(data({nli,nlj,nri,nrj}));
                }
            }
            if(valid)   break;
        }
        cout << (valid ? "Yes" : "No") << endl;
    }
    return 0;
}


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

int main()
{   
    string s;
    cin>>s;
    int ans=999;
    int n=s.size();
    for(int i=0;i+2<n;i++){
        string t=s.substr(i,3);
        int k=atoi(t.c_str());
        ans=min(ans,abs(k-753));
    } 

    cout<<ans<<endl;
}

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

int main() {
  int r,D;
  cin >>r >>D; 
  vector<int> vec(11);
  cin >> vec.at(0);
  int k;
  for(int i = 1; i< 10; i++){
    k = vec.at(i-1)*r ;
    vec.at(i) = k-D;
    cout << vec.at(i)<<endl;
  }
   vec.at(10) = vec.at(9)*r-D;
  cout << vec.at(10);
  

}


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int X, A, B;
	cin >> X >> A >> B;

	if (B - A <= 0)
	{
		cout << "delicious" << endl;
	}
	else if (B - A <= X)
	{
		cout << "safe" << endl;
	}
	else
	{
		cout << "dangerous" << endl;
	}

	return 0;
}

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

int main(){
 	 int n, alice=0, bob=0, last=0;
 	 cin >> n;
 	 vector<int> data;
 	 rep(i,n){
 	 	int tmp;
 	 	cin >> tmp;
 	 	data.push_back(tmp);
 	 	rep(j,last){
 	 		if(data[last] > data[j]){
 	 			swap(data[last], data[j]);
 	 		}
 	 	}
 	 	last++;
 	 }
 	 rep(i,n){
 	 	alice = (i%2==0) ? alice+data[i]:alice;
 	 	bob = (i%2==1) ? bob+data[i]:bob; 
 	 }
 	 cout << alice - bob;
}

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

#define ll             long long
#define sf             scanf
#define pf             printf
#define nl             printf("\n")
#define TEST           int Test;cin>>Test;for(int _t=1;_t<=Test;_t++)

using namespace std;

ll dp[3003][3003][5], grid[3003][3003], val;
int r,c,k,x,y;

ll solve(int i, int j, int pick){
	if(i>r or j>c) return 0;
	//if(grid[i][j] == -1) return 0;
	
	if(dp[i][j][pick] == -1){
		ll right = 0LL, down = 0LL, cost = 0LL;
		if(pick>0){
			if(grid[i][j]!=-1) cost = grid[i][j]; 
			right = cost + solve(i,j+1,pick-1);
			down = cost;
		}
		right = max(right, solve(i,j+1,pick));
		down += solve(i+1,j,3);
		dp[i][j][pick] = max(right, down);
	}
	return dp[i][j][pick];
}
	

int main()
{
	sf("%d %d %d",&r,&c,&k);
	for(int i=0; i<=r; i++){
		for(int j=0; j<=c; j++){
			grid[i][j] = -1;
			for(int l=0; l<5; l++){
				dp[i][j][l] = -1;
			}
		}
	}
	for(int i=0; i<k; i++){
		sf("%d %d %lld",&x,&y,&val);
		grid[x][y] = val;
	}
	ll ans = 0LL;
	//if(grid[1][1]!=-1) 
	ans = solve(1,1,3);
	pf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 426456
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>

#define pb push_back
#define mp make_pair

using namespace std;

template<typename T>inline void upmin(T &x,T y) { y<x?x=y:0; }
template<typename T>inline void upmax(T &x,T y) { x<y?x=y:0; }

typedef unsigned int u32;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod pi=acos(-1);
const int oo=1<<30;
const LL OO=1e18;

int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}

int f[110],g[110];

int main()
{
	int n=gi(),i;
	for (i=1;i<=n;i++) f[i]=gi()+f[i-1];
	for (i=1;i<=n;i++) g[i]=max(g[i-1],f[i])+gi();
	cout<<g[n]<<endl;
	return 0;
}


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

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    VPL ab(n);
    REP(i, n) cin >> ab[i].first >> ab[i].second;
    sort(ALL(ab));
    ll ans = 0;
    REP(i, n) {
        if(ab[i].second <= m) {
            ans += ab[i].first * ab[i].second;
            m -= ab[i].second;
        } else {
            ans += ab[i].first * m;
            break;
        }
    }
    cout << ans << ln;
    return 0;
}


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


int main(){
    int n;
    int dp[31] = {0};
    dp[0] = 1;
    dp[1] = 1;
    dp[2] = 2;
    for (int i = 3; i < 31; i++)
    {
        dp[i] = dp[i-1] + dp[i-2] + dp[i-3];
    }
    
    while(true){
        cin >> n;
        if(n == 0) break;
        int day = (dp[n]-1)/10 + 1;
        int year = (day-1)/365 + 1;
        cout << year << endl;
    }
    return 0;
}


Measured memory_bytes: 3088
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<functional>
#include<map>
using namespace std;
int main()
{
	int a, b;
	cin >> a >> b;
	cout<< (100*(a-b)+1900*b)*pow((double)2,(double)b)<<endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
N = int(input())
f_list = []
p_list = []

for i in range(N):
    f = input()
    f_list.append(f)
for i in range(N):
    p = list(map(int, input().split()))
    p_list.append(p)

profit = []
for i in range(1, 2**10):
    sum = 0
    for f, p in zip(f_list, p_list):
        f = int(f.replace(" ", ""), 2)
        c = bin(f & i).count("1")
        sum += p[c]
    profit.append(sum)
print(max(profit))


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

using namespace std;

string s, t;

vector<vector<int>> memo;
vector<vector<pair<int,int>>> paths;

int lcs(int i, int j) {
    if(i >= s.size() || j >= t.size())
        return 0;
    int result = 0;

    if(memo[i][j] != -1)
        return memo[i][j];

    if(s[i] == t[j]){
        memo[i][j] = 1 + lcs( i + 1, j + 1);
        paths[i][j] = { 1, 1};
        return memo[i][j];
    }

    int left = lcs(i + 1, j);
    int right = lcs(i, j + 1);

    if(left >= right) {
        paths[i][j] = { 1, 0};
    }else {
        paths[i][j] = { 0, 1};
    }

    memo[i][j] = max( left, right);
    return memo[i][j];
}

string reconstructString() {
    string result = "";
    int i = 0, j = 0;
    while( i < s.size() && j < t.size()) {
        if(s[i] == t[j])
            result += s[i];
        pair<int,int> current = paths[i][j];
        i += current.first;
        j += current.second;
    }
    return result;
}

int main() {

    cin >> s >> t;

    memo = vector<vector<int>>( s.size(), vector<int>(t.size(), -1));
    paths = vector<vector<pair<int,int>>>( s.size(), vector<pair<int,int>>(t.size(), {-1, -1}));

    int max_length = lcs( 0, 0);
/*
    cout << max_length << endl;

    for(int i = 0; i < s.size(); i++) {
        for(int j = 0; j < t.size(); j++) {
            cout << "( " << paths[i][j].first << " " << paths[i][j].second << " )";
        }
        cout << endl;
    }
*/
    cout << reconstructString() << endl;

    return 0;
}

Measured memory_bytes: 106368
using System;
using System.Linq;

class Program {
  static void Main() {
    var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
    int n = a[0];
    int k = a[1];
    int cnt = 0;
    while (n > 0) {
      for (int i = 1; i <= n; i++) {
        if ((double)(n - i) / i <= k) {
          n -= i;
          cnt++;
          break;
        }
      }
    }
    Console.WriteLine(cnt);
  }
}


Measured memory_bytes: 18436
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

const MAX = 25
const NIL = -1

var N [MAX]Node
var D [MAX]int
var H [MAX]int

var sc = bufio.NewScanner(os.Stdin)

type Node struct {
	parent int
	left   int
	right  int
}

func (n *Node) degree() int {
	if n.left != NIL && n.right != NIL {
		return 2
	}
	if n.left != NIL || n.right != NIL {
		return 1
	}
	return 0
}

func (n *Node) kind() string {
	if n.parent == NIL {
		return "root"
	} else if n.left == NIL && n.right == NIL {
		return "leaf"
	} else {
		return "internal node"
	}
}

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func init() {
	sc.Split(bufio.ScanWords)
}

func print(w io.Writer, i int) {
	fmt.Fprint(w, "node ", i, ": ")
	fmt.Fprint(w, "parent = ", N[i].parent, ", ")
	fmt.Fprint(w, "sibling = ", findSibling(i), ", ")
	fmt.Fprint(w, "degree = ", N[i].degree(), ", ")
	fmt.Fprint(w, "depth = ", D[i], ", ")
	fmt.Fprint(w, "height = ", H[i], ", ")
	fmt.Fprint(w, N[i].kind())
	fmt.Fprintln(w)
}

func findSibling(id int) int {
	n := N[id]
	if n.parent == NIL {
		return NIL
	}

	p := N[n.parent]
	if p.left == NIL || p.right == NIL {
		return NIL
	}

	if p.left == id {
		return p.right
	} else {
		return p.left
	}
}

func findRoot(id int) int {
	for N[id].parent != NIL {
		id = N[id].parent
	}
	return id
}

func findLeaf() []int {
	res := make([]int, 0)
	for i, n := range N {
		if n.left == NIL && n.right == NIL {
			res = append(res, i)
		}
	}
	return res
}

func setDepth(id, depth int) {
	if id == NIL {
		return
	}
	D[id] = depth
	setDepth(N[id].left, depth+1)
	setDepth(N[id].right, depth+1)
}

func setHeight(id, height int) {
	if id == NIL {
		return
	}

	H[id] = max(H[id], height)
	setHeight(N[id].parent, height+1)
}

func main() {
	n := scanInt()
	for i := 0; i < n; i++ {
		N[i].parent = NIL
		N[i].left = NIL
		N[i].right = NIL
	}

	for i := 0; i < n; i++ {
		id, left, right := scanInt(), scanInt(), scanInt()
		N[id].left = left
		N[id].right = right

		if left != NIL {
			N[left].parent = id
		}
		if right != NIL {
			N[right].parent = id
		}
	}

	root := findRoot(0)
	setDepth(root, 0)

	for _, leaf := range findLeaf() {
		setHeight(leaf, 0)
	}

	wtr := bufio.NewWriter(os.Stdout)
	for i := 0; i < n; i++ {
		print(wtr, i)
	}
	wtr.Flush()
}



Measured memory_bytes: 1140
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

const ll INF = 1LL << 60;

int n,m;
bool seen[8] = {false};

int dfs(int v, int cnt, vvi &G){
  if(cnt == n-1) return 1;

  seen[v] = true;
  int ret = 0;
  for(int nv : G[v]){
    if(seen[nv]) continue;
    ret += dfs(nv, cnt+1, G);
  }
  seen[v] = false;

  return ret;
}

int main(){
  cin >> n >> m;
  vvi G(n);
  rep(i, m){
    int a,b; cin >> a >> b;
    a--; b--;
    G[a].pb(b); G[b].pb(a);
  }

  std::cout << dfs(0, 0, G) << '\n';
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		loop: while (true) {
			w = scanner.nextInt();
			h = scanner.nextInt();
			if ((w | h) == 0)
				break;
			count = 0;
			visited = new boolean[h][w];
			sx = -1;
			sy = -1;
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					int now = scanner.nextInt();
					if (now == 0) {
						count++;
						if (sx == -1) {
							sy = i;
							sx = j;
						}
					} else {
						visited[i][j] = true;
					}
				}
			}
			if (count % 2 == 1) {
				System.out.println("No");
				continue;
			}
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					if (visited[i][j])
						continue;
					int count = 0;
					for (int k = 0; k < 4; k++) {
						int x = j + vx[k];
						int y = i + vy[k];
						if (!isOK(x, y))
							continue;
						if (!visited[y][x])
							count++;
					}
					if (count < 2) {
						System.out.println("No");
						continue loop;
					}
				}
			}

			System.out.println(dfs(sx, sy, 0) ? "Yes" : "No");
		}

	}

	private boolean dfs(int x, int y, int deep) {
		if (count - deep < Math.abs(x - sx) + Math.abs(y - sy))
			return false;

		for (int i = 0; i < 4; i++) {
			int nx = x + vx[i];
			int ny = y + vy[i];
			if (!isOK(nx, ny))
				continue;
			if (ny == sy && nx == sx && deep + 1 == count)
				return true;
			if (visited[ny][nx])
				continue;
			boolean res = check(nx, ny);
			if (!res)
				continue;
			visited[ny][nx] = true;
			if (dfs(nx, ny, deep + 1))
				return true;
			visited[ny][nx] = false;
		}
		return false;

	}

	private boolean check(int x, int y) {
		loop: for (int i = 4; i < vx.length; i++) {
			int nx = x + vx[i];
			int ny = y + vy[i];
			if (!isOK(nx, ny))
				continue;
			if (nx == sx && ny == sy)
				continue;
			if (visited[ny][nx])
				continue;
			int count = 0;
			for (int j = 0; j < 4; j++) {
				int nnx = nx + vx[j];
				int nny = ny + vy[j];
				if (!isOK(nnx, nny))
					continue;
				if (visited[nny][nnx])
					continue;
				count++;
				if (count == 2)
					continue loop;
			}
			return false;
		}
		return true;
	}

	private boolean isOK(int x, int y) {
		if (0 <= x && x < w && 0 <= y && y < h)
			return true;
		return false;
	}

	boolean[][] visited;
	boolean ans;
	int count, w, h, sx, sy;
	int[] vx = { 0, 1, 0, -1, 1, 1, -1, -1 };
	int[] vy = { -1, 0, 1, 0, -1, 1, 1, -1 };
}

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

#define ll          long long
#define pb          push_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
void solve(){
    ll n,m;
    cin>>n>>m;
    char arr[n][m];
    vector<pii> temp;
    rep(i,0,n-1){
        rep(j,0,m-1){
            cin>>arr[i][j];
            if(arr[i][j]=='.') temp.pb({i,j});
        } 
    }
    ll ans=0;
    rep(i,0,sz(temp)-1){
        // rep(j,i+1,sz(temp)-1){
            pii start=temp[i];
            // pii end=temp[j];
            ll dp[n][m];
            ll vis[n][m];
            memset(dp,0,sizeof(dp));
            memset(vis,0,sizeof(vis));
            dp[start.F][start.S]=0;
            // vis[start.F][start.S]=1;
            queue <pii> q;
            q.push(start);
            // ll tp=0;
            vis[start.F][start.S]=1;
            while(!q.empty()){
                pii curr=q.front();
                q.pop();
                if(curr.F!=0 && !vis[curr.F-1][curr.S] && arr[curr.F-1][curr.S]=='.'){
                    q.push({curr.F-1,curr.S});
                    vis[curr.F-1][curr.S]=1;
                    dp[curr.F-1][curr.S]=dp[curr.F][curr.S]+1;
                }
                if(curr.S!=m-1 && !vis[curr.F][curr.S+1] && arr[curr.F][curr.S+1]=='.'){
                    q.push({curr.F,curr.S+1});
                    vis[curr.F][curr.S+1]=1;
                    dp[curr.F][curr.S+1]=dp[curr.F][curr.S]+1;
                }
                if(curr.F!=n-1 && !vis[curr.F+1][curr.S]&& arr[curr.F+1][curr.S]=='.'){
                    q.push({curr.F+1,curr.S});
                    vis[curr.F+1][curr.S]=1;
                    dp[curr.F+1][curr.S]=dp[curr.F][curr.S]+1;
                }
                if(curr.S!=0 && !vis[curr.F][curr.S-1] && arr[curr.F][curr.S-1]=='.'){
                    q.push({curr.F,curr.S-1});
                    vis[curr.F][curr.S-1]=1;
                    dp[curr.F][curr.S-1]=dp[curr.F][curr.S]+1;
                }
                // tp++;
            }
            // cout<<start.F<<" "<<start.S<<endl;
            rep(j,0,n-1) rep(k,0,m-1) if(arr[j][k]=='.')ans=max(ans,dp[j][k]);
            // cout<<ans<<endl;
            // cout<<start.F<<" "<<start.S<<" "<<end.F<<" "<<end.S<<" "<<dp[end.F][end.S]<<endl;
            // ans=max(ans,dp[end.F][end.S]);
        // }
    }
    cout<<ans;
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

const int MAX_N = 200000;

template <typename T>
class BIT{
	private:
		vector<T> bit; //[1, n]
	public:
		BIT(){
			bit = vector<T>(MAX_N + 1, 0);
		}
		T sum(int i, long long m){
			if(i == 0) return 0;
			assert(1 <= i and i <= MAX_N and "invalid argument");
			T s = 0;
			while(i > 0){
				(s += bit[i]) %= m;
				i -= i & -i;
			}
			return s;
		}

		void add(int i, int x, long long m){
			assert(1 <= i and i <= MAX_N and "invalid argument");
			while(i <= MAX_N){
				(bit[i] += x) %= m;
				//bit[i] = max(bit[i], x);
				i += i & - i;
			}
		}
};

int main(){
	long long a, b, m;
	while(cin >> a >> b >> m, a||b||m){
		vector<pair<string, int>> p;
		range(i,a,b + 1){
			p.emplace_back(to_string(i), i - a);
		}
		sort(all(p));

		vector<int> ma(p.size());
		rep(i,p.size()){
			ma[ p[i].second ] = i;
		}

		//cout << ma << endl;

		BIT<long long> bit;
		long long ans = 0;
		for(int i = b; i >= a; i--){
			long long t = (bit.sum(MAX_N, m) - bit.sum( ma[i - a] , m) + m) % m + 1;
			t %= m;
			(ans += t) %= m;
			bit.add(ma[i - a] + 1, t, m);
		}
		cout << ans << endl;
	}
}



Measured memory_bytes: 11480
#include <iostream>
#include <cstdio>
int main()
{
    int n,m,ans=1e9,x,y;
    std::cin>>n>>m;

    for(int i=1;i<=n;i++)
    {
        std::cin>>x>>y;
        if(y>m)continue;
        ans=std::min(ans,x);
    }

    if(ans==1e9)
    {
        puts("TLE");
    }
    else std::cout<<ans<<std::endl;

}

Measured memory_bytes: 256
// Gaurav Nuti
 
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii > vii;
typedef vector<pll > vll;
#define pb push_back
#define mp make_pair 
#define ar array
#define mod 1000000007
#define F first
#define S second
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define For(i, a, b) for(__typeof (a) i=a; i<=b; i++)
#define inp_arr(a,n) for(__typeof (n) i=0; i<n; ++i) {cin>>a[i];}
#define debug_arr(a,n) {{for(__typeof (n) i=0; i<n; ++i) {cout<<a[i]<<" ";}cout<<"\n";}}
#define INF 1e9 

ll power(ll x, ll y) 
{ 
    ll res = 1;   
    while (y > 0) { 
        if (y & 1) 
            res = (res*x)%mod; 
        y = y>>1;
        x = (x*x)%mod; 
    } 
    return res%mod; 
}

ll power_without_mod(ll x, ll y) 
{ 
    ll res = 1;   
    while (y > 0) { 
        if (y & 1) 
            res = (res*x); 
        y = y>>1;
        x = (x*x); 
    } 
    return res; 
}

bool comparep(pair<ll, ll> i1, pair<ll, ll> i2){
	return (i1.S < i2.S);
} 

ll modInverse(ll a)
{
    return power(a , mod - 2);
}

vector<vector<ll>> graph;
vector<bool> visited;
vector<ll> dist;
map<ll,ll> mymap;
ll max_dist = 1;

void bfs(int u1){
    visited[u1] = 1;
    dist[u1] = 1;
    mymap[1] = u1;
    queue<ll> q;
    q.push({u1});
    while(!q.empty()){
        ll u = q.front();
        q.pop();
        for(auto i=graph[u].begin();i!=graph[u].end();i++){
            if(!visited[*i]){
                dist[*i] = dist[u] + 1;
                visited[*i] = 1;
                max_dist = max(dist[*i],max_dist);
                mymap[dist[*i]] = *i;
                q.push({*i});
            }
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout); 
    #endif  
	
    ll t;
    // cin>>t;
    t = 1;
    for(ll z=0;z<t;z++){
        ll n;
        cin>>n; 
        int flag = 0;
        while(n > 0){
            int digit = n%10;
            if(digit == 7)
                flag = 1;
            n /= 10;
        }
        if(flag == 1)
            cout<<"Yes";
        else
            cout<<"No";
    }
}

Measured memory_bytes: 3628
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define INF 1000000007

typedef pair<int, int> pint;
typedef long long ll;

int main()
{
    string S;
    cin >> S;
    int ans[2] = {0, 0};

    for (int i = 0; i < S.size(); i++)
    {
        if (i % 2 == 0 && S[i] == '0')
        {
            ans[0]++;
        }
        if (i % 2 == 0 && S[i] == '1')
        {
            ans[1]++;
        }
        if (i % 2 == 1 && S[i] == '1')
        {
            ans[0]++;
        }
        if (i % 2 == 1 && S[i] == '0')
        {
            ans[1]++;
        }
    }

    cout << min(ans[0], ans[1]) << endl;
}

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

bool possible(int H, int W, array<int, 26> counts)
{
    array<int, 5> needed{};
    needed[4] = (H/2) * (W/2);
    needed[2] = (H/2)*(W%2) + (W/2)*(H%2);
    needed[1] = (H%2) * (W%2);

    array<int, 5> available{};
    for (const int x : {4, 2, 1})
    {
        for (int& c : counts)
        {
            available[x] += c/x;
            c %= x;
        }
    }

    for (const int x : {4, 2, 1})
    {
        if (available[x] < needed[x])
            return false;

        available[x] -= needed[x];
        available[x/2] += 2*available[x];
    }
    return true;
}

int main()
{
    int H, W;
    cin >> H >> W;

    array<int, 26> counts{};
    for (int h = 0; h < H; h++)
        for (int w = 0; w < W; w++)
        {
            char c;
            cin >> c;
            counts[c-'a']++;
        }

    cout << (possible(H, W, counts) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <string.h>
#include <iomanip>
using namespace std;

int N,M,s,t,Q;
vector<vector<int>> v(110),rv(110),nv(110);
vector<int> rs;
int visited[110] = {},cmp[110] = {},in_cnt[110] = {};
double p[110] = {},p_cmp[110] = {},dp[110] = {};

void dfs(int n){
    visited[n] = 1;
    for(auto x:v[n]) if(!visited[x]) dfs(x);
    rs.push_back(n);
}

void rdfs(int n,int cnt){
    visited[n] = 1;
    cmp[n] = cnt;
    for(auto x:rv[n]) if(!visited[x]) rdfs(x,cnt);
}

int scc(){
    memset(visited,0,sizeof(visited));
    for(int i=1;i<=N;i++) if(!visited[i]) dfs(i);
    memset(visited,0,sizeof(visited));
    int now = 1;
    for(int i=rs.size()-1;i>=0;i--) if(!visited[rs[i]]) rdfs(rs[i],now++);
    for(int i=1;i<=N;i++){
        for(auto x:v[i]){
            if(cmp[i]!=cmp[x]){
                nv[cmp[i]].push_back(cmp[x]);
                in_cnt[cmp[x]]++;
            }
        }
    }
    return now-1;
}

int main(){
    while(cin >> N && N>0){
        for(int i=1;i<=N;i++){v[i].clear(); rv[i].clear(); nv[i].clear();}
        rs.clear();
        for(int i=1;i<=N;i++){
            p_cmp[i] = 1;
            dp[i] = 1;
            visited[i] = 0;
            cmp[i] = 0;
            in_cnt[i] = 0;
        }
        int m,a;
        for(int i=1;i<=N;i++){
            cin >> p[i] >> m;
            p[i] = 1-p[i];
            for(int j=0;j<m;j++){
                cin >> a;
                v[i].push_back(a);
                rv[a].push_back(i);
            }
        }
        int cmp_size = scc();
        for(int i=1;i<=N;i++){
            p_cmp[cmp[i]] *= 1-p[i];
        }
        queue<int> Q;
        for(int i=1;i<=cmp_size;i++){
            p_cmp[i] = 1-p_cmp[i];
/*            if(in_cnt[i]==0){
                Q.push(i);
                dp[i] = p_cmp[i];
            }
*/        }
/*        while(!Q.empty()){
            int n = Q.front(); Q.pop();
            for(auto x:nv[n]){
                in_cnt[x]--;
                dp[x] = dp[x]*dp[n];
                if(in_cnt[x]==0) Q.push(x);
            }
        }
*/        double ans = 1;
        for(int i=1;i<=cmp_size;i++) if(in_cnt[i]==0) ans *= p_cmp[i];
        cout << fixed;
        cout << setprecision(10) << ans << endl;
    }
}


Measured memory_bytes: 3344
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<sstream>
#include<algorithm>
#include<stack>
#include<bitset>
#include<map>
#include<set>
#define rep(i,n) for(int i=0;(i)<(n);i++)
#define rep1(i,n) for(int i=1;(i)<=(n);i++)
#define mst(a,b) memset(a,b,sizeof(a))
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define dbg(a) cout<<"* "<< #a <<" : "<<a<<endl
#define fr first
#define se second
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ls x<<1
#define rs x<<1|1
#define lowbit(x) x&(-x)
#define ac cout<<ans<<endl
//#define DEBUG 0
using namespace std;
const double pi=acos(-1.0);
const double eps=1e-6;
const ull hashp=1e7+19;
const ll INF=0x3f3f3f3f3f3f3f3fll;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
const int maxn=2e5+100;

void solve()
{
	int k,x;
	scdd(k,x);
	if(k*500>=x)printf("Yes");
	else printf("No");
}
int main(){
    //IOS;
    solve();
    return 0;
}

Measured memory_bytes: 256
from collections import deque
h,w = map(int,input().split())
grid = [list(input()) for _ in range(h)]
nxt = deque()
for i in range(h):
		for j in range(w):
			if grid[i][j] == "#":
				nxt.append((i,j,0))
a=0
while nxt:
	i,j,t = nxt.popleft()
	if t > a:
		a+=1
	for i,j in ((i-1,j),(i+1,j),(i,j-1),(i,j+1)):
		if (-1<i<h)&(-1<j<w) and grid[i][j] == ".":
				grid[i][j] = "#"
				nxt.append((i,j,t+1))
print(a)

Measured memory_bytes: 161756
#include<bits/stdc++.h>
#define prArr(Arr,n) for(int _=0;_<n;_++)   cout<<(Arr)[_]<<" ";
#define f first
#define s second
using namespace std;
const int INF=(int)0x3f3f3f3f;
const int MOD=(int)1e9+7;
const double eps=1e-9;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,l,mn=INF,sum=0;
    cin>>n>>l;
    for(int i=1;i<=n;i++)
        sum+=l+i-1;
    for(int i=l;i<=l+n-1;i++)
        if(abs(i)<abs(mn))
            mn=i;
    cout<<sum-mn;
    return 0;
}



Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
  int x,y;
  scanf("%d%d",&x,&y);
  if ((y%2==0) && (y>=2*x && y<=4*x))
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}

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

using namespace std;

int main(){
    int ans, k, i, j, t;

    cin >> i >> k >> j;

    ans = 0;
    if (k > i){
        if (k > j && j > i) ans = 1;
    }
    else{
        if (i > j && j > k) ans = 1;
    }

    if (ans) cout << "Yes\n";
    else cout << "No\n";
}

   

Measured memory_bytes: 256
/*huzaifa242 copyright*/
#include <bits/stdc++.h>
using namespace std;
#define PI 3.1415926535897932384626
#define mod 1000000007
#define MAX 100005
long long int n,dp[MAX],cc[MAX][2];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);  
    #endif
    long long int i,j,ans=0,w,v,u;
    cin>>n>>w;
    for(i=0;i<MAX;i++)
    dp[i]=mod;
    for(i=0;i<n;i++)
    {
        cin>>u>>v;
        for(j=MAX-1;j>=0;j--)
        {
        	if(j+v<MAX)
        	dp[j+v]=min(dp[v+j],dp[j]+u);
        }
        dp[v]=min(dp[v],u);
    }
    for(i=MAX-1;i>=0;i--)
    {
        if(dp[i]<=w)
        {
            cout<<i<<"\n";
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 1024
//2:43
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define Min(a,b) a=min(a,b);
typedef long long ll;

using namespace std;
typedef pair<ll,ll> P;
#define N 100010
vector<P>g[N];
class Dijkstra{
public:
    ll d[N];
    void f(int root){
	lol(i,N)d[i]=(ll)mod*(ll)mod;
	priority_queue<P,vector<P>,greater<P> >Q;
	Q.push(make_pair(0,root));
	while(!Q.empty()){
	    ll cost=Q.top().first;
	    ll x=Q.top().second;
	    Q.pop();
	    if(d[x]!=(ll)mod*(ll)mod)continue;
	    d[x]=cost;
	    for(auto to:g[x]){
		Q.push(make_pair(cost+to.second,to.first));
	    }
	}
    }
};
int n,m,s,t,u,v;
Dijkstra ST[2],U,V;
ll dis[2][N];
P arr[N];
int main(){
    cin>>n>>m>>s>>t>>u>>v;
    lol(i,m){
	ll a,b,c;cin>>a>>b>>c;
	g[a].push_back(make_pair(b,c));
	g[b].push_back(make_pair(a,c));
    }
    ST[0].f(s);ST[1].f(t);U.f(u);V.f(v);
    lol(k,2){
	lol(i,N)arr[i]=make_pair(ST[k].d[i],i);
	lol(i,N)dis[k][i]=U.d[i];
	sort(arr,arr+N,greater<P>());
	lol(i,N){
	    int x=arr[i].second;
	    for(auto to:g[x]){
		ll y=to.first,len=to.second;
		bool ok=true;
		ok&=(ST[0].d[t]==ST[0].d[y]+ST[1].d[y]);
		ok&=(ST[1-k].d[x]+len==ST[1-k].d[y]);
		ok&=(ST[0+k].d[y]+len==ST[0+k].d[x]);
		if(ok)Min(dis[k][y],dis[k][x]);
	    }
	}
    }
    ll ans=U.d[v];
    lol(i,N){
	ll mini=min(dis[0][i],dis[1][i]);
	ll maxi=max(dis[0][i],dis[1][i]);
	if(maxi>=(ll)mod*(ll)mod)continue;
	Min(ans,mini+V.d[i]);
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 25900
#include <stdio.h>
int LCM(int a,int b)
{
	int r,x,tmp;
	x=a*b;
	if(a<b){
		tmp=a;
		a=b;
		b=tmp;
	}
	r=a%b;
	while(r!=0){
		a=b;
		b=r;
		r=a%b;
	}
	return x/b;
}
int main(void)
{
	int a,b,c,d,i,j;
	scanf("%d%d%d",&a,&b,&c);
	d=LCM(a,b);
	for(i=1; i<=d/a; i++){
		if((a*i-c)%b==0){
			printf("YES\n");
			return 0;
		}
	}
	printf("NO\n");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main()
{
	long long ans = 1;
	long long n,k;
	cin >> n >> k;
	while(n--)
	    {
	    	if(ans < k)
	    	    {
	    	    	ans += ans;
				}
				else
				    {
				    	ans += k;
					}
		}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<ll, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int n;
    cin >> n;
    ll a[n],b[n];
    vector<P> vec(n);
    REP(i,n){
        cin >> a[i] >> b[i];
        vec[i].first = a[i] + b[i];
        vec[i].second = i;
    }
    sort(ALL(vec));
    reverse(ALL(vec));
    ll takahasi = 0, aoki = 0;
    REP(i,n){
        if(i % 2 == 0){
            takahasi += a[vec[i].second];
        }else{
            aoki += b[vec[i].second];
        }
    }
    cout << takahasi - aoki << endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() { 
  int n,m;
  cin >> n >> m;
  vi cnt(n);
  rep(i,m){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    cnt[a]++;
    cnt[b]++;
  }
  rep(i,n){
    if(cnt[i]%2){
      cout<<"NO"<<endl;
      return 0;
    }
  }
  cout<<"YES"<<endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;

#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    int n;
    cin>>n;
    vector<int>a(n);
    int tmp=0;
    for(int i=0;i<n;i++){
        cin>>a.at(i);
        tmp+=a.at(i);
    }
    if(tmp==0){
        cout<<"Yes"<<endl;
        return 0;
    }
    if(n%3!=0){
        cout<<"No"<<endl;
    }
    else{
        sort(a.begin(), a.end());
        if(a.at(0)!=0){
            for(int i=0;i<n-1;i++){
                if(a.at(i)!=a.at(i+1)){
                    if(i==n/3-1 || i==2*n/3-1){
                        continue;
                    }
                    else{
                        cout<<"No"<<endl;
                        return 0;
                    }
                }
                else{
                    if(i==n/3-1 || i==2*n/3-1){
                        cout<<"No"<<endl;
                        return 0;
                    }
                }
            }
            int x = a.at(0)^a.at(n/3);
            int y = a.at(n/3)^a.at(2*n/3);
            int z = a.at(2*n/3)^a.at(0);
            if(x==a.at(n*2/3) && y==a.at(0) && z==a.at(n/3)){
                cout<<"Yes"<<endl;
            }
            else{
                cout<<"No"<<endl;
            }
        }
        else{
            int cnt=0;
            for(int i=0;i<n;i++){
                if(a.at(i)!=0){
                    break;
                }
                cnt++;
            }
            if(cnt==n){
                cout<<"Yes"<<endl;
                return 0;
            }
            for(int i=0;i<n-1;i++){
                if(a.at(i)!=a.at(i+1)){
                    if(i==n/3-1){
                        continue;
                    }
                    else{
                        cout<<"No"<<endl;
                        return 0;
                    }
                }
                else{
                    if(i==n/3-1){
                        cout<<"No"<<endl;
                        return 0;
                    }
                }
            }
            int x = a.at(0)^a.at(n/3);
            int y = a.at(n/3)^a.at(2*n/3);
            int z = a.at(2*n/3)^a.at(0);
            if(x==a.at(n*2/3) && y==a.at(0) && z==a.at(n/3)){
                cout<<"Yes"<<endl;
            }
            else{
                cout<<"No"<<endl;
            }
        }
    }



    return 0;
}


Measured memory_bytes: 640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author MaxHeap
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Wall solver = new Wall();
        solver.solve(1, in, out);
        out.close();
    }

    static class Wall {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int[][] mat = new int[10][10];
            int n = in.nextInt();
            int m = in.nextInt();
            for (int i = 0; i < 10; i++) {
                for (int j = 0; j < 10; j++) {
                    mat[i][j] = in.nextInt();
                }
            }
            for (int k = 0; k < 10; k++) {
                for (int i = 0; i < 10; i++) {
                    for (int j = 0; j < 10; j++) {
                        mat[i][j] = Math.min(mat[i][j], mat[i][k] + mat[k][j]);
                    }
                }
            }
            int ans = 0;
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    int cur = in.nextInt();
                    if (cur != -1) {
                        ans += mat[cur][1];
                    }
                }
            }
            out.println(ans);

        }

    }

    static class FastReader {
        BufferedReader reader;
        StringTokenizer st;

        public FastReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            st = null;
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String line = reader.readLine();
                    if (line == null) {
                        return null;
                    }
                    st = new StringTokenizer(line);
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

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

    }
}



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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;

#define PI (2*acos(0.0))
#define eps 1e-9
#define pb push_back
#define endl "\n"
#define watch(x) cout << (#x) << " is " << (x) << endl;
#define show(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi] << " "; cout << endl;
#define showpair(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi].first << " " << v[fi].second << endl;
#define mp make_pair
#define ff first
#define ss second
#define fu cout << "lol" << endl;
#define precision(n) cout << fixed << setprecision(n);
#define lb lower_bound
#define up upper_bound
#define vscan for(i = 0;i<n;i++){cin>>in; v.pb(in);}
#define all(a) a.begin(), a.end()
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define mem(a,val) memset(a,val,sizeof(a))
#define loop(i,n) for(i = 0; i < n; i++)
#define TC() ull T; cin>>T; while(T--)
#define IN(x) {scanf("%d",&x);}
#define LL(x) {scanf("%lld",&x);}
#define CC(x) {scanf("%c",&x);}
#define pfl(x) printf("%d\n",x)
#define pfll(x) printf("%lld\n",x)
#define newl puts("")
#define space printf(" ")
#define MOD 1000000007
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL);


int main()
{
    int i = 0, j = 0, in;
    int n, k; cin>>n>>k;
    int cnt = 0;
    while(n > 0){
        n /= k;
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int n;
    cin >> n;
    int F[100][14], P[100][15];
    for(int i = 0; i < n; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> F[i][j];
        }
    }
    for(int i = 0; i < n; i++) {
        for (int j = 0; j < 11; j++) {
            cin >> P[i][j];
        }
    }

    int ans = -(1 << 30);
    for (int bit = 1; bit < (1<<10); bit++) {
        int cc = 0;
        for(int i = 0; i < n; i++) {
            int c = 0;
            for (int j = 0; j < 10; j++) {
                if ((bit >> j&1) && F[i][j]) c++;
            }
            cc += P[i][c];
        }
        ans = max(ans, cc);
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2E5 + 5;
const int mod = 998244353;

int dp[N];

void solve(){

    int n, k;
    scanf("%lld %lld",&n, &k);
    pair<int, int> p[15];

    for(int i = 0;i < k; i++){
        int x, y;
        scanf("%lld %lld",&x, &y);
        p[i] = make_pair(x, y);
    }

    dp[1]=1;

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

        dp[i] = 0;

        for(int j = 0; j < k; j++){

            int l = max(1LL, i - p[j].second);
            int r = i - p[j].first;

            if(l <= r) {
                dp[i] += dp[r] - dp[l - 1];
                dp[i] %= mod;
                dp[i] += mod;
                dp[i] %= mod;
            }
        }

        dp[i] += dp[i - 1];
        dp[i] %= mod; 
    }

    printf("%lld\n",((dp[n] - dp[n - 1]) + mod) % mod);
}

int32_t main() 
{
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  #endif 
  ios::sync_with_stdio(0); 
  cin.tie(0); cout.tie(0);
   
  solve();

  return 0;
}

Measured memory_bytes: 5396
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		String result = "Yes";
		while(true) {
			c -= b;
			if(c <= 0) break;
			a -= d;
			if(a <= 0) {
				result = "No";
				break;
			}
		}
		System.out.println(result);

	}

}

Measured memory_bytes: 35760
#include <stdio.h>
#include <climits>
#include <iostream>
#include <cstdlib>
#include <string>
#define FOR(i,ii,n) for(int i=ii; i<n; i++)

using namespace std;

int main(){
	int N;
	cin >> N;
	string S[N];
	FOR(i,0,N){
		cin >> S[i];
	}
	long long cnt = 0;
	FOR(d,0,N){
		bool flg = true;
		FOR(r,0,N){
			FOR(c,r+1,N){
				if(S[(r+d)%N][c] != S[(c+d)%N][r])
					flg = false;
			}
		}
		if(flg)
			cnt += N;
	}
	printf("%lld", cnt);
}

Measured memory_bytes: 384
N, Y = map(int, input().split())

for i in range(N+1):
  for j in range(N+1):
    k = N - i - j
    if 0 <= k <= N and Y == 10000*i + 5000*j + 1000*k:
      print('{} {} {}'.format(i, j, k))
      exit()

print('-1 -1 -1')


Measured memory_bytes: 2940
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  LL L, R; cin >> L >> R;
  LL dL = L/2019LL, dR = R/2019LL;
  if (dL != dR) {
    cout << 0 << endl;
    return 0;
  }

  LL L2 = L % 2019, R2 = R % 2019;
  LL vmin = 1e18;
  for (LL i = L2; i <= R2; ++i) {
    for (LL j = i + 1LL; j <= R2; ++j) {
      LL v = (i * j) % 2019;
      vmin = min(v, vmin);
    }
  }

  cout << vmin << endl;
}


Measured memory_bytes: 3552
#include<algorithm>
#include<iostream>
#include<functional>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
  int a,b,n[110000],ans=1;
  cin>>a>>b;
  for(int i=0;i<a;i++){
    cin>>n[i];
  }
  for(int j=0;j<a;j++){
    if(j==0)
      ans=abs(b-n[j]);
    else
     ans=__gcd(abs(n[j]-b),ans);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 640