akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define wi(t) int t;cin>>t;while(t--)
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}
int mpow(int base, int exp); 
void ipgraph(int n, int m);
void dfs(int u, int par);

const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];

void solve()
    {
  
  int n;
  cin>>n;
  int k=n%1000;
  if(k==0)
  {
      cout<<"0";
      return;
  }
  int t=n;
  t=t+(1000-k);
  cout<<t-n;
  
  
    }

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

   // wi(t)
    {
      solve();
    }

    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(int n, int m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
    u--, v--;
		g[u].pb(v);
		g[v].pb(u);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}






Measured memory_bytes: 10688
// Average Score

#include <iostream>
#include <vector>

using namespace std;

int main()
{
  vector<int> exam;
  int i, x, ave = 0;

  for (i = 0; i < 5; i++) {
    cin >> x;
    exam.push_back(x);
  }

  for (i = 0; i < 5; i++) {
    if (exam[i] < 40) {
      ave += 40;
    } else {
      ave += exam[i];
    }
  }

  ave /= exam.size();

  cout << ave << endl;

  return 0;
}

Measured memory_bytes: 1212
h,w,n=map(int,input().split())
xy=[list(map(int,input().split())) for i in range(n)]
xy.sort()
cnt=0
ans=h
for x,y in xy:
  if x-1>=y+cnt:
    ans=x-1
    break
  elif x==y+cnt:
    cnt+=1
print(ans)


Measured memory_bytes: 79576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VVL vector<vector<ll>>
#define ALL(v) (v).begin(), (v).end()
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    ll h,w,k,cnt=1; cin>>h>>w>>k;
    VS data(h); VVL ans(h,VL(w,0));
    rep(i,0,h) cin>>data[i];
    rep(i,0,h)rep(j,0,w){
        if(j==0){
            if(data[i][j]=='#'){
                ans[i][j]=cnt;
                cnt++;
            }
        }
        else{
            if(data[i][j]=='#'){
                ans[i][j]=cnt;
                cnt++;
            }
            else if(ans[i][j-1]!=0 && ans[i][j]==0){
                ans[i][j]=ans[i][j-1];
            }
        }
    }
    rep(i,0,h)for(ll j=w-1;j>=(ll)(0);j--){
        if(j==w-1) continue;
        if(ans[i][j+1]!=0 && ans[i][j]==0)
        ans[i][j]=ans[i][j+1];
    }
    rep(i,0,w)rep(j,0,h){
        if(j==0) continue;
        if(ans[j-1][i]!=0 && ans[j][i]==0)
        ans[j][i]=ans[j-1][i];
    }
    rep(i,0,w)for(ll j=h-1;j>=(ll)(0);j--){
        if(j==h-1) continue;
        if(ans[j+1][i]!=0 && ans[j][i]==0)
        ans[j][i]=ans[j+1][i];
    }
    rep(i,0,h)rep(j,0,w){
        if(j!=w-1) cout<<ans[i][j]<<" ";
        else cout<<ans[i][j]<<endl;
    }
}

Measured memory_bytes: 1664
#include <iostream>

using namespace std;

int main()
{
  char s[100];
  char p[100];
  int i;
  int j;
  int start;
  
  cin >> s >> p;
  
  i=0;
  
  Roop:;
  
  for(;s[i]!='\0';i++)
  {
    if(s[i]==p[0])
    {
      start=i;
      goto Next;
    }
  }
  
  cout << "No\n";
  goto Exit;
  
  Next:;
  
  for(i=start,j=0;p[j]!='\0';j++ , i++)
  {
    if(s[i]=='\0')
      i=0;
    
    if(s[i]!=p[j])
    {
      i=start+1;
      goto Roop;
    }
  }
  cout << "Yes\n";
  Exit:;
}

Measured memory_bytes: 1104
#include<iostream>
#include<string.h>
#include<cstdio>
#include<queue>
using namespace std;

int flag[100010];
int main(){

   int n, l, r;
   while(cin >> n){
        memset(flag, 0, sizeof(flag));
   int cnt = 0;
   for(int i = 0; i < n; ++i){
        cin >> l>> r;
        for(int i = l; i <= r; ++i){
            if(!flag[i]){
                flag[i] = 1;
                cnt ++;
            }
        }
   }
   cout << cnt <<endl;
   }


   return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long
using namespace std;
int32_t main()
{
    int n;
    cin>>n;
    vector<int> a(n),b(n),c(n-1);
    for(auto &i:a)
        cin>>i;
    for(auto &i:b)
        cin>>i;
    for(auto &i:c)
        cin>>i;
    int ans=0;
    for(int i=0;i<n;i++)
    {
        if(i==0)
        {
            ans+=b[a[i]-1];
        }
        else
        {
            if(a[i]-a[i-1]==1)
            {
                ans+=b[a[i]-1];
                ans+=c[a[i-1]-1];
            }
            else
                ans+=b[a[i]-1];
        }
    }
    cout<<ans;
    return 0;
}
//17:05
//13+5+8+24

Measured memory_bytes: 3632
using System;

namespace newEx
{
    class Program
    {
        static void Main(string[] args)
        {
            //string[] l = Console.ReadLine().Split(' ');
            //int p = int.Parse(l[0]);
            //int q = int.Parse(l[1]);

            string l = Console.ReadLine();

            Console.WriteLine(S(l));
        }

        public static string S(string s)
        {
            char x, y, z, w;

            x = s[0];
            y = s[1];
            z = s[2];
            w = s[3];

            if (x != y && y != z && z != w)
            {
                return "Good";
            }
            else
            {
                return "Bad";
            }
        }
    }
}


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

namespace 練習１
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = Console.ReadLine();
            var N = int.Parse(a);
            int n = N;
            int count = 0;

            while (n > 0)
            {
                if (n % 10 == 7)
                {
                    count = 1;
                    break;
                }
                n = n / 10;
            }

            if (count == 1)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 27188
lst_input_num = list(map(int, input().split()))
r, c = lst_input_num[0], lst_input_num[1]
lst = []
lst_row = []

for i in range(r):
    lst_input = list(map(int, input().split()))
    lst.append(lst_input)

for i in range(c):
    lst_column = []
    for j in range(r):
        lst_column.append(lst[j][i])

    lst_row.append(sum(lst_column))

lst.append(lst_row) 

count = 0
for i in lst:
    for j in i:
        print(j, end=" ")

    print(sum(i))



Measured memory_bytes: 6220
def main():
    n, c = map(int, input().split())
    sushi = [None]*n
    for i in range(n):
        sushi[i] = list(map(int, input().split()))
    cal_r = [None] * n
    cal_l = [None] * n
    max_r = [None] * n
    max_l = [None] * n
    cal_r[0] = sushi[0][1] - sushi[0][0]
    max_r[0] = cal_r[0]
    for i in range(1, n):
        cal_r[i] = cal_r[i-1] + sushi[i][1] - (sushi[i][0] - sushi[i-1][0])
        max_r[i] = max(max_r[i-1], cal_r[i])
    cal_l[n-1] = sushi[n-1][1] - (c - sushi[n-1][0])
    max_l[n-1] = cal_l[n-1]
    for i in reversed(range(n-1)):
        cal_l[i] = cal_l[i+1] + sushi[i][1] - (sushi[i+1][0] - sushi[i][0])
        max_l[i] = max(max_l[i+1], cal_l[i])
    max_r_1 = max(max_r)
    max_l_1 = max(max_l)
    ans = max(0, max_r_1, max_l_1)
    cal_r_2 = [None] * n
    cal_l_2 = [None] * n
    cal_r_2[n-1] = 0
    cal_l_2[0] = 0
    for i in range(n-1):
        cal_r_2[i] = cal_r[i] - sushi[i][0] + max_l[i+1]
    for i in reversed(range(1, n)):
        cal_l_2[i] = cal_l[i] - (c - sushi[i][0]) + max_r[i-1]
    max_r_2 = max(cal_r_2)
    max_l_2 = max(cal_l_2)
    ans = max(ans, max_l_2, max_r_2)
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 46376
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
#include <random>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
#define CONTAINS_SET(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }


signed main()
{
	string a, b, c;
	cin >> a >> b >> c;
	cout << a[0] << b[1] << c[2] << endl;
}



Measured memory_bytes: 3568
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define vec vector
#define fi first
#define se second
#define eb emplace_back
#define ef emplace_front
#define pof pop_front()
#define pob pop_back()
#define Rep(i,n) for(li i=0,nn=(li)(n);i!=nn;++i)
#define Rep1(i,n) for(li i=1,nn=(li)(n)+1;i!=nn;++i)
#define Size(v) (li)(v.size())
#define SortA(v) sort(v.begin(),v.end())
#define SortD(v) sort(v.rbegin(),v.rend())
#define All(a) (a).begin(),(a).end()
#define Input(a) for(li ii=0,nn=(li)(a.size());ii!=nn;++ii){cin>>(a).at(ii);}
#define Input2(a,b) for(li ii=0,nn=(li)(a.size());ii!=nn;++ii){cin>>(a).at(ii)>>(b).at(ii);}
#define mp make_pair
using li = int64_t;
using intl = int64_t;
using vi = vec<li>;
using vb = vec<bool>;
using vvi = vec<vi>;
using qi = deque<li>;
using pi = pair<li, li>;
using vpi = vec<pi>;
using si = set<li>;
using vsi = vec<si>;
using mii = map<li, li>;
using vmii = vec<mii>;
vec<li> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<li> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr li INF = LLONG_MAX;
constexpr li mod = 1000000007;

void Yes(li b) {
	if (b)cout << "Yes";


	else cout << "No";
}
void yes(li b) {
	if (b)cout << "yes";
	else cout << "no";
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	cout.precision(16);

	li N;
	cin >>N;

	vi A(N);
  Rep(i,N){
    cin>>A[i];
  }

	__int128 sum=0;
	__int128 sumsq = 0;

	for(auto&& a:A){
		sum += a;
		sumsq += a*a;

	}

	sum = sum * sum;
	sum -= sumsq;
	sum /=2;
	sum %= mod;
	if(sum<0)sum+=mod;

	cout <<li(sum);


}

Measured memory_bytes: 4784
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		//????????????????????????
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));

		
		//?????????
		int n = Integer.parseInt(bf.readLine());
		Point p1= new Point(0,0);
		Point p2= new Point(100,0);
		System.out.println(p1.x + " "+p1.y);
		koch(n,p1,p2);
		System.out.println(p2.x + " "+p2.y);
	}
	
	public static boolean koch(int depth,Point p1,Point p2){
		if(depth==0){
			return true;
		}
		Point s = new Point((p1.x*2+p2.x)/3,(p1.y*2+p2.y)/3);
		Point t = new Point((p1.x+p2.x*2)/3,(p1.y+p2.y*2)/3);
		Point u = new Point((t.x-s.x)*Math.cos(Math.toRadians(60))-(t.y-s.y)*Math.sin(Math.toRadians(60))+s.x,(t.x-s.x)*Math.sin(Math.toRadians(60))+(t.y-s.y)*Math.cos(Math.toRadians(60))+s.y);
		koch(depth-1,p1,s);
		System.out.println(s.x+" "+s.y);
		koch(depth-1,s,u);
		System.out.println(u.x+" "+u.y);
		koch(depth-1,u,t);
		System.out.println(t.x+" "+t.y);
		koch(depth-1,t,p2);
		return true;
	}
	
}
class Point{
	double x;
	double y;
	
	public Point(double x,double y){
		this.x = x;
		this.y =y ;
	}
}

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

using namespace std;

long double dp[301][301][301];
long double calc(int x, int y, int z, int n) {
    if (x<0 || y<0 || z<0)
        return 0;
    if (x==0 && y==0 && z==0)
        return 0;
    else if (dp[z][y][x] != 0)
        return dp[z][y][x];
    long double a;
    a = 1.0*n/(1.0*(x+y+z));
    a += 1.0*z/(1.0*(x+y+z))*calc(x, y+1, z-1, n);
    a += 1.0*y/(1.0*(x+y+z))*calc(x+1, y-1, z, n);
    a += 1.0*x/(1.0*(x+y+z))*calc(x-1, y, z, n);
    dp[z][y][x] = a;
    return a;
}

int main() {
    int n;
    cin>>n;
    int x=0, y=0, z=0;
    long double dp[n+1][n+1][n+1];
    for (int i=0; i<n; i++) {
        int a;
        cin>>a;
        if (a==1)
            x++;
        else if (a==2)
            y++;
        else if (a==3)
            z++;
    }
    
    cout<<setprecision(12)<<calc(x, y, z, n)<<endl;
    return 0;
}

Measured memory_bytes: 426240
#include<iostream>
#include<iomanip>
#include<sstream>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include<numeric>
#include<set>
using namespace std;

int main(){
  long n;
  cin >> n;

  long ans = n*(n-1)/2;
  cout << ans << endl;
  
  return 0;
}

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

public class Main{
	public static void main(String args[]){
		InputStreamReader rd = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(rd);
		try{
				ArrayList<Integer> al = new ArrayList<Integer>();
				String str = br.readLine();
				String initial[] = str.split(" ");
				for(int j=0;j<initial.length;j++){
					al.add(Integer.parseInt(initial[j]));
				}
				int pos = al.indexOf(0);
				System.out.println(pos+1);
		}
		catch(Exception e){
			return;
		}
	}
}

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

int main()
{
    int n;
    int a[100];

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

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

    return 0;
}

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

int main() {
  int P, Q, R, a,i,u;
  cin >>P>>Q>>R;
  a=P+Q;
  i=P+R;
  u=Q+R;
  vector<int>vec;
  vec={a,i,u};
  sort(vec.begin(), vec.end());
  cout<<vec.at(0)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    while (1) {
        int n;
        cin >> n;
        if (n == 0) return 0;
        
        int q[1005], sm = 0;
        for (int i = 0; i < n; i++) {
            cin >> q[i];
            sm += q[i];
        }
        
        sort(q, q + n);
        
        cout << (sm - q[0] - q[n - 1]) / (n - 2) << endl;
    }
}



Measured memory_bytes: 3148
num_of_odd = num_of_even = 0
N = int(input())
buff = []
for n in map(int, input().split()):
    #n = int(input())
    if n % 2:
        num_of_odd += 1
    else:
        num_of_even += 1
    buff.append(n)


if num_of_odd:
    if num_of_odd % 2:
        if num_of_odd == 1 and num_of_even == 0:
            print('YES')
        else:
            print('NO')
    else:
        print('YES')
else:
    pirnt('YES')

Measured memory_bytes: 14052
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define x first
#define y second
using namespace std;
const int maxn=2e5+100;
typedef long long ll;
typedef pair<int, int>pii;
int n, arr[maxn];
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0);
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>arr[i];
    int l=0, r=0, cur=arr[0];
    ll ans=0;
    while(l<n)
    {
        while(r+1<n&&((cur&arr[r+1])==0))
        {
            cur^=arr[r+1];
            r++;
        }
        ans+=(r-l+1);
        cur^=arr[l++];
    }
    cout<<ans<<"\n";
    return 0;
}

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }

    vector<int> cnt(n + 1, 0);
    for (int i = 0; i < n; i++) {
        cnt[p[i]] = cnt[p[i] - 1] + 1;
    }

    int ans = 0;
    for (int i = 1; i <= n; i++) {
        ans = max(ans, cnt[i]);
    }
    ans = n - ans;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
import bisect

N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for a in range(N):
    for b in range(a):
        ab = L[a] + L[b]
        r = bisect.bisect_left(L, ab)
        l = a + 1
        ans += max(r - l, 0)
print(ans)

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

int main() {
  int N;
  cin >> N;
  int Ns=N;
  int sum=0;
  while(Ns>0){
    sum+=Ns%10;
    Ns=Ns/10;
  }
  if(N%sum==0)cout << "Yes";
  else cout << "No";
}



Measured memory_bytes: 256
# https://atcoder.jp/contests/abc088/tasks/abc088_d
# 最短経路を求めて，それ以外を塗る

# from heapq import heappush, heappop, heapify
from collections import deque

INF = int(1e18)
neighbors = [(0, 1), (0, -1), (1, 0), (-1, 0)]

h, w = map(int, input().split())
MAP = [list(input()) for _ in range(h)]


d = [[INF for _ in range(w)] for _ in range(h)]
queue = deque([(0, 0)])
# visited = set({})
# queue = [(0, (0, 0))]
# heapify(queue)
d[0][0] = 0
while len(queue) > 0:
    (y, x) = queue.popleft()
    for (dy, dx) in neighbors:
        nx = x + dx
        ny = y + dy
        if 0 <= nx < w and 0 <= ny < h:
            if MAP[ny][nx] == '.' and d[ny][nx] > d[y][x] + 1:
                d[ny][nx] = d[y][x] + 1
                queue.append((ny, nx))

# for drow in d: print(*drow)
if d[h - 1][w - 1] == INF:
    print(-1)
else:
    distST = d[h - 1][w - 1]
    count0 = 0
    for row in MAP:
        for ch in row:
            if ch == '#':
                count0 += 1
    print(h * w - count0 - distST - 1)

Measured memory_bytes: 41712
#include <stdio.h>

int main() {
        int a, b, c;
        int n = 0;

        scanf("%d %d %d", &a, &b, &c);

        for (int i = a; i <= b; i++) {
                if (c % i == 0) {
                        n++;
                }
        }

        printf("%d\n", n);

}


Measured memory_bytes: 2104
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>

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

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;

int main()
{
    vector<vector<int> > c(3, vector<int>(3));
    vector<int> a(3), b(3);
    a[0] = 0; //なんでもいいので

    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            cin >> c[i][j];
        }
    }
    for(int i = 0; i < 3; i++) b[i] = c[0][i] - a[0];
    for(int i = 0; i < 3; i++) a[i] = c[i][0] - b[0];

    bool is_right = true;
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            if(a[i] + b[j] != c[i][j]){
                is_right = false;
            }
        }
    }

    if(is_right == true) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void solve(){
    int a[3];
    for(int i = 0; i < 3;i ++){
        cin >> a[i];
    }
    int b[3];
    b[0] = a[0] + a[1];
    b[1] = a[0] + a[2];
    b[2] = a[1] + a[2];
    int min = b[0];
    for(int i = 0; i < 3; i++){
        if(b[i] < min) min = b[i];
    }

    cout << min << endl;

}

int main(){
    
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/

    solve();

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <complex>
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;

typedef int Weight;
const int inf = 1<<29;

struct Edge{
  int src,dst;
  Weight weight, cost;
  Edge(int src, int dst, Weight weight, Weight cost) :
    src(src), dst(dst), weight(weight) , cost(cost) {;}
};

bool operator<(const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight :
    e.cost != f.cost ? e.cost > f.cost : e.src != f.src ? e.src < f.src : e.dst < f.dst;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

set<pair<int ,int> > usedPath;

void dijkstra(const Graph &g, int s, vector<Weight> &dist, vector<int> &prev,vector<int> &cost) {
  const int n = g.size();
  dist.assign(n, inf);
  cost.assign(n, inf);
  dist[s] = cost[s] = 0;
  prev.assign(n, -1);

  priority_queue<Edge> Q;
  for(Q.push(Edge(-2, s, 0, 0)); !Q.empty();) {
    Edge e = Q.top();
    Q.pop();
    //cout<<"now : "<<e.src<<" "<<e.dst<<" "<<e.weight<<" "<<e.cost<<endl;
    if(prev[e.dst] != -1) continue;
    prev[e.dst] = e.src;

    if(e.src >= 0 && e.dst >= 0) {
      usedPath.insert(make_pair(min(e.src,e.dst), max(e.src,e.dst)));

    }

    for(Edges::const_iterator it = g[e.dst].begin(); it != g[e.dst].end(); ++it) {
      if(dist[it->dst] > e.weight + it->weight
         ||(dist[it->dst] == e.weight + it->weight && cost[it->dst] > it->cost)) {
        dist[it->dst] = e.weight + it->weight;
        cost[it->dst] = it->cost;
        //cout<<"add "<<it->src<<" "<<it->dst<<" "<<it->cost<<" "<<e.weight+it->weight<<endl;
        Q.push(Edge(it->src, it->dst, e.weight+ it->weight, it->cost));
      }
    }
  }
}

int main() {
  int n,m;
  while(cin>>n>>m, n|m) {
    usedPath.clear();
    int u,v,c,d;
    ll sum = 0;
    Graph g(n);
    REP(i,m) {
      cin>>u>>v>>d>>c;
      u--, v--;
      g[u].push_back(Edge(u,v,d,c));
      g[v].push_back(Edge(v,u,d,c));
    }

    vector<Weight> dist(n);
    vector<int> prev(n);
    vector<int> cost(n);
    dijkstra(g, 0, dist, prev, cost);
    sum = 0;
    for(set<pair<int,int> >::iterator it = usedPath.begin(); it != usedPath.end(); ++it) {
      pair<int,int> now = *it;
      for(int i = 0; i< g[now.first].size(); ++i)
        if(g[now.first][i].dst == now.second) {
          //cout<<now.first<<" "<<now.second<<endl;
          sum += g[now.first][i].cost;
          break;
        }
    }
    cout<<sum<<endl;

  }
}

Measured memory_bytes: 2380
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

int n;

int main(void){
	scanf("%d",&n);
	ll res=mod_pow(10,n,MOD);
	res+=MOD-mod_pow(9,n,MOD);
	res+=MOD-mod_pow(9,n,MOD);
	res+=mod_pow(8,n,MOD);
	res%=MOD;
	printf("%lld\n",res);
	return 0;
}


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

int main()
{
	std::ios::sync_with_stdio(false);

	long long k, a, b;
	cin >> k >> a >> b;

	long long pocket = 1;

	int i = 1;

	while (i<=k)
	{
		if (pocket < a)
		{
			pocket++;
			i++;
		}
		else
		{
			if (b - a >= 2 && (k - i + 1) >= 2)
			{
				i=i+2;
				pocket = pocket - a;
				pocket=pocket + b;
			}
			else
			{
				pocket++;
				i++;
			}
		}

	}

	cout << pocket << endl;


	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<complex>
const int mod=998244353;
using namespace std;
int jc[9000005]={1},ny[9000005]={1},c,d;
int Power(int x,int y,int mod) {
	int ret=1;
	while(y) {
		if(y&1)ret=1ll*ret*x%mod;
		x=1ll*x*x%mod,y>>=1;
	}
	return ret;
}
int C(int n,int m){
	if(n<m)return 0;
	return 1ll*ny[m]*ny[n-m]%mod*jc[n]%mod;
}
int ff[3005][3005];
int f(int a,int b){
	//cout<<a<<' '<<b<<' '<<c<<' '<<d<<endl;
	if(a>c||b>d)return 0;
	if(a==c&&b==d)return 1;
	if(ff[a][b])return ff[a][b];
	int ans=0;
	for(int i=0;i<=min(c-a,1);i++){
		for(int j=0;j<=min(d-b,1);j++){
			if(!i&&!j)continue;
			int w=1ll*Power(a,j,mod)*Power(b,i,mod)%mod*f(a+i,b+j)%mod;
			if(!(i&&j))ans=(ans+w)%mod;
			else ans=(ans-w+mod)%mod;
			//if(a==2&&b==1&&c==3&&d==4)cout<<i<<' '<<j<<' '<<w<<endl;
		}
	}
	return ff[a][b]=ans;
}
int main() {
	ny[1]=1;
	for(int i=2; i<=9000000; i++)ny[i]=1ll*(mod-mod/i)*ny[mod%i]%mod;
	for(int i=1; i<=9000000; i++)ny[i]=1ll*ny[i-1]*ny[i]%mod,jc[i]=1ll*jc[i-1]*i%mod;
	int a,b;
	cin>>a>>b>>c>>d;
	//cout<<1ll*jc[c*d-a*b]*ny[c-a+d-b]%mod*ny[c*d-a*b-(c-a+d-b)]%mod;
	cout<<f(a,b);
	return 0;
}

Measured memory_bytes: 109640
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }


        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var NY = Sarray();
            var N = NY[0];
            var Y = NY[1];

            for (var i = 0; i <= N; ++i)
            {
                for (var j = 0; j <= N; ++j)
                {
                    var k = N - (i + j);
                    if (k < 0) break;
                    if (1000 * k == Y - (i * 10000 + j * 5000))
                    {
                        WriteLine($"{i} {j} {k}");
                        return;
                    }
                }
            }
            WriteLine("-1 -1 -1");
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 13396
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

int main()
{
    std::string S;
    std::cin >> S;
    long len=S.length();
    long count=0;
    for(long i=0; i<len/2; i++){
        if(S[i]!=S[len-1-i]){
            count++;
        }
    }
    std::cout << count << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
using namespace std;
typedef long long ll;
int main(){
  ll A,B,C,X,Y;
  cin >> A >> B >> C >> X >> Y;

  if(2 * C > A + B){
    cout << X * A + Y * B << endl;
  }
  else{
    if(X > Y){
      cout << 2 * C * Y + min(A*(X-Y), 2*C*(X-Y)) << endl;
    }
    else if(Y >= X){
      cout << 2 * C * X + min(B*(Y-X),2*C*(Y-X)) << endl;
    }
  }

}


Measured memory_bytes: 384
a, b = map(int, input().split())
c = list(map(int, input().split()))
d = 0
for i in range(a):
    if i == 0:
        if c[i] > b:
            d += abs(c[i] - b)
            c[i] -= abs(c[i] - b)
    else:
        if c[i] + c[i-1] > b:
            d += abs(c[i] + c[i-1] - b)
            c[i] -= abs(c[i] + c[i-1] - b)
print(d)


Measured memory_bytes: 14132
let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let fold_left f init str =
  let acc = ref init in
  for i = 0 to String.length str - 1 do
    acc := f !acc str.[i];
  done;
  !acc

let () =
  let to_x = Array.make 128 (-1) in
  to_x.(Char.code 'A') <- 0;
  to_x.(Char.code 'C') <- 1;
  to_x.(Char.code 'G') <- 2;
  to_x.(Char.code 'T') <- 3;
  let set = Array.make 9999973 false in
  let hash s = fold_left (fun acc c -> 4*acc + to_x.(Char.code c)) 1 s in
  let n = read_int () in
  for _ = 0 to n - 1 do
    match split_on_char ' ' (read_line ()) with
    | ["find"; s] -> print_endline (if set.(hash s) then "yes" else "no")
    | [_; s] -> set.(hash s) <- true
    | _ -> assert false
  done

Measured memory_bytes: 83416
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=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 pair<int,int> P;
typedef pair<ll,ll> PL;

#define mod 1000000007

ll add(ll x, ll y){
    return (x+y)%mod;
}

ll mul(ll x, ll y){
    return (x%mod)*(y%mod)%mod;
}

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

ll divll(ll x, ll y){
    return (x * powll(y,mod-2)) % mod;
}

ll nPr(ll n, ll r){
    ll res = 1LL;
    FOR(i,1,r){
        res = (res * ((n-i+1) % mod)) % mod;
    }
    return res;
}

ll nCr(ll n, ll r){
    ll res = nPr(n,r);
    FOR(i,1,r){
        res = (res * powll(i,mod-2)) % mod;
    }
    return res;
}

int main() {
    int n, m;
    cin >> n >> m;
    VL x(n), y(m);
    REP(i,n) scanf("%lld", &x[i]);
    REP(i,m) scanf("%lld", &y[i]);

    ll s = 0;;
    REP(i,n-1){
        s = add(s, mul(mul(i+1, n-i-1), x[i+1]-x[i]));
    }

    ll ans = 0;
    REP(j,m-1){
        ans = add(ans, mul(s, mul(mul(j+1, m-j-1), y[j+1]-y[j])));
    }
    cout << ans << endl;
    return 0;
}

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

namespace ARC100
{
    class C
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] A = Console.ReadLine().Split().Select(int.Parse).ToArray();

            int[] B = new int[N];
            for (int i = 0; i < N; i++)
            {
                B[i] = A[i] - (i + 1);
            }
            B = B.OrderBy(x => x).ToArray();

            int res = 0;
            if (B.Count() == 1) res = B[0];
            else if (B.Count() % 2 == 1) res = B[B.Count() / 2];
            else res = (B[B.Count() / 2] + B[B.Count() / 2 - 1]) / 2;

            long ans = 0;
            for (int i = 0; i < N; i++)
            {
                ans += Math.Abs(A[i] - (i + 1 + res));
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 34208
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;

int main(){
  
 int a,b,c; cin >> a >> b >> c;
  if(2*b == a+c){ cout << "YES" << endl;}
  else{cout << "NO" << endl;}
  return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define yn(x, ok, ng) cout << ((x)?(ok):(ng)) << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
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 const INF = 1001001001;


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

int D;
cin >> D;
vi c(26);
rep(i,26) cin >> c[i];
vvi s(D,vi(26));
rep(d,D) rep(i,26) cin >> s[d][i];

int cur = 0;
vi last(26);
rep(d,D) {
    int res = -INF;
    int p = 0;
    rep(i,26) {
        int up = s[d][i];
        int old = last[i];
        last[i] = d+1;
        int down = 0;
        rep(j,26) {
            down += c[j] * (d+1-last[j]);
        }
        last[i] = old;
        if(chmax(res,up-down)) p = i;
    }
    last[p] = d+1;
    cout << p+1 << endl;
}

return 0;
}

Measured memory_bytes: 3660
#include <iostream>
using namespace std;
int keta(int n, int k) { return n / k % 10; }
int main()
{
    int A, B;
    cin >> A >> B;
    int cnt = 0;
    for (int i = A; i <= B; i++) {
        if (keta(i, 1) == keta(i, 10000) && keta(i, 10) == keta(i, 1000))
            cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
N, W = map(int, input().split())
items = []
for _ in range(N):
    v, w = map(int, input().split())
    items.append((v, w))

C = [[0] * (W + 1) for _ in range(N + 1)]

for i in range(1, N + 1):
    for j in range(1, W + 1):
        item = items[i - 1]
        if item[1] <= j:
            C[i][j] = max(C[i - 1][j], C[i - 1][j - item[1]] + item[0])
        else:
            C[i][j] = C[i - 1][j]

print(C[N][W])



Measured memory_bytes: 25520
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var a, b string
	fmt.Scanln(&a)
	fmt.Scanln(&b)

	na, _ := strconv.ParseInt(a, 10, 0)
	nb, _ := strconv.ParseInt(b, 10, 0)
	fmt.Print(run(na, nb))
}

func run(na, nb int64) int64 {
	const total = 6
	return total - na - nb
}


Measured memory_bytes: 512
using System;

public class Test
{
    public static void Main()
    {

        int n = int.Parse(Console.ReadLine().Trim());
        int k = int.Parse(Console.ReadLine().Trim());
        int x = int.Parse(Console.ReadLine().Trim());
        int y = int.Parse(Console.ReadLine().Trim());

        int total = 0;

        total = k * x + (n - k) * y;

        if (n<=k)
        {
           total = n * x;
        }

        Console.WriteLine(total);
    }
}

Measured memory_bytes: 2648
#include <iostream>
#include <string>
#include <tuple>
using namespace std;

int main() {
    string s;
    int y, m, d;
    while (cin >> s) {
        if (s == "#") break;
        cin >> y >> m >> d;
        string res = s;
        if (make_pair(y, make_pair(m, d)) >= make_pair(31, make_pair(5, 1))) res = "?", y -= 30;
        cout << res << " " << y  << " " << m << " " << d << endl;
    }
}



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

const int _ = 1e5 + 7;
char A[_] , B[_]; deque < int > posA , posB; int N;

int main(){
	scanf("%d %s %s" , &N , A + 1 , B + 1);
	if(N == 1){printf("%d\n" , A[1] ^ B[1]); return 0;}
	for(int i = 2 ; i <= N ; ++i) if(!(A[i] ^ A[i - 1])) posA.push_back(i);
	for(int i = 2 ; i <= N ; ++i) if(!(B[i] ^ B[i - 1])) posB.push_back(i);
	long long ans = 1e18;
	for(int i = -(int)max(posA.size() , posB.size()) - 10 ; i <= (int)max(posA.size() , posB.size()) + 10 ; ++i)
		if(!((A[1] - B[1] + i) & 1)){
			deque < int > pA = posA , pB = posB; long long sum = 0;
			for(int j = 0 ; j < abs(i) ; ++j) (i < 0 ? pA : pB).push_front(1);
			while(pA.size() < pB.size()) pA.push_back(N + 1);
			while(pB.size() < pA.size()) pB.push_back(N + 1);
			for(int j = 0 ; j < pA.size() ; ++j) sum += abs(pA[j] - pB[j]);
			ans = min(ans , sum);
		}
	cout << ans; return 0;
}

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

int main(){
    ll A,B,N;
    cin >> A >>B >> N;
    cout << (A*(min(N,B-1)))/B << endl;   
}


Measured memory_bytes: 3636
N = int(input())
nums = []
length = len(str(N))
def dfs(s, n):
        global nums
        nums.append(s)
        if n == length:
                return
        dfs(s + "3", n + 1)
        dfs(s + "5", n + 1)
        dfs(s + "7", n + 1)

dfs("", 0)
ans = 0
for i in nums:
        if i.count("3") >= 1 and i.count("5") >= 1 and i.count("7") >= 1:
                if int(i) <= N:
                        ans += 1
print(ans)

Measured memory_bytes: 5236
#include <iostream>
#include <map>
#include <vector>
#include <deque>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <string>
#include <set>
#include <valarray>
#include <iomanip>
#include <bitset>
#include <random>
#include <complex>
#include <random>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define pb push_back
#define ll __int128
#define mp make_pair
#define fdeg firdeg
#define snd second
#define ld long double
#define mt make_tuple
#define fst firs
const double PI = acos(-1);
const int N = 5e6 + 17;
ll MOD = 1e9 + 7;
const int INF = 1e9 + 9;
const int MAXN = 26;
const int maxlog = 18;
ld eps = 1e-8;
random_device rd;
mt19937 rnd(rd());
uniform_int_distribution<ll> nextRand(0,(ll)1e9);
template<class A, class B>
void sum(A &a, B b)
{
    a += b;
    if (a < 0LL) a += MOD;
    if (a >= MOD) a -= MOD;
}
ll add(ll a, ll b)
{
    a += b;
    if (a < 0) a += MOD;
    if (a >= MOD) a -= MOD;
    return a;
}
int to_i(char c)
{
    return c - 'a';
}
ll mult(ll a, ll b)
{
    ll res = a * b - (ll) ((ld) a * b / MOD) * MOD;
    if (res < 0)
    {
        res += MOD;
    }
    if (res >= MOD)
    {
        res -= MOD;
    }
    return res;
}
ll gcd (ll a, ll b, ll & x, ll & y)
{
    if (a == 0)
    {
        x = 0LL; y = 1LL;
        return b;
    }
    ll x1, y1;
    ll d = gcd (b%a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}
long long poww(long long a, long long b)
{
    long long res = 1;
    a %= MOD;
    while (b > 0)
    {
        if (b % 2) res = mult(a, res);
        a = mult(a, a);
        b >>= 1;
    }
    return res % MOD;
}
ll inv(ll a)
{
    return poww(a , MOD - 2);
}
ll ans = 0;



ll fact[N] , ifact[N];
ll cnk(ll n , ll k)
{
    ll res = mult(fact[n], ifact[k]);
    res = mult(res, ifact[n - k]);
    return res;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    MOD = 998244353;
    srand(time(0));
    long long n , a , b , k;
    cin >> n >> a >> b >> k;
    ll res = 0;
    ll c = a + b;
    ll d = 0;
    fact[0] = 1;
    ifact[0] = 1;
    for(int i = 1; i <= n; i++)
    {
        fact[i] = mult(fact[i - 1], i);
        ifact[i] = inv(fact[i]);
    }
    for (int i = 0; i <= n && k >= 0; i++ , k = k - a)
    {
        if(k % b || k / b > n) continue;
        else
        {
       //     cout << n << " " << i << " " << cnk(n , i) << "\n";
            sum(ans,
                mult(cnk(n , i), cnk(n , k / b)));
        }
    }
                cout << (long long)ans << "\n";
    return 0;
}


Measured memory_bytes: 12544
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vpii> vvpii;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int w, h;
  while (cin >> w >> h, w) {
    vvi a(h, vi(w - 1)), b(h - 1, vi(w));
    rep(i, 2 * h - 1) {
      if (even(i)) rep(j, w - 1) cin >> a[i / 2][j];
      if (odd(i)) rep(j, w) cin >> b[i / 2][j];
    }
    queue<tuple<int, int, int>> q;
    q.emplace(0, 0, 1);
    vvi visited(h, vi(w));
    while (q.size()) {
      int i, j, d;
      tie(i, j, d) = q.front();
      q.pop();
      if (visited[i][j]) continue;
      visited[i][j] = true;
      if (i == h - 1 && j == w - 1) {
        cout << d << endl;
        goto next;
      }
      if (i > 0 && !b[i - 1][j]) q.emplace(i - 1, j, d + 1);
      if (j > 0 && !a[i][j - 1]) q.emplace(i, j - 1, d + 1);
      if (i < h - 1 && !b[i][j]) q.emplace(i + 1, j, d + 1);
      if (j < w - 1 && !a[i][j]) q.emplace(i, j + 1, d + 1);
    }
    cout << 0 << endl;
  next:;
  }
}

Measured memory_bytes: 3072
#include <stdio.h>
int main(void)
{
    int i,n,d,cnt,s=0,sum=0;
    int max=0,min=1000;
 
    scanf("%d",&n);
    
    while(n!=0){
        sum=0;
        max=0;
        min=1000;
        cnt=n;
        while(cnt>0){
            scanf("%d",&s);
            sum+=s;
            if(s>max)   max=s;
            if(s<min)   min=s;
//            printf("%d %d %d \n",max,min,sum);  
            cnt--;
        }
    s=(sum-max-min)/(n-2);
    printf("%d\n",s);
    scanf("%d",&n);
    }

    return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb emplace_back
typedef pair<int,int> pi;

int n,ans;
map<int,int> mp;

int main() {
	ios_base::sync_with_stdio(0); 
	cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; ++i) {
		int a; cin >> a;
		++mp[a], ++mp[a-1], ++mp[a+1];
	}
	for (auto i: mp) {
		ans = max(i.second, ans);
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 7904
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main(void){
	int n;
	int a[210]={};
	int b[210]={};
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> a[i];
		int cnt=0;
		while(a[i]%2==0){
			cnt++;
			a[i]=a[i]/2;
		}
		b[i]=cnt;
	}
	int mina=10000000;
	for(int i=0; i<n; i++){
		mina = min(mina, b[i]);
	}
	cout << mina << endl;


	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;
ll n, a[100010], b[100010], ans;
map<ll, ll> mp;
int main(void){
    // Your code here!
    cin >> n;
    for (ll i = 0; i < n; i++){
        cin >> a[i];
        b[i] = a[i];
    }
    sort(b, b + n);
    for (ll i = 0; i < n; i++){
        mp[b[i]] = i;
    }
    for (ll i = 0; i < n; i++){
        if (mp[a[i]] % 2 && i % 2 == 0) ans++; 
    }
    cout << ans << endl;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ll long long
#define mp make_pair
using namespace std;
int usable[1000009];
int main(){
	int n,k;
	vector<ll> a,bsum,num;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		a.pb(x);
	}
	bsum.pb(0);
	for(int i=0;i<n;i++){
		bsum.pb(bsum[i]+a[i]);
	}
	for(int i=1;i<=n;i++){
		for(int j=0;j<i;j++){
			num.pb(bsum[i]-bsum[j]);
		}
	}
	ll ans = 0;
	for(int i=63;i>=0;i--){
		int cnt = 0;
		for(int j=0;j<num.size();j++){
			if(usable[j] == 0){
				if( ( (num[j])>>i ) % 2 == 1){
					cnt++;
				}
			}
		}
		if(cnt>=k){
			ans += (ll)1<<i;
			for(int j=0;j<num.size();j++){
				if( ( (num[j])>>i ) % 2 == 0){
					usable[j] = 1;
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
    ll n, a, b, c, d, e;
    cin >> n >> a >> b >> c >> d >> e;

    ll neck = min(a, min(b, min(c, min(d, e))));
    //cout << neck << endl;
    double ceil = n / (neck*1.0);
    //cout << ceil << endl;
    ll ans;
    if((ceil-(ll)ceil) > 0) ans = (ll)ceil + 1;
    else ans = (ll)ceil;

    ans += 4;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <cstdlib>
#define NMAX 10000
#define MMAX 10000
using namespace std;
int main(){
	int A = 0;
	string S;
	char j;
	cin >> S;
	j = S[0];
	for (int i = 1; i < S.size(); ++i)
	{
		if(S[i] != j){
			A++;
			j = S[i];
		}
	}
	cout << A << "\n";
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main () {
    long long A, B, C;
    cin >> A >> B >> C;
    if ((A % 2) * (B % 2) * (C % 2) == 0) {
        puts("0");
    }
    else {
        cout << min({A*B, B*C, C*A}) << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
#include <deque>
#include <queue>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int a, b, c, x, ans = 0;
    cin >> a >> b >> c >> x;
    for (int i = 0 ; i <= a ; i++) {
    	for (int j = 0 ; j <= b ; j++) {
    		for (int k = 0 ; k <= c ; k++) {
    			if (500 * i + 100 * j + 50 * k == x) ans++; 
			}
		}
	}  
    cout << ans;
}

Measured memory_bytes: 3596
#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 n;
	cin >> n;

	vector<int> h(n);
	rep(i, n) cin >> h[i];

	int mx = 0;
	int ans = 0;
	rep(i, n){
		if(h[i] >= mx){
			mx = h[i];
			ans++;
		}
	}

	cout << ans << endl;
}


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

using namespace std;

void solve()
{
    int n, m;
    cin >> n >> m;
    vector<vector<long>> dp(n, vector<long>(n, 1e15));
    while (m--)
    {
        int s, t;
        long d;
        cin >> s >> t >> d;
        dp[s][t] = d;
    }
    for (int k = 0; k < n; k++)
    {
        dp[k][k] = 0;
    }
    for (int k = 0; k < n; k++)
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
            {
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
            }
    for (int k = 0; k < n; k++)
    {
        if (dp[k][k] < 0)
        {
            cout << "NEGATIVE CYCLE\n";
            return;
        }
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if (dp[i][j] >= 1e12)
            {
                cout << "INF";
            }
            else
            {
                cout << dp[i][j];
            }
            cout << " \n"[j == n - 1];
        }
    }
}

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



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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using v = vector<T>;
template <class T>
using vv = v<v<T>>;
#define ALL(c) (c).begin(), (c).end()

using Graph = vv<int>;
v<bool> seen;

int dfs(const Graph &G, int v)
{
    seen[v] = true;
    bool all = true;

    for (int i = 0; i < seen.size(); i++)
    {
        if (!seen[i])
            all = false;
    }

    if (all)
        return 1;

    
    int ans = 0;
    for (auto next_v : G[v])
    {
        if (seen[next_v])
            continue;
        ans += dfs(G, next_v);
        seen[next_v] = false;
    }
    return ans;
}

int main()
{
    int N, M;
    cin >> N >> M;
    Graph G(N);

    for (int i = 0; i < M; i++)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    seen.assign(N, false);

    cout << dfs(G, 0) << endl;

    return 0;
}

Measured memory_bytes: 3608