akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
vector<char> Alphabet = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
vector<char> alphabet = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


int main()
{
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  int ans = 0;
  vector<int> L(N);
  rep(i,N) cin >> L[i];
  rep(i,N-2)
  {
    for(int j=i+1;j<N-1;j++)
    {
      for(int k=j+1;k<N;k++)
      {
        if(L[i]!=L[j]&&L[j]!=L[k]&&L[k]!=L[i])
        {
          vector<int> vec(3);
          vec = {L[i],L[j],L[k]};
          sort(RALL(vec));
          if(vec[0]<vec[1]+vec[2])
          {
            ans ++;
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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


int main () {
  int N, A, B, train, taxi;
  cin >> N >> A >> B;
  train = A * N;
  taxi = B;
  if (train < taxi) cout << train << endl;
  else cout << taxi << endl;
}


Measured memory_bytes: 3544
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <map>
#include <unordered_map>
#define REP(i,n) for (int i=0;i<(n);++i)
using namespace std;
using ll = long long;

int main(){
     int n,k;
     cin>>n>>k;
     int arr[n];
     for(int i=0;i<n;i++) cin>>arr[i];
     int ans[n];
     ans[0]=0;
     ans[1]=abs(arr[1]-arr[0]);
     for(int i=2;i<n;i++)
     {    ans[i]=INT_MAX;
          int l=i-1;
         for(int j=0;j<k && l>=0;j++){
         ans[i]=min(ans[i],ans[l]+abs(arr[i]-arr[l]));
        l--;}
     }
     cout<<ans[n-1];
return 0;
}


Measured memory_bytes: 1024
N=int(input())
a=[1,6,36,216,1296,7776,46656,9,81,729,6561,59049]
a=sorted(a)
dp=[-1]*(N+1)
dp[0]=0
for i in range(N):
    m=[]
    for j in range(len(a)):
        if(a[j]<=i+1):
            m.append(dp[(i+1)-a[j]]+1)
    dp[i+1]=min(m)
print(dp[N])

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

struct data
{
    int a, b;
} players[100005];

int n;
long long ans;

bool cmp(data x, data y)
{
    return x.a<y.a;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for(int i=0; i<n; i++) cin >> players[i].a >> players[i].b;
    sort(players, players+n, cmp);

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

    return 0;
}


Measured memory_bytes: 1024
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	l := getNextInt(scanner)
	ee := make([]int, 0)
	for i := l; i > 0; {
		e := exp(i)
		ee = append(ee, e)
		i -= 1 << uint(e)
	}
	e := ee[0]
	n := e + 1
	edges := make([]Edge, 0)
	for i := 0; i < e; i++ {
		edges = append(edges, Edge{
			s: i,
			t: i + 1,
			c: 0,
		})
		edges = append(edges, Edge{
			s: i,
			t: i + 1,
			c: 1 << uint(i),
		})
	}

	for i := 1; i < len(ee); i++ {
		edges = append(edges, Edge{
			s: ee[i],
			t: n - 1,
			c: l - (1 << uint(ee[i])),
		})
		l -= 1 << uint(ee[i])
	}

	m := len(edges)
	fmt.Fprintln(writer, fmt.Sprintf("%d %d", n, m))
	for i := 0; i < m; i++ {
		fmt.Fprintln(writer, fmt.Sprintf("%d %d %d", edges[i].s+1, edges[i].t+1, edges[i].c))
	}

	writer.Flush()
}

func exp(l int) int {
	ans := 0
	for i := 0; i < 20 && 1<<uint(i) <= l; i++ {
		ans = i
	}
	return ans
}

type Edge struct {
	s, t, c int
}


Measured memory_bytes: 640
#include<cstdio>
#include<cmath>
#define Pi 3.141592653589793238462643383279502884197169399375105820974944592307816406286
using namespace std;
long double a,b,x,v;
int main()
{
	scanf("%Lf%Lf%Lf",&a,&b,&x);
	v=a*a*b;
	if(x*2<=v)
	{
		long double sy=x*2/a/b;
		printf("%.10Lf",atan(b/sy)/Pi*180.0);
	}
	else 
	{
		long double sy=(v-x)*2/a/a;
		printf("%.10Lf",atan(sy/a)/Pi*180.0);
	}
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    int ans = 0;
    if(n>=10) ans+=9;
    else ans+=n;
    if(n>=1000) ans+=900;
    else if(n>=100) ans+=(n-99);
    if(n>=100000) ans+=90000;
    else if(n>=10000) ans+=(n-9999);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
    int H,N,A;
    int sum=0;
    cin >> H >> N;
    for(int i=0;i<N;i++)
    {
        scanf("%d",&A);
        sum+=A;
    }
    if(H>sum)
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define swap(type ,a ,b) {type t; t=a; a=b; b=t;}
#define forN(i,n) for(i=0;i<n;i++)
#define forR(i,s,n) for(i=s;i<n;i++)
#define ll long long
#define pb(t,d,n) {t p;int i;forN(i,n){cin>>p;d.push_back(p);}}

using namespace std;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;

typedef vector<pair<int,int>> vpii;

int main(){
    int n,i,tmp;
    vpii a;
    pii ai,rnk1,rnk2;
    cin >> n;
    forN(i,n){
        cin >> tmp;
        a.push_back({i,tmp});
    }
    rnk1 = {0,0};
    rnk2 = {0,0};
    forN(i,n){
        if(a[i].second>=rnk1.second){
            rnk2 = rnk1;
            rnk1 = a[i];
        }
        else if(a[i].second>=rnk2.second){
            rnk2 = a[i];
        }
    }
    forN(i,n){
        if(i==rnk1.first) cout << rnk2.second << endl;
        else cout << rnk1.second << endl;
    }
}

Measured memory_bytes: 3312
#include<cstdio>
#include<algorithm>
using namespace std;
long long n;
int g[20];
int dfs(int x,bool lim)
{
	if(!x)	return 0;
	if(!lim)	return dfs(x-1,0)+9;
	else	return max(dfs(x-1,1)+g[x],g[x]>0 ? (dfs(x-1,0)+g[x]-1) : 0);
}
int main()
{
	scanf("%lld",&n);
	for(;n;n/=10)	g[++g[0]]=n%10;
	printf("%d",dfs(g[0],1));
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<list>
#include<bitset>
#include<cctype>
#include<iomanip>
using namespace std;
const int N = 100;
typedef long long ll;
#define PI 3.1415927

int main(){
	int x,y,z,i=0;
	while(cin>>x>>y>>z)
	{
		i=0;
		x=x-z;
		while(x>=0){
			x=x-z-y;
			i++;
			}
		cout<<i-1<<endl;
		
		
		}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (4) << f << endl; Prints x.xxxx


using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);   
int arr[123456],barr[123456];
vii vec;
int main(){
	std::ios::sync_with_stdio(false);
	int n,x,y,a,b,c,i,j;
	cin>>n>>x>>y;
	rep(i,n){
		cin>>a>>b>>c;
		int val=y*a-x*b;
		vec.pb(mp(val,c));


	}
	rep(i,100000){
		arr[i]=inf;
	}
	rep(i,vec.size()){
		//cout<<vec[i].ff<<"  "<<vec[i].ss<<endl;
		f(j,600,30000){
			barr[j+vec[i].ff]=min(arr[j]+vec[i].ss,arr[j+vec[i].ff]);

		}
		barr[10000+vec[i].ff]=min(barr[10000+vec[i].ff],vec[i].ss);
		//cout<<barr[10000]<<endl;
		rep(j,100000){
			arr[j]=barr[j];
		}

	}
	//..cout<<arr[10000];
	if(arr[10000]>10000)
		cout<<-1<<endl;
	else
		cout<<arr[10000]<<endl;

}


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

using namespace std;

long long myatoll(char c) {
    return (long long)atoi(&c);
}

long long P_is_not_2_5(long long N, long long P, const string& S) {
    map<long long, long long> residual;
    residual.insert(make_pair(0LL, 1LL));
    long long pow10 = 1;
    long long curr = 0LL;
    for (long long i = N - 1; i >= 0; --i) {
        int s = atoi(S.substr(i, 1).c_str());
        int m = (s * pow10 + curr) % P;
        if (residual.count(m) == 0) {
            residual.insert(make_pair(m, 0LL));
        }
        residual[m] += 1;
        curr = m;
        //curr += pow10 * myatoll(S[i]);
        //curr %= P;
        //if (residual.count(curr) == 0) {
        //    residual.insert(make_pair(curr, 0LL));
        //}
        //residual[curr] += 1;
        pow10 *= 10;
        pow10 %= P;
    }
    long long ans = 0;
    for (auto it : residual) {
        long long n = it.second;
        if (n >= 2) {
            ans += n * (n - 1) / 2;
        }
    }
    return ans;
}

long long P_is_2_or_5(long long N, long long P, const string& S) {
    long long ans = 0LL;
    for (long long i = 0; i < N; ++i) {
        long long c = myatoll(S[i]);
        if (c % P == 0) {
            ans += i + 1;
        }
    }
    return ans;
}

void Main() {
    long long N, P;
    cin >> N >> P;
    string S;
    cin >> S;

    long long ans = 0LL;
    if (P == 2LL || P == 5LL) {
        ans = P_is_2_or_5(N, P, S);
    }
    else {
        ans = P_is_not_2_5(N, P, S);
    }
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 1028
import numpy as np
H, W = map(int,input().split())
S = []
maxval = 10000
blacknum = 0
for i in range(H):
    S.append(input())
board = np.zeros((H+2,W+2), dtype=np.int64)
dist = np.full((H+2,W+2), maxval, dtype=np.int64)
for i in range(1,H+1):
    for j in range(1,W+1):
        if S[i-1][j-1] == '#':
            board[i][j] = 1
            dist[i][j] = maxval
            blacknum += 1
        else:
            board[i][j] = 0
            dist[i][j] = maxval
dist[1][1] = 0
for iter in range(563):
    update_flag = 0
    for i in range(1,H+1):
        for j in range(1,W+1):
            if board[i][j] == 1:
                continue
            newdist = min([dist[i-1][j], dist[i+1][j], dist[i][j-1], dist[i][j+1]])+1
            if newdist < dist[i][j]:
                dist[i][j] = newdist
                update_flag = 1
    if update_flag == 0:
        break
pass_cell = dist[H][W] + 1
maxscore = H*W - pass_cell - blacknum
if pass_cell >= maxval:
    print(-1)
else:
    print(maxscore)


# 最長経路は1226マスなので1226回るーぷすればいい
# 1226*2500=3065000なのできついか？
# 下に49マス右に49マスは必須なのでこれはループ1回分
# 上や左に進んだ数と同じだけ下や右に進む必要があるので、
# (1226-98)/2 + 1 = 563ループでいけそう
# →563*2500 = 1407500. 大体半分になったけどまだつらそう
# ループのたびに走査方向を切り替えると速くなる…？
# (左から右、上から下)と(右から左、下から上)の2種類持つ感じで

# 1ループで変化がなければフラグ立てて終了させる


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

int main() {
    int N,M,K;
    cin >> N >> M >> K;
    vector<ll> A(N+1),B(M+1);
    // vector<int>::iterator position;
    rep(i,N){
        cin >> A[i+1];
    }
    rep(i,M){
        cin >> B[i+1];
    }
    rep(i,M){
        B[i+1] += B[i];
    }

    int ans = 0;
    ll sum = 0;
    
    rep(i,N+1){
        sum += A[i];
        if(sum > K){
            break;
        }
        ll rest = K - sum;
        int j = 0;
        if(rest > 0){
            auto position = upper_bound(B.begin(), B.end(), rest);
            j = distance(B.begin(), position);
            j--;
        }
        
        ans = max(ans, i+j);
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6408
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;
        PrintWriter pw = new PrintWriter(System.out);

        st = new StringTokenizer(br.readLine());
        long n = Integer.parseInt(st.nextToken());
        long m = Integer.parseInt(st.nextToken());

        long ans = n*(n-1)/2;
        ans += m*(m-1)/2;

        pw.println(ans);

        
        
        
        
        
        pw.flush();
        pw.close();
    }
}


Measured memory_bytes: 22484
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
const ll dx[4]={1,0,-1,0};
const ll dy[4]={0,1,0,-1};
int main() {
    ll h,w;
    cin >> h >> w;
    ll ans=0;
    vector<vector<char>>s(h,vector<char>(w));
    for(ll i=0;i<h;i++){
        for(ll j=0;j<w;j++){
            cin >>s[i][j];
            if(s[i][j]=='.') ans++;
        }
    }
    ll sx=0,sy=0,gx=h-1,gy=w-1;
    vector<vector<ll>>dist(h,vector<ll>(w,-1));
    dist[sx][sy]=0;

    queue<pair<ll,ll>>que;
    que.push({sx,sy});

    while(!que.empty()){
        pair<ll,ll> pos=que.front();
        ll x=pos.first;
        ll y=pos.second;
        que.pop();

        for(ll i=0;i<4;i++){
            ll nx=x+dx[i];
            ll ny=y+dy[i];
            if(nx<0||nx>=h||ny<0||ny>=w) continue;
            if(s[nx][ny]=='#') continue;

            if(dist[nx][ny]==-1){
                que.push({nx,ny});
                dist[nx][ny]=dist[x][y]+1;
            }
        }
    }
    ans-=(dist[gx][gy]+1);
    if(dist[gx][gy]==-1){
        cout << -1 << endl;
    }
    else cout << ans << endl;
}

Measured memory_bytes: 3632
import math
N = int(input())

C = [list(map(int,input().split())) for i in range(N-1)]

for i in range(N-1):
    total = 0
    for j in range(i,N-1):
        total = max(math.ceil(total/C[j][2])*C[j][2],C[j][1])
        total += C[j][0]
    print(total)

print(0)

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

template<typename Type> class StarrySkyTree {
public:
	unsigned size_; std::vector<Type> dat1, dat2, dat;
	inline void update_(unsigned a, unsigned b, Type x, unsigned k, unsigned l, unsigned r) {
		if (r <= a || b <= l) return;
		if (a <= l && r <= b) {
			dat2[k] += x; return;
		}
		update_(a, b, x, (k << 1), l, (l + r) >> 1);
		update_(a, b, x, (k << 1) + 1, (l + r) >> 1, r);
		dat1[k] = std::min(dat1[k << 1] + dat2[k << 1], dat1[(k << 1) + 1] + dat2[(k << 1) + 1]);
	}
	inline Type query_(unsigned a, unsigned b, unsigned k, unsigned l, unsigned r) {
		if (r <= a || b <= l) return std::numeric_limits<Type>::max();
		if (a <= l && r <= b) return dat1[k] + dat2[k];
		Type lc = query_(a, b, (k << 1), l, (l + r) >> 1);
		Type rc = query_(a, b, (k << 1) + 1, (l + r) >> 1, r);
		return std::min(lc, rc) + dat2[k];
	}
	//StarrySkyTree() : size_(0), dat(std::vector<Type>()) {};
	StarrySkyTree(int size__) {
		for (size_ = 1; size_ < size__; ) size_ <<= 1;
		dat1.resize(size_ << 1, 0);
		dat2.resize(size_ << 1, 0);
		dat.resize(size_ << 1, 0);
	}
	template<class T>
	StarrySkyTree(T begin_, T end_) {
		unsigned n = (end_ - begin_);
		for (size_ = 1; size_ < n; size_ <<= 1); dat.resize(size_ << 1, std::numeric_limits<Type>::max());
		for (unsigned i = 0; i < n; i++) dat[i + size_] = *(begin_ + i);
		for (unsigned i = size_ - 1; i > 0; i--) dat[i] = std::min(dat[i << 1], dat[(i << 1) + 1]);
	}
	inline unsigned size() { return size_; }
	inline void add(unsigned i, Type x) {
		update_(i, i + 1, x, 1, 0, size_);
	}
	inline void add(unsigned l, unsigned r, Type x) {
		update_(l, r, x, 1, 0, size_);
	}
	inline Type query(unsigned l, unsigned r) {
		return query_(l, r, 1, 0, size_);
	}
};

string S; int N, Q, P;
StarrySkyTree<int> X(1);

int solve(int pos) {
	int I1 = X.query(pos, pos + 1); // pos の depth
	int I2 = X.query(pos + 1, pos + 2); // pos + 1 の depth

	if (I1 > I2) {
		// もともと ')' だった : ')' -> '('
		X.add(pos + 1, N + 1, 2);
		int L = 0, R = N + 1, M, minx = N + 1;
		for (int i = 0; i < 20; i++) {
			M = (L + R) / 2;
			int B = X.query(M, N + 1);
			if (B >= 2) { minx = min(minx, M); R = M; }
			else { L = M; }
		}
		X.add(minx, N + 1, -2);
		return minx - 1;
	}
	else {
		// もともと '(' だった : '(' -> ')'
		X.add(pos + 1, N + 1, -2);
		int L = 0, R = N + 1, M, minx = N + 1;
		for (int i = 0; i < 20; i++) {
			M = (L + R) / 2;
			int B = X.query(M, M + 1);
			if (M != B) { minx = min(minx, M); R = M; }
			else { L = M; }
		}
		X.add(minx, N + 1, 2);
		return minx - 1;
	}
}

int main() {
	cin >> N >> Q >> S;
	X = StarrySkyTree<int>(N + 1);
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == '(') X.add(i + 1, N + 1, 1);
		if (S[i] == ')') X.add(i + 1, N + 1, -1);
	}
	for (int i = 1; i <= Q; i++) {
		cin >> P; P--;
		cout << solve(P) + 1 << endl;
	}
	return 0;
}


Measured memory_bytes: 15584
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>
#include<assert.h>

using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
// #define MOD 998244353 
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

bool check_fn(int X,vector<int> & vec)
{
  string s = to_string(X);
  for (int i = 0; i < s.size(); i++)
  {
    int V = (int)(s[i] - '0');
    for (int j = 0; j < vec.size(); j++)
    {
      if(V == vec[j])return false;
    }
    
  }
  return true;
  
}


void solve(void)
{
  int N,K;cin>>N>>K;
  vector<int> vec;
  for (int i = 0; i < K; i++)
  {
    int X;
    cin>>X;
    vec.push_back(X);
  }
  
  while(true)
  {
    if(check_fn(N,vec))
    {
      cout<<N<<endl;
      return;
    }
    else
    {
      N++;
    }
    // DEBUG(N);
    
  }

  

  
    return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int f(int n) {  //nの桁数xを求める関数
    int x = 0;

    while(n != 0) {
        x++;
        n /= 10;
    }

    return x;
}

int main() {
    int n, ans = 0;
    cin >> n;
    for(int i = 1; i <= n; i++) {
        if(f(i)%2 == 1) {
            ans++;
        }
    }
    cout << ans;
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()

ll MOD = 1000000007;
ll lcm(ll a, ll b) { return (a / __gcd(a, b) * b); }

int main() {
  //
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  int dx = tx - sx;
  int dy = ty - sy;
  rep(i, dy) { cout << "U"; }
  rep(j, dx) { cout << "R"; }
  rep(i, dy) { cout << "D"; }
  rep(j, dx) { cout << "L"; }

  cout << "L";
  rep(i, dy) { cout << "U"; }
  cout << "UR";
  rep(j, dx) { cout << "R"; }
  cout << "DR";
  rep(i, dy) { cout << "D"; }
  cout << "DL";
  rep(j, dx) { cout << "L"; }
  cout << "U";

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ll long long
#define MOD 1000000007
#define MAX 1000010
using namespace std;

int main(){
  float h,a;
  cin >> h >> a;
  float ans = ceil(h/a);
  
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {
	static final int NUM_RAND = 10;
	static final int DIGIT = 4;

	/**
	 * @param args
	 */
	public static void main(String[] args)
			throws IOException {
		BufferedReader br = new BufferedReader(
				new InputStreamReader(System.in));
		int numInput = Integer.parseInt(br.readLine());
		for(int i = 0; i < numInput; i++){
			int[] r = rand(Integer.parseInt(br.readLine()), DIGIT, NUM_RAND);
			System.out.println("Case " + (i + 1) + ":");
			for(int n : r){
				System.out.println(n);
			}
		}
	}

	public static int[] rand(int seed, int digit, int numRand) {
		int[] r = new int[numRand];
		String randSquare = null;
		for (int i = 0; i < r.length; i++) {
			randSquare = String.format("%0" + digit * 2 + "d", seed * seed);
			String center = getCenter(randSquare, digit);
			r[i] = Integer.parseInt(center);
			seed = r[i];
		}
		return r;
	}

	private static String getCenter(String str, int digit) {
		return str.substring(digit / 2, digit / 2 + digit);
	}
}

Measured memory_bytes: 17056
#include <bits/stdc++.h>
#define FIO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"

using namespace std;

const int N = int(10e5 + 5);

int main() {

	FIO
	int x; cin >> x;
	(x >= 30) ? cout << "Yes" : cout << "No";
	return 0;
}

Measured memory_bytes: 3636
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
	"unsafe"
)

func main() {
	// P, Q, R := sc.nextInt(), sc.nextInt(), sc.nextInt()
	PQR := sc.nextInts()
	minv := PQR[0] + PQR[1]
	for i := 0; i < 3; i++ {
		for j := 0; j < 3; j++ {
			if i == j {
				continue
			}
			tmp := PQR[i] + PQR[j]
			if minv > tmp {
				minv = tmp
			}
		}
	}
	fmt.Println(minv)
}

var (
	sc scanner
)

func init() {
	sc = scanner{
		buf: make([]string, 0, 0),
		cur: 0,
		r:   bufio.NewReader(os.Stdin),
	}
}

type scanner struct {
	buf []string
	cur int
	r   *bufio.Reader
}

func (s *scanner) readln() {
	rbuf := make([]byte, 0, 0)
	for {
		line, prefix, err := s.r.ReadLine()
		if err != nil {
			panic(err)
		}
		rbuf = append(rbuf, line...)
		if prefix == false {
			break
		}
	}
	s.cur = 0
	s.buf = strings.Split(*(*string)(unsafe.Pointer(&rbuf)), " ")
}
func (s *scanner) isFull() bool {
	if s.cur == len(s.buf) {
		return true
	}
	return false
}
func (s *scanner) resetCur() {
	s.cur = 0
}
func (s *scanner) next() string {
	if s.cur == 0 {
		s.readln()
	}
	res := s.buf[s.cur]
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nexts() []string {
	s.readln()
	s.resetCur()
	return s.buf
}
func (s *scanner) nextInt() int {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.Atoi(s.buf[s.cur])
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nextInts() []int {
	s.readln()
	res := make([]int, len(s.buf))
	for i := range s.buf {
		res[i], _ = strconv.Atoi(s.buf[i])
	}
	s.resetCur()
	return res
}
func (s *scanner) nextFloat() float64 {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.ParseFloat(s.buf[s.cur],
		64)
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nextFloats() []float64 {
	s.readln()
	res := make([]float64, len(s.buf))
	for i := range s.buf {
		res[i], _ = strconv.ParseFloat(s.buf[i],
			64)
	}
	s.resetCur()
	return res
}
func digits(x int) int {
	return len(strconv.Itoa(x))
}
func powInt(x, p int) (result int) {
	result = 1
	for i := 0; i < p; i++ {
		result *= x
	}
	return
}
func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}
func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}
func abs(x int) int {
	return int(math.Abs(float64(x)))
}
func varDump(value ...interface{}) {
	for _, v := range value {
		fmt.Fprintf(os.Stderr, "%#v\n", v)
	}
}
func yes() {
	fmt.Println("Yes")
}
func no() {
	fmt.Println("No")
}

// Pair a
type Pair struct {
	first  int
	second int
}

// Queue a
type Queue struct {
	v []Pair
}

// Push for queue
func (q *Queue) Push(v Pair) {
	q.v = append(q.v, v)
}

// Pop for queue
func (q *Queue) Pop() Pair {
	r := q.v[0]
	q.v = q.v[1:]
	return r
}

// Front for queue
func (q Queue) Front() Pair {
	return q.v[0]
}

// Empty return true if empty
func (q Queue) Empty() bool {
	return len(q.v) == 0
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
	int n;
	cin >> n;
	int A, B, X = 1, Y = 1;
	for (int i = 0; i < n; i++) {
		cin >> A >> B;
		int tmp = max((X - 1) / A, (Y - 1) / B);
		X = (tmp + 1) * A, Y = (tmp + 1) * B;
	}
	cout << X + Y << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import deque

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

if m % 2:
    print(-1)
    exit()

adj = [[] for _ in range(n + 1)]
for a, b in ab:
    adj[a].append(b)
    adj[b].append(a)

s = 1
dq = deque([s])
d = [-1] * (n + 1)
d[s] = 0
p = [-1] * (n + 1)
order = []
while dq:
    u = dq.popleft()
    order.append(u)
    for v in adj[u]:
        if d[v] == -1:
            d[v] = d[u] + 1
            p[v] = u
            dq.append(v)

out = [0] * (n + 1)
ans = []
for a, b in ab:
    if p[a] == b or p[b] == a:
        continue
    ans.append((a, b))
    out[a] ^= 1

for v in order[1:][::-1]:
    u = p[v]
    if out[v]:
        ans.append((v, u))
        out[v] ^= 1
    else:
        ans.append((u, v))
        out[u] ^= 1

for u, v in ans:
    print(u, v)


Measured memory_bytes: 49732
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50



def run():
    N, X, T = map(int, input().split())

    times = math.ceil(N / X)
    ans = times * T
    print(ans)


if __name__ == "__main__":
    run()

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

int main() {
  int64_t X;
  cin >> X;
  int bank = 100;
  vector<int64_t> num(3761);
  num.at(0) = 100;
  for (int i=1; i<=3760; i++) {
    num.at(i) = num.at(i-1) * 1.01;
    if (num.at(i) >= X) {
      cout << i << endl;
      break;
    }
  }
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <map>
#include <algorithm>
#include <stdio.h>
#include <set>
#include <cmath>

typedef long long ll;

using namespace std;



int main(){
    int k, n;
    cin >> k >> n;
    vector<int> v;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        v.push_back(x);
    }
    int a[n];
    for(int i = 0; i < n - 1; i++){
        a[i] = v[i + 1] - v[i];
    }
    a[n - 1] = k - v[n - 1] + v[0];
    sort(a, a + n);
    cout << k - a[n - 1] << endl;
}


Measured memory_bytes: 1908
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int i=0; i<(n);i++)
typedef long long ll;


int main() {
    int N, Q; cin >> N >> Q;
    string str; cin >> str;
    vector<int> l(Q);
    vector<int> r(Q);
    rep(i,Q){
        cin >> l[i] >> r[i];
        l[i]--; r[i]--;
    }

    // 累積和
    vector<int> s(N+1, 0);
    for (int i = 0; i < N; ++i) {
        if (i+1 < N && str[i] == 'A' && str[i+1] == 'C') s[i+1] = s[i] + 1;
        else s[i+1] = s[i];
    }

    // クエリ
    for (int q = 0; q < Q; ++q) {
        cout << s[r[q]] - s[l[q]] << endl;
    }
}


Measured memory_bytes: 2240
import math

n, h = map(int, input().split())
a, b = [], []
for _ in range(n):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)

a_max = max(a)
b.sort(reverse=True)
damage_cnt = 0

while h > 0:
    if len(b) > 0 and b[0] >= a_max:
        h -= b[0]
        b.pop(0)
        damage_cnt += 1
    else:
        damage_cnt += math.ceil(h/a_max)
        h = 0
print(damage_cnt)

Measured memory_bytes: 11312
#include <bits/stdc++.h>
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrepi(i,a,b) for(int i=((int)(b)-1);i>=(a);--i)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) rrepi(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define ZERO(x) memset(x,0,sizeof(x))
#define MINUS(x) memset(x,-1,sizeof(x))
#define UNIQUE(x) (x).erase(unique(ALL(x)), (x).end())
#define debug(var)  do{std::cout << #var << " : "; view(var);}while(0)
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){for(const auto& v : vv){ view(v); } }
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void viewarr(T arr[], int n) { for(int i = 0; i < n; ++i) std::cout << arr[i] << " "; std::cout << std::endl; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll qp(ll a,ll b){ll ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
ll qp(ll a,ll b,ll mo){ll ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const int INF = 1e9;
const ll INFL = 1e18;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5;

struct mint {
    ll x;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const {return mint(-x);}
    mint& operator+=(const mint a) {
        if((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if(!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if(t&1) a *= *this;
        return a;
    }

    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) {
        mint res(*this);
        return res/=a;
    }
};


int main() {
    int n, a, b; cin >> n >> a >> b;
    mint pa(1), pb(1);
    repi(i,n-a+1,n+1) {
        pa *= i;
    }
    repi(i,1,a+1) {
        pa /= i;
    }
    repi(i,n-b+1,n+1) {
        pb *= i;
    }
    repi(i,1,b+1) {
        pb /= i;
    }
    cout << ((qp(2,n,MOD)-1 - pa.x - pb.x)%MOD +MOD)%MOD << endl;
    return 0;
}


Measured memory_bytes: 256
char S[12];
char out[2<<20];
int outsz,Slen;
main()
{
	int N,K;
	scanf("%d%d ",&N,&K);
	gets(S);
	Slen=strlen(S);
	for(int i=0;i<K;i++)
	{
		memcpy(out+outsz,S,Slen);
		outsz+=Slen;
		out[outsz++]='\n';
	}
	for(int i=K;i<N;i++)
	{
		out[outsz++]='7';
		out[outsz++]='\n';
	}
	write(1,out,outsz);
}

Measured memory_bytes: 2304
<?php
list($N,$A,$B) = explode(" ",trim(fgets(STDIN)));
if($A>$B){
  $a1 = $B;
}else{
  $a1 = $A;
}
if($A+$B-$N>0){
$a2 = $A + $B - $N;
}else{
$a2 = 0;
}
echo "$a1 $a2"."\n";

Measured memory_bytes: 3828
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl

const int MAXV = 100005;
vector<vector<int>> to(MAXV);
vector<bool> chk(MAXV);

void dfs(int v, int p) {
  chk[v] = true;
  for(auto u : to[v]) {
    if(chk[u]) continue;
    dfs(u, v);
  }
}

int main() {
  int n, m;
  cin >> n >> m;
  to.resize(n);
  rep(i, m) {
    int x, y, z;
    cin >> x >> y >> z;
    x--, y--;
    to[x].push_back(y);
    to[y].push_back(x);
  }
  chk.resize(n);
  int ans = 0;
  rep(i, n) {
    if(chk[i]) continue;
    dfs(i, -1);
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 10368
import java.io.*;
import java.util.*;



public class Main{
    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str;
                    
        str = br.readLine();
        int N = Integer.parseInt(str);
        
        str = br.readLine();
        String[] strs = str.split("\\s");
        int[] A = new int[strs.length];
        for(int i=0;i<strs.length;i++){
            A[i] = Integer.parseInt(strs[i]);
        }

        for(int i=1;i<N;i++){
            StringBuilder sb = new StringBuilder();
            for(int k=0;k<N;k++){
                sb.append(A[k]);
                if(k != (N-1)){
                    sb.append(" ");
                }
            }
            System.out.println(sb.toString());
            int v = A[i];//temp
            int j = i -1;
            while(j >=0 && A[j] > v){
                A[j+1] = A[j];
                j--;
                A[j+1] = v;//in order to exchange
            }
        }

        StringBuilder sb = new StringBuilder();
        for(int i=0;i<N;i++){
            sb.append(A[i]);
            if(i != (N-1)){
                sb.append(" ");
            }
        }
        System.out.println(sb.toString());
        br.close();
    }
}


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

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

#define fi first
#define se second
#define pb push_back

int n;

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

    cin>>n;
    string a,b,c;
    cin >> a>>b>>c;
    int ans = 0;
    for(int i = 0; i < n; i++){
        if(a[i]==b[i] && b[i]==c[i])continue;
        else if(a[i]==b[i] || a[i]==c[i] || b[i]==c[i]) ans++;
        else ans+=2;
    }
    cout<<ans;
    return 0;
}


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

int n;
int array[100];
int main(){
    int count;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> array[i];
    }
    for(int i=0;i<n;i++){
        for(int j=1;j<n-i;j++){
            if(array[j-1] > array[j]){
                swap(array[j-1], array[j]);
                count++;
            }
        }
    }
    cout << array[0];
    for(int i=1;i<n;i++){
        cout << " " << array[i];
    }
    cout << endl;
    cout << count << endl;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
long n;
void solve()
{
    long i;
    vector < long > inp(n);
    long long ans=0;
    for (i=0;i<n;i++)
        cin>>inp[i];
    sort(inp.begin(),inp.end());
    inp.push_back(inp[inp.size()-1]+1);
    vector < pair < long ,long > > res;
    pair < long ,long > tmp;
    tmp.first=inp[0];
    tmp.second=1;
    n=inp.size();
    for (i=1;i<n;i++)
        if (tmp.first==inp[i]) tmp.second++;
        else {res.push_back(tmp);tmp.first=inp[i];tmp.second=1;}
    n=res.size();
    for (i=0;i<n;i++)
        if (res[i].first==res[i].second) ;
        else if (res[i].first<res[i].second) ans+=res[i].second-res[i].first;
        else if (res[i].first>res[i].second) ans+=res[i].second;
    cout<<ans<<endl;
}
int main()
{
    while(cin>>n)
        solve();
}

Measured memory_bytes: 4108
import java.io.*;
import java.util.*;

public class Main{
	int w,h;
	int[] px={0,1,0,-1};
	int[] py={1,0,-1,0};
	int gx,gy,sx,sy;
	int res=11;
	public void dfs(int[][] fie2,int x,int y,int c,int m){
		if(c>=res)return;
		if(x==gx && y==gy){
			res=Math.min(res,c);
			return;
		}
		//System.out.printf("%d %d %d %d\n",x,y,c,m);
		if(m==-1){
			for(int i=0;i<4;i++){
				if(x+px[i]>=0 && x+px[i]<w && y+py[i]>=0 && y+py[i]<h)if(fie2[x+px[i]][y+py[i]]==0)dfs(fie2,x,y,c+1,i);
			}
		}else{
			if(x+px[m]>=0 && x+px[m]<w && y+py[m]>=0 && y+py[m]<h){
				if(fie2[x+px[m]][y+py[m]]==1){
					fie2[x+px[m]][y+py[m]]=0;
					for(int i=0;i<4;i++){
						if(x+px[i]>=0 && x+px[i]<w && y+py[i]>=0 && y+py[i]<h){
							if(fie2[x+px[i]][y+py[i]]==0)dfs(fie2,x,y,c+1,i);
						}
					}
					fie2[x+px[m]][y+py[m]]=1;
				}else dfs(fie2,x+px[m],y+py[m],c,m);
			}
		}
		return;
	}
	int[][] fie;
	public void run(){
		Scanner sc=new Scanner(System.in);
		while(true){
			w=sc.nextInt();
			h=sc.nextInt();
			fie=new int[w][h];
			res=11;
			if(w+h==0)break;
			for(int i=0;i<h;i++){
				for(int j=0;j<w;j++){
					fie[j][i]=sc.nextInt();
					if(fie[j][i]==2){
						sx=j;
						sy=i;
						fie[j][i]=0;
					}
					if(fie[j][i]==3){
						gx=j;
						gy=i;
						fie[j][i]=0;
					}
				}
			}
			dfs(fie,sx,sy,0,-1);
			if(res<=10)System.out.printf("%d\n",res);
			else System.out.printf("%d\n",-1);
		}
	}
	public static void main(String args[]){
		new Main().run();
	}
}

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

#define FOR(i,s,e) for(int i=(s);(i)<(int)(e);++(i))
#define REP(i,e) FOR(i,0,e)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define ppb(x) pop_back(x)
#define mp make_pair
#define mt make_tuple
#define t0(t) get<0>((t))
#define t1(t) get<1>((t))
#define t2(t) get<2>((t))

typedef long long ll;

int main() {
  double x;
  fscanf(stdin, "%lf ", &x);
  fprintf(stdout, "%.10f\n", x*x*x/27.0);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
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; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=998244353;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};




int main(){
    int n,s;cin >> n >> s;
    vector<LL> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    LL ans = 0;
    vector<LL> dp(5000,0);
    for (LL i = 0; i < n; i++) {
        for (int j = s; j >= 0; j--) {
            if(j + a[i] <= s) dp[j + a[i]] = (dp[j + a[i]] + dp[j])%mod;
        }
        dp[a[i]] = (dp[a[i]] + i + 1)%mod;
        ans = (ans + dp[s])%mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
const long long INF2 = -1000000000000000000;
using ll = long long;
int main(){
  ll a[2];
  ll b[2];
  ll ans = INF2;
  cin>>a[0]>>a[1]>>b[0]>>b[1];
  for(int i = 0;i<2;i++){
    for(int k = 0;k<2;k++){
      ans = max(ans,a[i]*b[k]);
    }
  }
  cout << ans << endl;
  return 0;
}
  

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	double ans=0;
	string s;
	getline(cin,s);
	while(n--)
	{
		getline(cin,s);
		int jpy;
		double btc;
		stringstream ss(s);
		if(s[s.length()-1]=='Y') ss>>jpy,ans+=jpy;
		else ss>>btc,ans+=btc*380000;
	}
	printf("%.8f\n",ans);
}


Measured memory_bytes: 256
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <sstream>
#include <vector>
#include <set>
#include <unordered_map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

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


int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;
	string s;
	cin >> s;

	auto check = [&](int len) {
	
		unordered_map<string, int> mp;
		for (int j = 0; j <= N - len; j++) {
			string tmp = s.substr(j, len);
			auto itr = mp.find(tmp);
			if (itr == mp.end()) mp.emplace(tmp, j);
			else if (j - itr->second >= len) return true;
		}
		
		return false;
	};

	
	auto biSearch = [&](auto f) {
		
	int ok = -1;
	int ng = N;

	while (abs(ok - ng) > 1) {
		int mid = (ok + ng) / 2;

		if (f(mid)) ok = mid;
		else ng = mid;
	}

	return ok;
	};
	
	cout << biSearch(check) << endl;
	
	return 0;
}


Measured memory_bytes: 6684
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}

int main() {
	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	cout << (k % 2 == 0? 1 : -1)*(a - b);

}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <iomanip>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};

class ANewYear {
public:
	void solve(istream& in, ostream& out) {
        int n; in >> n;
        out << 48 - n << endl;
	}
};

int main() {
	ANewYear solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

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


int main(){
	int n;
	while(cin >> n && n){
		string p[10];
		for(int i = 0 ; i < n ; i++){
			int a;
			cin >> a;
			p[a] += "*";
		}
		for(int i = 0 ; i < 10 ; i++){
			cout << (p[i].size()==0?"-":p[i]) << endl;
		}
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cassert>
#include<ctime>
using namespace std;

#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define absd(x) (x<0?-(x):x)
#define pow2(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; ++i)
#define repr(i,n) for(int i=n-1; i>=0; --i)
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define replr(i,s,n) for(int i=n; i>=s; --i)
#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)
#define repe(e,obj) for(auto e : obj)

#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X,Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 1000000000000000007LL
#define EPS 1e-9

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define P_TYPE int
typedef pair<P_TYPE, P_TYPE> P;
typedef pair<P, P_TYPE> PI;
typedef pair<P_TYPE, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P> > pvqueue;

class ConvexHullTrick {
  struct F {
    ll a, b;
    F(ll a, ll b) : a(a), b(b) {}
  };

  deque<F> deq;

  bool check(F &f1, F &f2, F &f3) {
    return (f2.a - f1.a) * (f3.b - f2.b) >= (f2.b - f1.b) * (f3.a - f2.a);
  }

  ll f(F &f1, ll x) {
    return f1.a * x + f1.b;
  }
public:
  void add_line(ll a, ll b) {
    F f1 = F(a, b);
    while(deq.size() >= 2 && check(deq[deq.size()-2], deq[deq.size()-1], f1)) {
      deq.pop_back();
    }
    deq.push_back(f1);
  }

  ll query(ll x) {
    while(deq.size() >= 2 && f(deq[0], x) >= f(deq[1], x)) {
      deq.pop_front();
    }
    return f(deq[0], x);
  }
};

#define N 200008

int n;
ll c;
ll y, h;

int main() {
  scanf("%d %lld", &n, &c);
  ConvexHullTrick cht;

  scanf("%lld", &h);
  cht.add_line(-2*h, h*h);
  rep(i, n-1) {
    scanf("%lld", &h);
    y = h*h + c + cht.query(h);
    cht.add_line(-2*h, y + h*h);
  }
  printf("%lld\n", y);
  return 0;
}

Measured memory_bytes: 2432