akhauriyash/Code-Regression huggingface dataset:
// in the name of Allah

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define pb push_back
#define ll long long
#define double long double
#define sz(x) ((int) (x.size()))

#define fr first
#define se second

const ll mod = 998244353;

ll add(ll a, ll b) {
	a += b;
	if(a >= mod) return a - mod;
	return a;
}

ll mul(ll a, ll b) {
	a *= b;
	if(a >= mod) return a % mod;
	return a;
}

ll power(ll a, ll b) {
	if(b == 0) return 1;
	ll p = 1;
	while(b) {
		if(b&1) p = mul(p, a);
		a = mul(a, a);
		b /= 2;
	}
	return p;
}

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

	int n, k;
	cin >> n >> k;
	vector <int> v;
	for(int i=1; i<=n; i+=2) v.pb(i);
	cout << ((sz(v) >= k) ? "YES" : "NO") << endl;
	return 0;
}

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

int main() {
  int N, M, C;
  cin >> N >> M >> C;
  int res = 0;
  vector<int> B(M);
  for (int i = 0; i < M; ++i) cin >> B[i];
  for (int i = 0; i < N; ++i) {
    int sum = C;
    for (int j = 0; j < M; ++j) {
      int a; cin >> a;
      sum += a * B[j];
    }
    if (sum > 0) ++res;
  }
  cout << res << endl;
}

Measured memory_bytes: 3580
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <time.h>
#include <iomanip>
#include <thread>
#include <atomic>
#include <mutex>
#include <future>
#define double long double
#define int long long
#define low lower_bound
#define upp upper_bound
#define mod (int)1e9+7
#define inf (int)1e16
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define vsort(vec) sort(all(vec))
#define vrever(vec) reverse(all(vec));
#define vunsort(vec) vsort(vec); vrever(vec);
#define bisea binary_search
#define cend cout<<endl;
#define P pair<int,int>
#define prique priority_queue<P,vector<P>,greater<P>>
using namespace std;
signed main() {
	int n;
	cin >> n;
	int v[22], c[22];
	rep(i, n) {
		cin >> v [i];
	}
	rep(i, n) {
		cin >> c[i];
	}
	int ans = 0;
	rep(i, (1 << n)) {
		int cnt = 0;
		rep(j, n) {
			if ((i >> j) & 1) {
				cnt += v[j] - c[j];
			}
		}
		ans = max(ans, cnt);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
double path[10][2];
int num[10];
bool vis[10];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        num[i]=i;
    for(int i=0;i<n;i++)
        scanf("%lf%lf",&path[i][0],&path[i][1]);
    double result=0;
    do{
        for(int i=1;i<n;i++)
        {
            result+=sqrt((path[num[i]][0]-path[num[i-1]][0])*(path[num[i]][0]-path[num[i-1]][0])+(path[num[i]][1]-path[num[i-1]][1])*(path[num[i]][1]-path[num[i-1]][1]));
        }
    }while(next_permutation(num,num+n));
    for(int i=2;i<=n;i++)
        result/=i;
    printf("%.6f",result);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")

using namespace std;

#define li long long int
#define ld double_t
#define mod (li)(1e9+7)
const int MX1=1e5+5;
const int MX2=1e6+5;
const li inf=1e18;

li power(li a,li b){li res=1;while(b){if(b%2)res=(res*a)%mod;
a=(a*a)%mod;b/=2;}return res;}

li mmi(li a){return power(a,mod-2);}

li cntbit(li n){li cnt=0;while(n){n&=(n-1);cnt++;}return cnt;}

int n,ma,mb,a[45],b[45],c[45],dp[45][405][405];

int f(int idx,int num,int den){
	if(idx>n){
		if(num==0 or den==0) return (int)(1e5);
		int g=__gcd(num,den);
		num/=g;
		den/=g;
		if(num==ma and den==mb) return 0;
		return (int)(1e5);
	}
	if(dp[idx][num][den]!=-1) return dp[idx][num][den];
	int ans=1e5;
	ans=min(ans,c[idx]+f(idx+1,num+a[idx],den+b[idx]));
	ans=min(ans,f(idx+1,num,den));
	return dp[idx][num][den]=ans;
}

void solve(){
	cin>>n>>ma>>mb;
	for(int i=1;i<=n;i++){
		cin>>a[i]>>b[i]>>c[i];
	}
	memset(dp,-1,sizeof(dp));
	int ans=f(1,0,0);
	if(ans==(int)(1e5)) ans=-1;
	cout<<ans;
}

int main(){
	ios_base::sync_with_stdio(false);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

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

using ll = long long;
const int N = 110 , M = 1e5 + 5 , INF = 1e9;

ll mem[N][M];
ll   v[N];
int  w[N];
int n , W;

ll dp(int i , int sum){
    if(sum > W)return -INF;

    if(i == n){
        return 0;
    }

    if(mem[i][sum] != -1)return mem[i][sum];

    return mem[i][sum] = max(v[i] + dp(i + 1 , sum + w[i]) , dp(i + 1 , sum));
}

main(){
    scanf("%d %d" , &n , &W);

    for(int i = 0 ; i < n ; i ++){
        scanf("%d %lld" , &w[i] , &v[i]);
    }

    memset(mem , -1 , sizeof mem);
    printf("%lld\n" , dp(0 , 0));
}


Measured memory_bytes: 86144
//Gather the Maps!
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

int N, F;
int date[50][30];
ll dp[50][50];

int main(){
  while(cin >> N, !(N==0)){
    //?????????
    memset(date, 0, sizeof(date));
    memset(dp, 0, sizeof(dp));
    //??\???
    for(int i=0; i<N; i++){
      cin >> F;
      for(int j=0; j<F; j++){
	int tmp;
	cin >> tmp;
	date[i][tmp-1] = 1; //???
      }
    }

    //dp?????????
    for(int i=0; i<N; i++)
      dp[i][i]=1;

    bool flag=false;
    for(int j=0; j<30; j++){
      for(int i=0; i<N; i++){
	if(date[i][j]==1){
	  for(int k=0; k<N; k++){
	    if(date[k][j]==1){
	      for(int l=0; l<N; l++){
		if(dp[k][l]==1){
		  dp[i][l]=1;
		}
	      }
	    }
	  }
	}
      }

      for(int i=0; i<N; i++){
	for(int k=0; k<N; k++){
	  if(dp[i][k]==0)break;
	  if(k==N-1){
	    flag=true;
	    break;
	  }
	}
      }
      if(flag){cout<<j+1<<endl; break;}
    }
    if(!flag){cout<<-1<<endl;}
  }
  return 0;
}

Measured memory_bytes: 1192
import math

def main():
    a, b = input().split()
    a, b = int(a), int(b)

    ans = []
    for i in range(1, 1251):
      tax8 = math.floor(i * 0.08)
      tax10 = math.floor(i * 0.10)
      if tax8 == a and tax10 == b:
        ans.append(i)

    if len(ans) == 0:
      print(-1)
    else:
      print(min(ans))

if __name__ == '__main__':
    main()

Measured memory_bytes: 38512
def solv(k, x)
  min_cost = nil

  x.size.times do |i|
    left = x[i]
    right = x[i+k-1]

    break unless right

    left = 0 unless left.negative?
    right = 0 if right.negative?

    left = left.abs
    right = right.abs

    cost = (left < right) ? (left*2 + right) : (left + right*2)

    min_cost = cost unless min_cost
    if cost < min_cost
      min_cost = cost
    end
  end

  min_cost
end

#nk = [5, 3]
#x = [-30, -10, 10, 20, 50]
#puts solv(nk[1], x)
#exit 1

kn = gets.chomp.split(' ').map(&:to_i)
x = gets.chomp.split(' ').map(&:to_i)

puts solv(kn[1], x)




Measured memory_bytes: 9484
N = int(input())

pn=[2];A=100
for L in range(3,A):
  chk=True
  for L2 in pn:
    if L%L2 == 0:chk=False
  if chk==True:pn.append(L)

mul = [0 for i in range(101)]
for i in range(1,N+1):
  for j in pn:
    if j > i:
      break
    temp = i
    while True:
      if temp%j == 0:
        temp /= j
        mul[j] += 1
        continue
      else:
        break
        
prime_num = []
for index, num in enumerate(mul):
  if num != 0:
    prime_num.append([index,num])

ans = 0
# 4,4,2の取り出し
from itertools import combinations
nums442 = list(combinations(prime_num,3))
for num in nums442:
  if num[0][1]>=2 and num[1][1]>=4 and num[2][1]>=4:
    ans += 1
  if num[0][1]>=4 and num[1][1]>=2 and num[2][1]>=4:
    ans += 1
  if num[0][1]>=4 and num[1][1]>=4 and num[2][1]>=2:
    ans += 1

# 14,4の取り出し
nums14_4 = list(combinations(prime_num,2))
for num in nums14_4:
  if num[0][1]>=14 and num[1][1]>=4:
    ans += 1
  if num[0][1]>=4 and num[1][1]>=14:
    ans += 1

# 24,2の取り出し
nums24_2 = list(combinations(prime_num,2))
for num in nums24_2:
  if num[0][1]>=24 and num[1][1]>=2:
    ans += 1
  if num[0][1]>=2 and num[1][1]>=24:
    ans += 1
    
# 74の取り出し
for num in prime_num:
  if num[1] >= 74:
    ans += 1
    
print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll n, k;
    cin >> n >> k;

    vector<P> p(n);
    rep(i, n) {
        ll a, b;
        cin >> a >> b;
        p[i] = make_pair(a, b);
    }
    sort(all(p));

    ll cnt = 0;
    rep(i, n) {
        cnt += p[i].second;
        if(cnt >= k) {
            out(p[i].first);
            re0;
        }
    }

    re0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 3000;
int dp[maxn][4][2];
char N[maxn];
string s;
int k, len;

inline int dfs (int idx, int c0, int flag) {
  if (c0 > k) return 0; // hit max number of 0s
  if (idx > len) return c0 == k; // out of bounds, return 1 if capacity is met
  if (dp[idx][c0][flag] != -1) return dp[idx][c0][flag];
  int ans = 0;
  int bound = (flag == 1) ? N[idx] - '0' : 9;
  for (int i = 0; i <= bound; i++) {
    ans += dfs(idx + 1, c0 + (i != 0), flag && (i == bound));
  }
  return dp[idx][c0][flag] = ans;
}

signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  memset(dp, 255, sizeof(dp));

  // index the number N (string) from 1
  cin >> s;
  len = s.size();
  for (int i = 0; i < len; i++) N[i + 1] = s[i];
  len = strlen(N + 1);
  cin >> k;

  // start at 1st char, count of 0s is 0, flag set (bounded)
  cout << dfs(1, 0, 1) << endl;
  return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#define H 12
#define W 12

void Move(int i,int j,int movex[],int movey[],char data[H][W]){
  int k;
  if (0<=j && j<W && 0<=i && i<H){
    if (data[i][j]=='0')
      return ;
    else
      data[i][j]='0';
  }else
    return ;

  for (k=0;k<4;k++)
    Move(i+movey[k],j+movex[k],movex,movey,data);
}

int main(){
  int i,j;
  int movex[]={0,0,1,-1},movey[]={-1,1,0,0};
  char data[H][W];
  while (1){
  for (i=0;i<H;i++)
    if (scanf("%s",&data[i])==EOF) return 0;
  int cnt=0;
  for (i=0;i<H;i++)
    for (j=0;j<W;j++)
      if (data[i][j]=='1'){
        cnt++;
        Move(i,j,movex,movey,data);
      }

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

}

Measured memory_bytes: 544
#include <stdio.h>
const int maxn = 100005;
#define ll long long
ll a[maxn];
ll dis[maxn];


int main()
{
	ll n,i;
	scanf("%lld",&n);
	ll sum = 0;
	for (i = 1; i <= n; ++i)
	{
		scanf("%lld",&a[i]);
		if(i >= 2)
			dis[i] = a[i] - a[i-1];
		sum += a[i];
	}
	dis[1] = a[1] - a[n];
	if( sum % (n*(n+1)/2) )
	{
		printf("NO\n");
		return 0;
	}
	else
	{
		sum /= (n*(n+1)/2);
		ll ans = 0;
		for (i = 1; i <= n; ++i)
		{
			if( (sum - dis[i] < 0) || ((sum - dis[i]) % n) )
			{
				printf("NO\n");
				return 0;
			}
			else
				ans += (sum - dis[i]) / n;
		}
		if(ans != sum)
			printf("NO\n");
		else
			printf("YES\n");
	}
	return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
const long long MOD = 1000000007;
const int INF = INT_MAX / 2;
const long double PI = 3.1415926;
#define FOR(i, r, n) for(int i=(ll)(r); i<(ll)(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ALL(r) r.begin(), r.end()
#define ll long long int
#define vci vector<ll>
#define vcs vector<string>
#define vcp vector<pair<ll, ll>>
#define vct vector<tuple<ll, ll, ll>>
using namespace std;
//vector<vector<ll>> vv(n, vector<ll>(n));

typedef int Weight;
struct Edge
{
	int from, to; Weight cost;
	bool operator < (const Edge& e) const { return cost < e.cost; }
	bool operator > (const Edge& e) const { return cost > e.cost; }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
void add_edge(Graph &g, int from, int to, Weight cost)
{
	g[from].push_back(Edge{ from, to, cost });
}

int main()
{
	ll h, w, n;
	cin >> h >> w >> n;
	vector<vector<ll>> vv(h, vector<ll>(w, 0));
	vcp v;
	REP(i, n)
	{
		ll t;
		cin >> t;
		v.emplace_back(t, i + 1);
	}
	sort(ALL(v), greater<pair<ll, ll>>());
	REP(i, h)
	{
		if (i % 2)
		{
			for (int j = w - 1; j >= 0; --j)
			{
				if (v.front().first) {
					vv[i][j] = v.front().second;
					v.front().first--;
				}
				else
				{
					v.erase(v.begin());
					j++;
				}
			}
		}
		else
		{
			REP(j, w)
			{
				if (v.front().first) {
					vv[i][j] = v.front().second;
					v.front().first--;
				}
				else
				{
					v.erase(v.begin());
					j--;
				}
			}
		}
	}
	REP(i, h) {
		REP(j, w)
		{
			cout << vv[i][j] << (j != w - 1 ? " " : "");
		}
		cout << endl;
	}
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
int main(){
	int z;
	cin>>z;
	int ar[z];
	for(int i=0;i<z;i++){
		cin>>ar[i];
	}
	int cnt=0;
	for(int i=1;i<z-1;i++){
		int ma=max({ar[i],ar[i-1],ar[i+1]});
		int mi=min({ar[i],ar[i-1],ar[i+1]});
		if(ma!=ar[i]&&mi!=ar[i]){
			cnt++;
		}
	}
	cout<<cnt<<endl;
}

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

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

lint lcm(lint x, lint y) { return x/gcd(x,y)*y; }


int main() {
  string sa,sb,sc; cin >> sa >> sb >> sc;
  int index_a=0,index_b=0,index_c=0,size_a=(int)sa.size(),size_b=(int)sb.size(),size_c=(int)sc.size();

  char next='a';
  while(true) {
    if(next == 'a') {
      if(index_a > size_a-1) { cout << "A\n"; break; }
      else { next = sa[index_a]; index_a++; }
    } else if(next == 'b') {
      if(index_b > size_b-1) { cout << "B\n"; break; }
      else { next = sb[index_b]; index_b++; }
    } else if(next == 'c') {
      if(index_c > size_c-1) { cout << "C\n"; break; }
      else { next = sc[index_c]; index_c++; }
    }
  }

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() /4;
const ll linf = numeric_limits<ll>::max() /4;
const ull ulinf = numeric_limits<ull>::max()/4;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
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; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

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



int main(){
    int a,b;
    cin >> a >> b;
    a += b;
    P((a+1)/2);
	return  0;
}

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

int main() {
  char a,b;
  cin >>a >>b;
  if(a=='H'){
    cout <<b <<endl;
  }
  else{
    if(b=='H'){
      cout <<"D" <<endl;
    }
    else{
      cout <<"H" <<endl;
    }
  }
}

Measured memory_bytes: 256
<?php
$polygon=trim(fgets(STDIN));
$side=explode(" ",trim(fgets(STDIN)));

rsort($side);
$longest=$side[0];

unset($side[0]);
$otherSum=array_sum($side);

if($longest<$otherSum){
    echo "Yes";
}else{
    echo "No";
}
?>

Measured memory_bytes: 4728
#include <iostream>
#include <string>

using namespace std;

int main() {
  string str;
  cin >> str;
  if (str == "Sunny")
    cout << "Cloudy" << endl;
  else if (str == "Cloudy")
    cout << "Rainy" << endl;
  else
    cout << "Sunny" << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;

class Program {

    static void Main (string[] args) {
        int N = int.Parse (Console.ReadLine ());
        N %= 10;
        if (N == 2 || N == 4 || N == 5 || N == 7 || N == 9) {
            Console.WriteLine ("hon");
        } else if (N == 0 || N == 1 || N == 6 || N == 8) {
            Console.WriteLine ("pon");
        } else {
            Console.WriteLine ("bon");
        }
    }
}
//dotnet run --project test

Measured memory_bytes: 27536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
ll rui(ll a,ll b){
    ll ans=1;
    while(b>0){
        if(b&1) ans=ans*a%mod;
        a=a*a%mod;
        b/=2;
    }
    return ans;
}

ll comb(ll a,ll b){
    ll ans=1;
    for(ll i=a;i>a-b;i--){
        ans=ans*i%mod;
    }
    for(ll i=1;i<=b;i++){
        ans=(ans*rui(i,mod-2))%mod;
    }
    return ans;
}

int main(){
  ll n,m; cin>>n>>m;
  cout<<comb(n,2)+comb(m,2);
}

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

using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vvvd = vector<vector<vector<double>>>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pint = pair<int, int>;
using Graph = vvi;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

bool cmp(pint a, pint b) {return a.second < b.second;}
void YN(bool flg) {cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg) {cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg) {cout<<(flg?"yes":"no")<<'\n';}

int main() {
    string s, t;
    cin >> s >> t;

    int idx = -1;
    bool can = false;
    rep(i, s.size() - t.size() + 1) {
        bool flg = true;
        rep(j, t.size()) {
            if(s[i + j] == t[j] || s[i + j] == '?') continue;
            flg = false;
        }
        if(flg) {
            idx = i;
            can = true;
        }
    }
    if(!can) {
        cout << "UNRESTORABLE" << endl;
        return 0;
    }

    rep(i, t.size()) {
        if(s[i + idx] == '?') s[i + idx] = t[i];
    }
    rep(i, s.size()) {
        if(s[i] == '?') s[i] = 'a';
    }

    cout << s << endl;

    return 0;
}

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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

#define	Rep0(i, n)	for (auto i=0; i<n; i++)
#define	Rep1(i, n)	for (auto i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

void unique_count(vector<int> &a, vector<vector<int>> &b) {
	// erase(b.begin(), b.end());
	for (int i=0; i<a.size(); i++)
		if ((i>0)&&(a.at(i)==a.at(i-1)))
			b.back().at(1)++;
		else
			b.push_back({a.at(i), 1});
	return;
}

int	main() {
	int A=2019;
	string S;
	cin >>S;
	int N=S.size();
	vector<int> SS(N+1, 0);
	Rep1(i, N)
		SS.at(i)=S.at(i-1)-'0';
	vector<int> M(N+1, 0);
	int ss=0;
	Rep1(i, N) {
		ss *=10;
		ss +=SS.at(i);
		ss %=A;
		M.at(i)=ss;
	}
	ss=1;
	for (auto i=N; i>0; i--) {
		M.at(i) *=ss;
		M.at(i) %=A;
		ss *=10;
		ss %=A;
	}
	Sort(M);
	vector<vector<int>> B;
	unique_count(M, B);
	int SSS=0;
	Rep0(i, B.size()) {
		int BB=B.at(i).at(1);
		SSS+=BB*(BB-1)/2;
	}
	cout <<SSS <<endl;
	return 0;
}



Measured memory_bytes: 5144
a = int(input())
b = int(input())
c = int(input())
x = int(input())

# if 500 then
# a = 1, b = 5, b = 4,c = 2, b = 3, c = 4...

sum = 0
count = 0

for i in range(a + 1):
  for j in range(b + 1):
    for k in range(c + 1):
      sum = 500 * i + 100 * j + 50 * k
      if sum == x:
        count += 1

print(count)

Measured memory_bytes: 3064
n,m = map(int,input().split())
l = [list(map(int,input().split())) for i in range(n)]
l.sort()

count = 0
ans = 0
for i in range(n):
    if count + l[i][1] >= m:
        ans += (m-count)*l[i][0]
        print(ans)
        exit()
    else:
        count += l[i][1]
        ans += l[i][1]*l[i][0]

Measured memory_bytes: 27756
#include<iostream>
#include<queue>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>

using namespace std;

int main(){
    int a, b;
    cin >> a >> b;
    if(abs(a-b)%2==1){
        cout << "IMPOSSIBLE" << endl;
    }
    else{
        cout << min(a,b) + abs(a-b)/2 << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define itn int
#define nibu(K,x) binary_search(K.begin(),K.end(),x)
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define si(x) x.size()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define out(x) cout<<x<<endl
#define in(x) cin>>x
#define maxx(a,b,c) max(a,max(b,c))
#define minn(a,b,c) min(a,min(b,c))
using pii = pair<int,int>;
using psi = pair<string,int>;
using pis = pair<int,string>;
using ll = long long;
using vl = vector<ll>;
using vs = vector<string>;


int main() {
 ll a, b,c;
  cin >>a >>b>>c;
if(a%2==0||b%2==0||c%2==0) out(0);
  else out(minn(b*c,a*c,b*a));
}
  


Measured memory_bytes: 256
package main

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

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	max := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}

	var n, sz, v int
	Fscan(in, &n, &sz)
	sum := make([]int, n+1)
	for i, s := range sum[:n] {
		Fscan(in, &v)
		sum[i+1] = s + v + 1
	}
	ans := 0
	for i := 0; i+sz <= n; i++ {
		ans = max(ans, sum[i+sz]-sum[i])
	}
	Fprintf(out, "%.12f", float64(ans)/2)
}

func main() { run(os.Stdin, os.Stdout) }


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

int gcd(int a,int b){	
	while(b){
		int c=a%b;
		a=b;
		b=c;
	}
	return a;
}

int main() {
	
	int a,b;
	
	cin>>a>>b;
	
	int c = gcd(a,b);
	
	cout<<c<<endl;
	
	return 0;
}

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

#define pb     push_back
#define mp     make_pair
#define all(v) v.begin() , v.end()
#define allr(v) v.rbegin(), v.rend()
const ll INF =  0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int MOD = 1e9+7;
const int MAX = 1e5+5;

int n, t, x, y, X, Y, T;

int main(int argc, char const *argv[]){
    ios_base::sync_with_stdio(false);

    // #ifndef ONLINE_JUDGE
    // freopen("in","r",stdin);
    // freopen("out","w",stdout);
    // #endif

    scanf("%d\n", &n);
    X = 0;
    Y = 0;
    T = 0;

    while(n--){
        scanf("%d %d %d" , &t, &x, &y);
        if( ((t-T) >= abs(x - X) + abs(y - Y)) && (((t-T) - abs(x - X) - abs(y - Y))%2 == 0)){
            T = t;
            X = x;
            Y = y;
        }
        else{
            printf("No");
            return 0;
        }
    }
    printf("Yes");
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

#define Q   200000

void pushBack(int x);
void randomAccess(int p);
void popBack(void);

int A[Q];
int Ap;

int main(void) {
  int q, op, x, p;

  scanf("%d", &q);

  while(q--) {
      scanf("%d", &op);

      switch(op) {
        case 0: scanf("%d", &x);
                pushBack(x);
                break;
        case 1: scanf("%d", &p);
                randomAccess(p);
                break;
        case 2: popBack();
                break;
      }
  }

  return 0;
}

void pushBack(int x) {
  A[Ap] = x;
  ++Ap;
}

void randomAccess(int p) {
  printf("%d\n", A[p]);
}

void popBack(void) {
  A[Ap] = 0;
  --Ap;
}



Measured memory_bytes: 2524
#include<iostream>
#include<list>

int main(){
    std::string S;
    std::list<char> lis;
    std::cin >> S;
    for(int i = 0; i < S.size(); i++){
        if(S[i] == 'B' && lis.size() != 0) lis.pop_back();
        else if(S[i] != 'B') lis.push_back(S[i]);
    }

    for(auto c : lis){
        std::cout << c;
    }
    std::cout << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>

using namespace std;

int main(void) {
	int n;
	scanf("%d", &n);
	int a = 0;
	int b = -1;
	int mag = 0;
	for (int i = 0; i < n; i++) {
		scanf("%d", &a);
		if (a == b) {
			mag++;
			b = -1;
		}
		else {
			b = a;
		}
	}
	printf("%d", mag);
	return 0;
}

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

using namespace std;

typedef long long ll;
 

int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	
	int l, r, d;

	cin >> l >> r >> d;
	if (l%d != 0){
		l += d-(l%d);
	}
	int ans = 0;
	for (int i = l; i <= r; i+=d)
	{
		/* code */
		ans ++;
	}
	cout << ans << "\n";

	return 0;
}



Measured memory_bytes: 3608
n = int(input())
d = [list(map(int, input().split())) for _ in range(n)]

ans = "No"
for i in range(n - 2):
    bl = True
    for j in range(3):
        bl = bl and (d[i+j][0] == d[i+j][1])

    if bl:
        ans = "Yes"

print(ans)


Measured memory_bytes: 9188
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>

using namespace std;

bool is_even(int w, int h, int x, int y) {
    return ((w-x == x) && (h-y == y));
}

int main(int argc, char **argv) {
    int w, h, x, y;
    cin >> w >> h>> x >> y;
    if (is_even(w, h, x, y)) {
        cout << setprecision(9) << (double)w * h / (double)2<< " " << 1 <<  endl;
    } else {
        cout << setprecision(9) << (double)w * h / (double)2<< " " << 0 <<  endl;
    }

    return 0;
}

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

#define ALL(x) x.begin(), x.end()

using namespace std;

typedef long long ll;
typedef vector<int> vi;

void solve(void) {

	int n, k;
	cin >> n >> k;

	vi A(n);
	vi dp(n, INT_MAX);

	for(int& x : A) {
		cin >> x;
	}

	dp[0] = 0;
	for(int i = 0; i < n; i++) {
		for(int j = i + 1; j <= min(i + k, n - 1); j++) {
			dp[j] = min(dp[j], dp[i] + abs(A[i] - A[j]));
		}
	}

	cout << dp[n-1] << '\n';

}

int main(void) {

	solve();
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>

int main(void){
    int k;
    std::string s;
    std::cin >> k >> s;
    int ss = s.size();
    if(ss <= k) std::cout << s << std::endl;
    else{
	for(int i = 0; i < k; i++){
	    std::cout << s[i];
	}
	std::cout << "..." << std::endl;
    }
    return 0;
}


Measured memory_bytes: 3584
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
#define SENTINEL INT_MAX

int A[500000],c=0;

void Merge(int left, int mid, int right){
	int i, j, k;
	int n1 = mid - left;
	int n2 = right - mid;
	int L[300000], R[300000];

	for (i = 0; i < n1;i++){
		L[i] = A[left + i];
	}
	for (i = 0; i < n2;i++){
		R[i] = A[mid + i];
	}
	L[n1] = SENTINEL;
	R[n2] = SENTINEL;
	i = 0;
	j = 0;
	for (k = left; k < right;k++){
		c++;
		if (L[i] <= R[j]){
			A[k] = L[i];
			i = i + 1;
		}else{
			A[k] = R[j];
			j = j + 1;
		}
	}
}

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

int main(){
	int i, j, k;
	scanf("%d",&i);
	for (j = 0; j < i;j++){
		scanf("%d",&A[j]);
	}

	Merge_Sort(0,j);

	
	for (i = 0; i < j; i++){
		printf("%d", A[i]);
		if (i < j - 1){
			printf(" ");
		}
	}
printf("\n%d\n",c);
return 0;
}

Measured memory_bytes: 4708
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
const int mod=1000000007;
int fpow(int x,int y)
{
	if(y==0)
		return 1;
	int ret=fpow(x,y>>1);
	ret=(long long)ret*ret%mod;
	if(y&1)
		ret=(long long)ret*x%mod;
	return ret;
}
int dp[44][1<<18];
int main()
{
	int n,x,y,z,cnt,tar,nn,ans=0;
	scanf("%d%d%d%d",&n,&x,&y,&z);
	cnt=x+y+z;
	nn=(1<<cnt+1);
	tar=(((((1<<x)+1)<<y)+1)<<z)+1;
	memset(dp,0,sizeof(dp));
	dp[0][1]=1;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<nn;j++)
			if(dp[i][j]&&(j&tar)!=tar)
				for(int k=1;k<=10;k++)
					(dp[i+1][((j<<k)+1)&(nn-1)]+=dp[i][j])%=mod;
	}
	for(int i=0;i<nn;i++)
		if(dp[n][i]&&(i&tar)!=tar)
			(ans+=dp[n][i])%=mod;
	printf("%d",(fpow(10,n)-ans+mod)%mod);
	return 0;
}

Measured memory_bytes: 45312
import itertools

n, m = map(int, input().split())

nn = [2 for _ in range(0, n)]
mm = [1 for _ in range(0, m)]
nn.extend(mm)

ans = [True for (a, b) in itertools.combinations(nn, 2) if (a + b) % 2 is 0].__len__()
print(ans)


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<queue>
#include<utility>
using namespace std;
int main() {
	long long int n;
	cin >> n;
	long long int count = 0;
	while (n > 0) {
		if (n >= 1 && n <= 9 || n >= 100 && n <= 999 || n >= 10000 && n <= 99999) {
			count++;
		}
		n--;
	}
	cout << count << endl;
}

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

int main()
{
  int n;

  cin >> n;

  if(n <= 3)
    {
cout << "No" << endl;
 return 0;
    }
  
  for(int i=0;i<=100;i++)
    for(int j=0;j<=100;j++)
      {
	if(n == i * 4 + j * 7)
	  {
	    cout << "Yes" << endl;
	    return 0;
	  }
      }

  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define TYPE 4
#define CLASS 13

int main(){
	int num;
	int array[TYPE][CLASS]={};
	char type[4]={'S','H','C','D'};
	std::cin>>num;
	for(int i=0;i<num;i++){
		char c;
		int  n;
		std::cin>>c;
		std::cin>>n;
		for(int j=0;j<TYPE;j++){
			if(c==type[j]){
				array[j][n-1]=1;
			}
		}
	}
	for(int i=0;i<TYPE;i++){
		for(int j=0;j<CLASS;j++){
			if(!array[i][j]){
				std::cout<<type[i]<<" "<<j+1<<std::endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1160
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;

class in {
  int n;
public:
  in() {}
  in(int n_) : n(n_){};
  template <class T> operator T() { T ret; cin >> ret; return ret; }
  template <class T> operator vector<T>() { vector<T> ret(n); for (int i = 0; i < n; i++) cin >> ret[i]; return ret; }
};

template <std::uint_fast64_t Mod> class modint {
  using u64 = std::uint_fast64_t;
public:
  u64 a;
  constexpr modint(const u64 x = 0) noexcept : a(x % Mod) {}
  constexpr u64 val() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept { return modint(*this) += rhs; }
  constexpr modint operator-(const modint rhs) const noexcept { return modint(*this) -= rhs; }
  constexpr modint operator*(const modint rhs) const noexcept { return modint(*this) *= rhs; }
  constexpr modint operator/(const modint rhs) const noexcept { return modint(*this) /= rhs; }
  constexpr bool operator==(const modint rhs) const noexcept { return modint(*this).val() == rhs.val(); }
  modint &operator+=(const modint rhs) noexcept { a += rhs.a; if (a >= Mod) a -= Mod; return *this; }
  modint &operator-=(const modint rhs) noexcept { if (a < rhs.a) a += Mod; a -= rhs.a; return *this; }
  modint &operator*=(const modint rhs) noexcept { a = a * rhs.a % Mod; return *this; }
  modint &operator/=(modint rhs) noexcept { u64 exp = Mod - 2; while (exp) { if (exp % 2) *this *= rhs; rhs *= rhs; exp /= 2; } return *this; }
};
template <std::uint_fast64_t Mod>
ostream& operator<<(ostream& os, const modint<Mod>& m){ return os << m.a; }
const ll mod=(ll)1e9+7;
using mint = modint<mod>;
//}}}

int A[80][80];
int s[80][80][15000];

struct Pos{
  int x;
  int y;
};

int main(){
  int H = in();
  int W = in();
  rep(h, H) rep(w, W) A[h][w] = in();
  rep(h, H) rep(w, W){
    int B = in();
    A[h][w] -= B;
    if(A[h][w] < 0) A[h][w] *= -1;
  }

  s[0][0][A[0][0]] = 1;

  const int kMax = 15000;
  rep(y, H) rep(x, W){
    if(x != W - 1){
      rep(v, kMax){
        if(!s[y][x][v]) continue;
        s[y][x + 1][v + A[y][x + 1]] = 1;
        s[y][x + 1][abs(v - A[y][x + 1])] = 1;
      }
    }

    if(y != H - 1){
      rep(v, kMax){
        if(!s[y][x][v]) continue;
        s[y + 1][x][v + A[y + 1][x]] = 1;
        s[y + 1][x][abs(v - A[y + 1][x])] = 1;
      }
    }
  }

  int ans = 1000000;
  rep(v, kMax){
    if(!s[H - 1][W - 1][v]) continue;
    ans = min(ans, v);
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
    int a, b;
    cin >> a >> b;
    int p1 = a + a - 1;
    int p2 = a + b;
    int p3 = b + b - 1;
    int pmax;
    if(p1 >= p2) pmax = p1;
    else pmax = p2;

    if(pmax >= p3) pmax = pmax;
    else pmax = p3;

    cout << pmax << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int n[5],ans1=0,ans2=0;

int main(){
    while(scanf("%d,%d,%d",&n[0],&n[1],&n[2])!=EOF){
        if(n[0]==n[1])ans1++;
        else if(n[0]*n[0]+n[1]*n[1]==n[2]*n[2])ans2++;
    }
    printf("%d\n%d\n",ans2,ans1);
    return 0;
}


Measured memory_bytes: 2108
#include <bits//stdc++.h>
using namespace std;
int in(void){int x;cin>>x;return x;}
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
#define ll long long int
long long int dx[4]={1,0,-1,0};
long long int dy[4]={0,1,0,-1};
int main() {
	double a,b;
	cin>>a>>b;
	cout<<a/b;
	
	return 0;
}


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

int main(){
    int la, lb, ra, rb;
    cin >> la >> lb >> ra >> rb;
    if(la + lb < ra + rb)cout << "Right" << endl;
    else if(la + lb == ra + rb)cout << "Balanced" << endl;
    else cout << "Left" << endl;
}

Measured memory_bytes: 3536
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

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

    vector<int> a(N, 0);
    vector<int> b(N, 0);
    for(int i = 0; i < N; i++) cin >> a[i];

    int M = 0;
    for(int i = N; i >= 1; i--) {
        int sum = 0;
        for(int j = 2; j * i <= N; j++) sum += b[j*i-1];
        b[i-1] = (a[i-1] + sum) % 2;
        M += b[i-1];
    }

    cout << M << endl;
    for(int i = 0; i < N;i++) {
        if(b[i] == 1) cout << i+1 << " ";
    }

}

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

using namespace std;

long long a,b,n;

long long eval(long long x)
{
	return a*x/b - a*(x/b);
}

int main()
{
	cin >> a >> b >> n;
	long long ans=0;
	for(long long i=0;i<=min(n,a);i++)
		ans=max(ans,a*i/b - a*(i/b));
	for(long long i=1;i*i<=b;i++)
	{
		if(i<=n) ans=max(ans,a*i/b - a*(i/b));
		long long x=b/i;
		if(x<=n) ans=max(ans,a*x/b - a*(x/b));
	}
	for(long long x=max(b-a,0LL);x<=b+a;x++)
		if(x<=n) ans=max(ans,eval(x));
	ans=max(ans,eval(n));
	for(long long x=n;x>=max(0LL,n-2*a);x--)
		ans=max(ans,eval(x));
	cout << ans << endl;
}

Measured memory_bytes: 3636
package main

import "fmt"

func main() {
	var m, n int
	fmt.Scan(&m, &n)
	a := make([][]rune, m+2)
	for i := 0; i < m+2; i++ {
		a[i] = make([]rune, n+2)
		if i == 0 || i == m+1 {
			for j := 0; j < n+2; j++ {
				a[i][j] = '#'
			}
		} else {
			a[i][0], a[i][n+1] = '#', '#'
			var s string
			fmt.Scan(&s)
			for j, r := range s {
				a[i][j+1] = r
			}
		}
	}
	for i := 0; i < m+2; i++ {
		for j := 0; j < n+2; j++ {
			fmt.Printf(string(a[i][j]))
		}
		fmt.Printf("\n")
	}
}


Measured memory_bytes: 640
s = input()
while s != '':
    tmp = s
    s = s.replace('eraser', '')
    s = s.replace('erase', '')
    s = s.replace('dreamer', '')
    s = s.replace('dream', '')
    if s == '':
        print('YES')
    if tmp == s:
        print('NO')
        break

Measured memory_bytes: 3188
n,a,b = map(int,input().split())
if (b - a)%2 == 0:
    x = (b - a)//2
    y = min(max(a-1,b-1),max(n-a,n-b))
    print(min(x,y))
else:
    p = max(a-1,b-1)
    q = max(n-a,n-b)
    r = a-1+1+(b-(a-1)-1-1)//2
    s = n-b+1+(n-(n-b+1)-a)//2
    #print(p,q,r,s)
    print(min(p,q,r,s))

Measured memory_bytes: 3064
var
 i,j,k,x,y,ans:longint;
begin
 read(x,y);
 for i:=0 to x do
  for j:=0 to x do
   begin
    if (y-i-j>=0) and (y-i-j<=x) then inc(ans);
   end;
 writeln(ans);
end.

Measured memory_bytes: 128
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

//Walking Ant
public class Main{

	void run(){
		int[][] move = {{-1,0},{0,1},{1,0},{0,-1}};
		Scanner sc = new Scanner(System.in);
		for(;;){
			int w = sc.nextInt(), h = sc.nextInt();
			if((w|h)==0)break;
			int[][] map = new int[h][w];
			int si = -1, sj = -1;
			for(int i=0;i<h;i++)for(int j=0;j<w;j++){
				map[i][j] = sc.nextInt();
				if(map[i][j]==2){
					si = i; sj = j;
					map[i][j] = 1;
				}
			}
			boolean[][][] u = new boolean[h][w][7];
			u[si][sj][6] = true;
			List<int[]> l = new ArrayList<int[]>();
			l.add(new int[]{si, sj, 6});
			int step = 0;
			int ans = -1;
			while(!l.isEmpty()){
				List<int[]> next = new ArrayList<int[]>();
				for(int[]a:l){
					int i = a[0], j = a[1], hp = a[2];
					if(map[i][j]==3){
						ans = step;
						next.clear();
						break;
					}
					if(hp<=1)continue;
					for(int k=0;k<4;k++){
						int ni = i+move[k][0];
						int nj = j+move[k][1];
						if(0<=ni&&ni<h&&0<=nj&&nj<w&&map[ni][nj]!=0){
							if(map[ni][nj]==4){
								if(u[ni][nj][6])continue;
								u[ni][nj][6] = true;
								next.add(new int[]{ni, nj, 6});
							}
							else{
								if(u[ni][nj][hp-1])continue;
								u[ni][nj][hp-1] = true;
								next.add(new int[]{ni, nj, hp-1});
							}
						}
					}
				}
				step++;
				l = next;
			}
			System.out.println(ans);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

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

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

    int n, capacity; cin >> n >> capacity;
    vector<ll> weights(n), values(n);
  
    for (int i = 0; i < n; i++)
      cin >> weights[i] >> values[i];
  
    vector<vector<ll>> dp(n, vector<ll> (capacity+1));
  
    for (int i = 0; i < n; i++)
      dp[i][0] = 0;
    for (int i = 0; i <= capacity; i++) {
      if (weights[0] <= i)
        dp[0][i] = values[0];
    }
  
    for (int i = 1; i < n; i++) {
     for (int w = 1; w <= capacity; w++) {
      if (weights[i] > w) 
        dp[i][w] = dp[i-1][w];
      else
        dp[i][w] = max(dp[i-1][w], values[i] + dp[i-1][w-weights[i]]);
     }
    }
    
    cout << dp[n-1][capacity];
    return 0;
}


Measured memory_bytes: 82224
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007

//read question carefully!

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    //cin >> t;
    while (t--)
    {
        int x;
        cin >> x;
        if (x >= 30)
            cout << "Yes"
                 << "\n";
        else
        {
            cout << "No"
                 << "\n";
        }
    }
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <string>
#include <utility>

using namespace std;
string s[500];
vector<int> G[200000];
bool used[200000];
long long a[200000],b[200000] = {},wh[200000] = {};
void dfs(int x){
	used[x] = true;
	for(int v:G[x]){
		if(!used[v]){
			a[v] = a[x];
			dfs(v);
		}
	}
}

int main(){
	int i,j,h,w,n;
	cin >> h >> w;
	n = h*w;
	for(i=0;i<h;i++){
		cin >> s[i];
	}
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			if(j!=w-1 && s[i][j]!=s[i][j+1]){
				G[i*w+j].push_back(i*w+j+1);
				G[i*w+j+1].push_back(i*w+j);
			}
			if(i!=h-1 && s[i][j]!=s[i+1][j]){
				G[i*w+j].push_back((i+1)*w+j);
				G[(i+1)*w+j].push_back(i*w+j);
			}
		}
	}
	for(i=0;i<n;i++) used[i] = false;
	for(i=0;i<n;i++){
		if(!used[i]){
			a[i] = i;
			dfs(i);
		}
	}
	for(i=0;i<n;i++){
		if(s[i/w][i%w]=='#') b[a[i]]++;
		else wh[a[i]]++;
	}
	long long ans = 0;
	for(i=0;i<n;i++){
		ans += b[i]*wh[i];
	}
	cout << ans << endl;
}
		
	

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

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

for(int i=0; i<H; i++){for( int j=0; j<W; j++){cout<<"#";
}
cout<<"\n";}
cout<<endl;
}
	// your code goes here
	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#define data_type long long

int main()
{
 data_type n,m;
 cin>>n>>m;
 vector<data_type> vc(n);
 for(auto &i:vc)
   cin>>i;
 sort(vc.begin(),vc.end());
 data_type x=  (accumulate(vc.begin(),vc.end(),0LL)+4*m-1) / (4*m);
 cout<<(n-distance(vc.begin(),lower_bound(vc.begin(),vc.end(),x))>=m?"Yes":"No")<<endl;



    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#define debug(x...) cout << #x << " = "; _print(x)
typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll;
#define rep(i,a,b) for (ll i = (a); i < (b); ++i)
#define per(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define mp make_pair 
#define pb push_back
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL) 
const int mod = 1e9 + 7, mxn = 1e5 + 1;

int solve(){
    string s;
    cin>> s;
    if(s.back() == 's')
        s += "es";
    else
        s += "s";
    cout<< s<< "\n";
    return 0;
}
//Counting problems: Sometimes easier to find complement of the answer
 
int main()
{
    fast;
    int t = 1;
    //cin>> t;
    while(t--){  
        solve();
    }
    return 0;
}
//v.clear(), vis.clear(); vis.resize(n + 1, 0), v.resize(n + 1);
 
/*  inv[1] = 1; // inv is ll
    for(int i=2; i<=mxn; ++i)
        inv[i]=mod-mod/i*inv[mod%i]%mod;*/
        
// lower bound   >=  
// upper bound   >
// vector<int>().swap(vec); //free memory from vec


Measured memory_bytes: 3652
n,m=map(int,input().split())
p=[]
for i in range(n):
  a,b=map(int,input().split())
  p.append((a,b))
  
p.sort(key=lambda x:x[0])
remain = m
res=0

for t in p:
  c=min(remain,t[1])
  res+=t[0]*c
  remain-=c
  if remain==0:
    break
print(res)

Measured memory_bytes: 18140
def m():
 e=input
 a=''
 for _ in[0]*int(e()):
  X,z=e(),[]
  for y in e():
   s=i=0
   for k in z:
    t=X.find(y,s)+1
    if t<1:break
    if t<k:z[i]=t
    s=k;i+=1
   else:
    t=X.find(y,s)+1
    if t:z+=[t]
  a+=f'\n{len(z)}'
 print(a[1:])
if'__main__'==__name__:m()


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

int N;
int t[100000], x[100000], y[100000];

void input() {
    cin >> N;
    
    for (int i = 0; i < N; ++i) cin >> t[i] >> x[i] >> y[i];
}

int main() {
    input();
    int x_pos = 0;
    int y_pos = 0;
    int dist = 0;
    int flg = 1;
    int bt = 0;

    for(int i = 0; i < N;i++){
        dist = abs(x_pos - x[i]) + abs(y_pos - y[i]);
        if(dist <= (t[i] - bt) && (dist % 2) == ((t[i] - bt) % 2)){
            x_pos = x[i];
            y_pos = y[i];
        } else {
            flg = 0;
            break;
        }
        bt = t[i];
    }
    if(flg){
        cout << "Yes" << endl;
    } else{
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#define invrep(i,n) for(int64_t i=n-1;i >= 0L;i--)
#define prep(i,n) for(int64_t i=1;i <= (int64_t)(n);i++)
using namespace std;

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  int64_t array_num = 1;
  fspcnt = 0;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}

int64_t calcmodcomb(int64_t n,int64_t r){
  return (((modfact.at(n)*modinvfact.at(r))%univMod)*modinvfact.at(n-r))%univMod;
}

int64_t calcmodpositive(int64_t n){
  return (n + ((abs(n)+univMod-1)/univMod)*univMod)%univMod;
}
  
    */


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  int k,n;
  cin >> n >> k;
  string s;
  cin >> s;
  s.at(k-1) = s.at(k-1) - 'A' + 'a';
  cout << s << endl;
}

Measured memory_bytes: 256
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
template<class Read>void in(Read &x){
    x=0;
    int f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x=f?-x:x;
    return;
}
ll x,y,a,b,c,l1,r1,l2,r2,l3,r3;
int main(){
	in(x);in(y);in(a);in(b);
	c=__gcd(a,b);
	c=c*(a/c)*(b/c);
	l1=(x+a-1)/a*a;
	r1=y/a*a;
	l2=(x+b-1)/b*b;
	r2=y/b*b;
	l3=(x+c-1)/c*c;
	r3=y/c*c;
	ll s1=(r1-l1)/a+1,s2=(r2-l2)/b+1,s3=(r3-l3)/c+1;
	cout<<y-x+1-s1-s2+s3<<endl;
	return 0;
}

Measured memory_bytes: 256