akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;
void solve(int n,int m){
  int taro[n];
  int hanako[m];
  int diff;
  int sum_taro = 0;
  int sum_hanako = 0;
  for(int i=0;i<n;i++){
    cin >> taro[i];
    sum_taro+=taro[i];
  }
  for(int i=0;i<m;i++){
    cin >> hanako[i];
    sum_hanako+=hanako[i];
  }
  diff = sum_taro - sum_hanako;




  int an = -1;int am = -1;
  int ma = 300;
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      if((taro[i] - hanako[j])*2 == diff){
        if(ma >= taro[i]+hanako[j]){
          an = i;am = j;
          ma = taro[i]+hanako[j];
        }
      }
    }
  }
  if(an != -1){
    cout << taro[an] << " " << hanako[am] << endl;
  }else{
    cout << -1 << endl;
  }
}
int main(){
  int n,m;
  while(cin >> n >> m && n!=0 && m!=0){
    solve(n,m);
  }
}

Measured memory_bytes: 0
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int a=1;
		
		
			if((s.charAt(0)=='S')&&(s.charAt(1)=='S')&&(s.charAt(2)=='S')) {
			 a=0;
			}
			else if((s.charAt(0)=='R')&&(s.charAt(1)=='R')&&(s.charAt(2)=='R')) {
				 a=3;
			}
			else if((s.charAt(0)=='R')&&(s.charAt(1)=='R')&&(s.charAt(2)=='S')) {
				 a=2;
			}
			else if((s.charAt(0)=='R')&&(s.charAt(1)=='S')&&(s.charAt(2)=='R')) {
				 a=1;
			}
			else if((s.charAt(0)=='S')&&(s.charAt(1)=='R')&&(s.charAt(2)=='R')) {
				 a=2;
			}
			else if((s.charAt(0)=='S')&&(s.charAt(1)=='S')&&(s.charAt(2)=='R')) {
				 a=1;
			}
		
	
		System.out.println(a);
		sc.close();
	}

}

Measured memory_bytes: 35564
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            //var line = ReadLine().Split(' ').Select(value => int.Parse(value)).ToArray();
            var n = int.Parse(ReadLine());
            var value = n;
            var root = (int)Sqrt(n);
            var answers = new List<int>();

            for(var i = 2; i <= root; i++)
            {
                while(value % i == 0)
                {
                    answers.Add(i);
                    value /= i;
                }
            }

            Write($"{n}:");
            answers.ForEach(i => Write($" {i}"));
            if(value != 1)
            {
                Write($" {value}");
            }
            WriteLine();
        }
    }
}



Measured memory_bytes: 20012
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i < (int)(n); i++)
using ull = unsigned long long;
using pii = pair<int, int>;

vector<pii> A;

int main() {
    int H, W, D;
    cin >> H >> W >> D;
    
    A.assign(H*W+1, pii(0, 0));
    int ai;
    rep(y, H) rep(x, W) {
        cin >> ai;
        A[ai] = pii(x, y);
    }

    int MP[H * W + 1] = {};
    for (int v=H*W-D; v>=1; v--) {
        int next_v = v + D;
        int abs_x = abs(A[v].first - A[next_v].first);
        int abs_y = abs(A[v].second - A[next_v].second);
        MP[v] = MP[next_v] + abs_x + abs_y;
    }

    int Q, li, ri;
    cin >> Q;
    rep(q, Q) {
        cin >> li >> ri;
        cout << MP[li] - MP[ri] << endl;
    }

    return 0;
}

 

Measured memory_bytes: 2176
#include <cstdio>
#include <algorithm>
#include <vector>
#include <iostream>
 
using namespace std;
 
vector<int>a;
 
bool dp[2][5005][5005];
 
int main() {
 
	int N, K;
 
	scanf("%d %d",&N,&K);
 
	int i,j;
 
	for (i = 0; i < N; i++) {
		int b;
		scanf(" %d", &b);
		if (b < K) {
			a.push_back(b);
		}
	}
 
	sort(a.begin(),a.end());
 
	int left = 0; 
	int right = a.size();
 
	while (left<right) {
 
		int mid = (left + right) / 2;
 
		fill(dp[0][0], dp[2][0], false);
 
		for (i = 0; i <= a.size(); i++) {
			dp[0][i][0] = true;
			dp[1][i][0] = true;
		}
		for (i = 0; i < mid; i++) {
			for (j = 0; j < K; j++) {
				if (j - a[i] >= 0) {
					dp[0][i + 1][j] = (dp[0][i][j] | dp[0][i][j - a[i]]);
				}
			}
		}
		for (i = mid+1; i < a.size(); i++) {
			for (j = 0; j < K; j++) {
				if (j - a[i] >= 0) {
					dp[1][i + 1][j] = (dp[1][i][j] | dp[1][i][j - a[i]]);
				}
			}
		}
		int flag = 0;
			for (i = K - a[mid]; i < K; i++) {
				if (flag == 1) { break; }
				for (j = 0; j <= i; j++) {
					if (dp[0][mid][j] && dp[1][a.size()][i - j]) {
						flag = 1;
						break;
					}
				}
			}
 
		if (flag == 0) {
			left = mid + 1;
		}
		else {
			right = mid;
		}
	}
 
	printf("%d\n",left);
 
 
	return 0;
}

Measured memory_bytes: 49280
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1, (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    int n;
    cin >> n;
    cout << (int)pow(2, (int)log2(n)) << endl;
    return 0;
}

Measured memory_bytes: 512
def examC():
    N = I(); D = LI()
    ans = -1
    choice = [0]*13; choice[0] +=1
    for i in D:
        choice[i] +=1
        if choice[i]>2:
            ans = 0
            break
    if choice[0]>=2 or choice[12]>=2:
        ans = 0
#    print(choice)
    curT = [0]; cur = []
    for i in range(1,12):
        if choice[i]==1:
            cur.append(i)
        elif choice[i]==2:
            curT.append(i)
            curT.append(24-i)
    ne = Counter(choice)
    if choice[12]==1:
        ne[1] -=1
        curT.append(12)
    loop = 2**(ne[1]-1)
#    print(loop)
    if ans==0:
        print(ans)
        exit()
    ans = 0
    for i in range(loop):
        now = copy.deepcopy(curT); ansC = 24
        for j in range(ne[1]-1):
            if i&(1<<j)==(1<<j):
                now.append(cur[j])
            else:
                now.append(24-cur[j])
        now.sort()
        for k in range(len(now)):
            if k != len(now) - 1:
                ansC = min(ansC, now[k+1]-now[k], 24-(now[k+1]-now[k]))
            else:
                ansC = min(ansC, now[k], 24-now[k])
        ans = max(ans, ansC)
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examC()


Measured memory_bytes: 43248
/**
 *    author:  tourist
 *    created: 31.07.2019 14:31:59       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, v, p;
  cin >> n >> m >> v >> p;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.rbegin(), a.rend());
  int low = p, high = n;
  while (low < high) {
    int mid = (low + high + 1) >> 1;
    long long total = 0;
    for (int i = 0; i < n; i++) {
      if (i < p - 1 || i >= mid - 1) {
        total += m;
      } else {
        if (a[i] > a[mid - 1] + m) {
          total = -1;
          break;
        }
        total += (a[mid - 1] + m) - a[i];
      }
    }
    if (total >= (long long) m * v) {
      low = mid;
    } else {
      high = mid - 1;
    }
  }
  cout << low << '\n';
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <map>

using namespace std;

int N, M;
int cnt[60];

int main() {
    cin >> N >> M;
    for(int i=0; i<M; i++) {
        int a, b; cin >> a >> b;
        cnt[a]++;
        cnt[b]++;
    }
    
    for(int i=1; i<=N; i++) {
        cout << cnt[i] << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ll long long
#define all(a) a.begin(), a.end() 
using namespace std;


int main() {
  int mod = 1000000007;
  int n;
  cin >> n;
  ll int a, b, c;
  a = 1;
  b = 1;
  c = 1;
  rep(i, n) {
    a*=10;
    b*=9;
    c*=8;
    a%=mod;
    b%=mod;
    c%=mod;
  }
  
  ll ans = a - 2*b + c;
  while(ans < 0) {
    ans += mod;
  }
  ans%=mod;
  cout << ans << endl;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define vlli vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vplli vector< pair< ll,ll> >
#define plli pair< ll,ll >
#define vps vector< pair< string, string> >
#define vpi vector< pair< int, int> >
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n) for(ll i=a;i<n;i++)
#define forr(i,n,a) for(ll i=n-1;i>=a;i--)
#define scan(arr,a,n) for(int i=(a);i<(n);i++)cin>>(arr)[i];
#define print(arr,a,n) for(int i=(a);i<(n);i++)cout<<(arr)[i]<<' ';

const ll inf = 1e18;

ll add(ll x, ll y) {ll res = x + y; return (res >= mod ? res - mod : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= mod ? res % mod : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + mod : res);}
ll power(ll x, ll y) {ll res = 1; x %= mod; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll mod_inv(ll x) {return power(x, mod - 2);}

int main(){
	fast;
	ll n;
	cin>>n;
	ll a[n][3], dp[n][3];
	cin>>a[0][0]>>a[0][1]>>a[0][2];
	dp[0][0] = a[0][0], dp[0][1] = a[0][1], dp[0][2] = a[0][2];
	forn(i, 1, n){
		forn(j, 0, 3){
			cin>>a[i][j];
		}
		dp[i][0] = a[i][0]+max(dp[i-1][1], dp[i-1][2]);
		dp[i][1] = a[i][1]+max(dp[i-1][0], dp[i-1][2]);
		dp[i][2] = a[i][2]+max(dp[i-1][0], dp[i-1][1]);
		
	}
	cout<<max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]))<<endl;
}

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

using namespace std;

typedef long long ll;

int main(){
	string s;
	cin >> s;
	bool flag = true;

	for(int i = 0; i < s.length(); i++){
		if(i % 2 == 0){
			if(s[i] == 'R' || s[i] == 'U' ||s[i] == 'D'){
				flag = true;
			}else{
				flag = false;
				break;
			}
		}

		if(i % 2 != 0){
			if(s[i] == 'L' || s[i] == 'U' ||s[i] == 'D'){
				flag = true;
			}else{
				flag = false;
				break;
			}
		}
	}

	if(flag) cout << "Yes" << endl;
	else cout << "No" << endl;	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    int N, K, d;
    cin >> N >> K;
    set<int> D;
    for ( int i = 0; i < K; i++ ) {
        cin >> d;
        D.insert(d);
    }
    int ans;
    for ( int i = N; i < 100000; i++ ) {
        int k = i;
        while ( k ) {
            if ( D.find(k % 10) != D.end() ) break;
            k /= 10;
        }
        if ( k == 0 ) {
            ans = i;
            break;
        }
    }
    cout << ans << '\n';
    return 0;
}

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

using namespace std;
using ll = long long;

int main() {
  string s;
  cin >> s;
  int sum;
  for (int bit = 0; bit < (1 << (s.size() - 1)); bit++) {
    sum = s[0] - '0';
    rep(i, s.size() - 1) {
      if (bit & (1 << i)) {
        sum += s[i + 1] - '0';
      } else {
        sum -= s[i + 1] - '0';
      }
    }
    if (sum == 7) {
      cout << s[0];
      rep(i, s.size() - 1) {
        if (bit & (1 << i)) {
          cout << "+" << s[i + 1];
        } else {
          cout << "-" << s[i + 1];
        }
      }
      cout << "=7" << endl;
      return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 3588
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <list>
#include <iomanip>
#include <queue>
#include <cmath>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
#define replm(i, l, r) for (ll i = l; i >= r; i--)
#define repm(i, n) repl(i, n , 0)

using namespace std;
using ll = long long;
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; }
const long long mod = 1e9 + 7;

int main() {

	int i;
	string S;

	cin >> S;

	ll N;
	N = S.size() + 1;

	vector<ll>a(N, 0);
	ll count = 100;

	while (count != 0) {
		count = 0;
		repl(i, 1, N) {
			if (S[i - 1] == '<' && a[i - 1] >= a[i]) {
				a[i] = a[i - 1] + 1;
				count++;
			}
		}
		replm(i, N - 1, 1) {
			if (S[i - 1] == '>' && a[i - 1] <= a[i]) {
				a[i - 1] = a[i] + 1;
				count++;
			}
		}
	}

	ll ans = 0;

	rep(i, N) {
		ans += a[i];
	}

	cout << ans;

	return 0;

}

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

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;


const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

struct Edge {int to, id;};

vector<vector<Edge> > g; 
vector<int> ans;

void dfs(int v, int p=-1, int pc=-1) {
    int c = 1;
    rep(i,g[v].size()) {
        int u = g[v][i].to;
        int id = g[v][i].id;
        if (u == p) continue;
        if (c == pc) ++c;
        ans[id] = c; ++c;
        dfs(u,v,ans[id]);
    }
}

int main() {
    int n;
    cin >> n;
    g.resize(n);
    rep(i,n-1) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        g[a].pb((Edge){b,i});
        g[b].pb((Edge){a,i});
    }
    ans.resize(n-1);
    dfs(0);

    int mx = 0;
    rep(i,n) mx = max(mx, (int)g[i].size());
    cout << mx << endl;
    rep(i,n-1) cout << ans[i] << endl;
    return 0;
}













Measured memory_bytes: 8320
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;
#define                          ll                          long long int
ll gcd(int a,int b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}

#define                          in(x)                       scanf("%lld",&x)
#define                          in2(x,y)                    scanf("%lld %lld",&x,&y)
#define                          in3(x,y,z)                  scanf("%lld %lld %lld",&x,&y,&z)
#define                          out(x)                      printf("%lld\n",x)
#define                          cy                          printf("YES\n")
#define                          cn                          printf("NO\n")
#define                          inf                         1e18
#define                          neg                         -1e18
#define                          fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define                          fi                          first
#define                          si                          second
#define                          ce                          cout<<endl
#define                          pb                          push_back
#define                          vc(x)                       x.begin(),x.end()
#define                          pb                          push_back
#define                          pi                          pair<ll,ll>
#define                          debug                       printf("ok\n");
#define                          pg                          pair<ll,ll>,vector<pair<ll,ll> >,greater<pair<ll,ll> >
#define                          mod                         1000000007


int main(){
 vector<ll> vt1,vt2;
      ll i,j,t,cas=0,k;

    ll n;
   in(n);
    while(n--)
    {
        ll x,y;
        in2(x,y);
        vt1.push_back(x+y);
        vt2.push_back(x-y);
    }
    sort(vc(vt1));
    sort(vc(vt2));
    ll mx=vt1[vt1.size()-1];
    ll mn=vt1[0];
    ll ans1=abs(mx-mn);
    ll mx1=vt2[vt2.size()-1];
    ll mn1=vt2[0];
    ll ans2=abs(mx1-mn1);
    out(max(ans1,ans2));



}




Measured memory_bytes: 6648
#include<iostream>
using namespace std;
int main()
{int a,b;
 cin>>a>>b;
 if (a==1) a=14;
 if (b==1) b=14;
 if (a>b)
 cout<<"Alice";
 if (a==b)
 cout<<"Draw";
 if (a<b)
 cout<<"Bob";
 system("pause");
 return 0;
}   

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


public class  Main{
	public static void main(String[] args) throws Exception{
		MScanner sc=new MScanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		int n=sc.nextInt(),k=sc.nextInt();
		int[]in=sc.takearr(n);
		int sum=0;
		for(int i=0;i<k;i++) {
			sum+=in[i]+1;
		}
		int max=sum;
		for(int i=k;i<n;i++) {
			sum-=(in[i-k]+1);
			sum+=in[i]+1;
			max=Math.max(max, sum);
		}
		pw.println(max/2.0);
		pw.flush();
	}
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] takearr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] takearrl(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public Integer[] takearrobj(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] takearrlobj(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

Measured memory_bytes: 43860
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;

#define mem(arr, i) fill(arr, arr + sizeof(arr), i)
#define MEM(arr, i) memset(arr, i, sizeof(arr))
#define Push push_back
#define Pair make_pair
#define ALL(x) x.begin(), x.end()
#define X first
#define Y second
#define ACCEL \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL); \
	cout.tie(NULL)
typedef unsigned long long ull;
typedef long long lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef pair<pll,lli> p3l;
typedef vector<int> vcI;
typedef vector<lli> vcL;
typedef vector<pii> vPI;
typedef vector<pll> vPL;
typedef vector<p3l> v3L;
typedef vector<vcL> vvL;
//typedef priority_queue<T> prior_S<T>;
//typedef priority_queue< T, vector<T>, greater<T> > prior_B<T>;
const double PI = 3.141592653589793;
const lli I_MAX = 1LL << 60;
      lli   mod = 1000000007;

/// templates ///

const lli maxN = 2E5;

vcL inv(maxN+5, 1);
vcL fac(maxN+5, 1);

void ADD(lli &x, lli y) {
	x += y;
	if (x >= mod) x -= mod;
	if (x < 0) x += mod;
}

void MUL(lli &x, lli y) {
	x *= y;
	x = (x % mod + mod) % mod;
}

lli mypow(lli b, lli e) {
	lli ans = 1;
	while (e) {
		if (e & 1) MUL(ans, b);
		MUL(b, b);
		e >>= 1;
	}
	return ans;
}

lli modinv(lli n) {
	return mypow(n, mod - 2);
}

void calcInv(lli n) {
	for (int i = 2; i <= n; ++i) {
		inv[i] = (mod - mod / i) * inv[mod % i] % mod;
	}
}

void calcFac(lli n) {
	for (int i = 2; i <= n; ++i) {
		fac[i] = fac[i - 1] * i % mod;
	}
}

lli cm(lli a, lli b) {
	lli ans = 1;
	if (a < b) return 0;

	MUL(ans, inv[fac[a - b]]);
	MUL(ans, inv[fac[b]]);
	MUL(ans, fac[a]);

	return ans;
}

lli Lucas(lli n, lli m) {
	if (m == 0) return 1;
	return cm(n % mod, m % mod) * Lucas(n / mod, m / mod) % mod;
}

lli doLucas(lli n, lli m) {
	calcInv(mod);
	calcFac(mod);
	return Lucas(n, m);
}

/// coding area ///

const lli maxn = 1E5;

void precal() {

	return;
}

void solve() {
	int m, d, cnt = 0;
	cin >> m >> d;
	
	for (int i = 1; i <= d; ++i) {
		if (i / 10 < 2 or i % 10 < 2) continue;
		if ((i / 10) * (i % 10) <= m) ++cnt;
	}
	
	cout << cnt << '\n';
}

int main() {
	precal();
	int t = 1;
	#ifdef LOCAL
		t = INT_MAX;
	#else
		ACCEL;
	#endif
//	cin >> t;
	for (int i = 1; i <= t; ++i) {
//		printf("Case #%d: ", i );
		solve();
	}
	return 0;
}



Measured memory_bytes: 3328
#include <iostream>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int main() {
  int a,b;
  cin >> a >>b;
  int ans = 0;
  rep2(i,a,b+1){
        int p=i/10000;
        int q=i%10;
        int r=(i-p*10000)/1000;
        int s=(i%100)/10;
        if (p==q && r==s) ++ans;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3584
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
int h[1010];
int main()
{
	int n,t,a,out=0;
	cin>>n;cin>>t>>a;
	rep(i,n){
		cin>>h[i];
	}
	rep(i,n){
		if(fabs(t-0.006*h[out]-a)>fabs(t-0.006*h[i]-a)) out=i;
	}
	cout<<out+1<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    int n,m,x;
    cin >> n >> m >> x;
    int bit[1<<15];
    vector<int> c(n);
    int A[15][15];
    rep(i,n){
        cin >> c[i];
        rep(j,m){
            cin >> A[i][j];
        }
    }
    int ans = 1e9;
    

    for (int bit = 0; bit < (1<<n); ++bit) {
        vector<int> S;    
        vector<int> learn(15);

        int tmp = 0;
        bool ok = true;
        for (int i = 0; i < n; ++i) {
            if (bit & (1<<i)) {
                S.push_back(i);
            }
        }

        for (int i = 0; i < (int)S.size(); ++i) {    
            tmp += c[S[i]];        
            rep(j,m){
                learn[j] += A[S[i]][j]; 
            }
        }

        rep(j,m){
            if(learn[j] < x){
                ok = false;
                break;
            }
        }
        //cout << tmp << endl;
        if(ok)ans = min(ans,tmp);
    }
    if(ans == 1e9)ans = -1;

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
# https://atcoder.jp/contests/abc156/submissions/10277689

# コンテスト中に通せたけどmodintクラスで実装してみる
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


class ModInt:
    def __init__(self, x, MOD=10 ** 9 + 7):
        '''
        pypyじゃないと地獄みたいな遅さなので注意
        '''
        self.mod = MOD
        self.x = x % MOD

    def __str__(self):
        return str(self.x)

    __repr__ = __str__

    def __add__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x + other.x, self.mod)
        else:
            return ModInt(self.x + other, self.mod)

    def __sub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x - other.x, self.mod)
        else:
            return ModInt(self.x - other, self.mod)

    def __mul__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * other.x, self.mod)
        else:
            return ModInt(self.x * other, self.mod)

    def __truediv__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * pow(other.x, self.mod - 2, self.mod), self.mod)
        else:
            return ModInt(self.x * pow(other, self.mod - 2, self.mod), self.mod)

    def __pow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(self.x, other.x, self.mod), self.mod)
        else:
            return ModInt(pow(self.x, other, self.mod), self.mod)

    __radd__ = __add__

    def __rsub__(self, other):  # 演算の順序が逆
        if isinstance(other, ModInt):
            return ModInt(other.x - self.x, self.mod)
        else:
            return ModInt(other - self.x, self.mod)

    __rmul__ = __mul__

    def __rtruediv__(self, other):
        if isinstance(other, ModInt):
            return ModInt(other.x * pow(self.x, self.mod - 2, self.mod), self.mod)
        else:
            return ModInt(other * pow(self.x, self.mod - 2, self.mod), self.mod)

    def __rpow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(other.x, self.x, self.mod), self.mod)
        else:
            return ModInt(pow(other, self.x, self.mod), self.mod)


def combination(n, r):
    if r > n:
        return 0  # このような通りの数は無いため便宜上こう定義する
    r = min(r, n - r)
    nf = rf = ModInt(1)
    for i in range(r):
        nf = nf * (n - i)
        rf = rf * (i + 1)
    return nf / rf


# すべての通り(2^n-1)からnCa,nCbを引けば良い
MOD = 10**9 + 7
n, a, b = read_ints()

tmp = ModInt(2)**n - 1
ans = tmp - combination(n, a) - combination(n, b)
print(ans)


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

using namespace std;

#define deb(x) cout << #x << " " << x << endl;

typedef long long ll;
const ll mod = 1000000007;

#define ffor(i,n) for(i=0;i<n;++i)

int main(){
    
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
    ll n;
    int a,b,i;
    cin>>a>>b;

    for(i=1;i<=1009;++i){
        if((i*8/100==a)&&(i/10==b)){
            cout<<i;
            break;
        }
    }
    if(i==1010)
        cout<<"-1";


    cerr << "\n\nTime elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<int ,P> P3;
typedef pair<P ,P> PP;
const ll MOD = ll(1e9+7);
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

int main() {
    ll l, n, m=0;
    cin >> l >> n;
    REP(i,n){
        ll x, w;
        cin >> x >> w;
        m += x*w;
    }
    if(abs(m)>0){
        cout << 1 << endl;
        cout << -m/abs(m) << " " << abs(m) << endl;
    }
    else cout << 0 << endl;
    return 0;
}



Measured memory_bytes: 3112
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file 
//#include <ext/pb_ds/tree_policy.hpp> 
#define int long long
#define pb push_back
#define ff first
#define ss second
#define ii insert
#define ld long double
#define ppb pop_back
#define nuenxfiu ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define input freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout);
#define TT int testcases;cin>>testcases;while(testcases--)
#define mk make_pair
#define MAX ((int)2e9+17)
#define N 200005
#define mod ((int)1e9+7)
#define MOD 1000003
//int fact[1000007]={0};
int fpow(int n, int k, int p = mod) {int r = 1; while(k > 0) {if (k & 1) r = r * n%p; n = n * n%p; k = k >> 1;} return r;}
int expo(int x,int y){ int res=1; while(y) {if(y%2) res=(res*x%mod)%mod; x=(x*x)%mod; y/=2; } return res;}
int sub(int a, int b) {return (a%mod - b%mod + mod)%mod;}
int mul(int a, int b) {return ((a%mod)*(b%mod) + mod)%mod;}
int inv(int x) {return expo(x, mod-2);}
using namespace std;





void solve()
{
	string s;
	cin>>s;
	cout<<s[0]<<s[1]<<s[2]<<endl;
	
}
signed main()
{
    
	nuenxfiu
	//TT
	solve();
     return 0;
}

Measured memory_bytes: 3548
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <utility>
#include <set>
#include <unordered_map>

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define IPSILON 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  vector<int> C(N-1);
  for(int i =0;i<N;i++){
    cin >> A[i];
  }
  for(int i =0;i<N;i++){
    cin >> B[i];
  }
  for(int i =0;i<N-1;i++){
    cin >> C[i];
  }

  int res = 0;
  for(int i=0; i<N;i++){
    res += B[A[i]-1];
    //    cout << B[A[i]-1] << endl;
    if(i > 0 && (A[i] - A[i-1] == 1)){
      res += C[A[i]-2];
      //      cout << "C "<<C[A[i] -2] << endl;
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 888
#include<iostream>
int a[50];
int main(void)
{
	int n;
	int k = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
		if (a[i] != i + 1)
		{
			k++;
		}
	}
	if (k <= 2)
	{
		printf("YES\n");
	}
	else
	{
		printf("NO\n");
	}
	return 0;
}

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

int main() {
	ll N,x=0;
	cin >> N;
	vector<ll> a(N);

	rep(i,N) {
		cin >> a.at(i);
		x ^= a.at(i);
	}

	rep(i,N)
		cout << (a.at(i)^x) << " ";
	cout << endl;
}

Measured memory_bytes: 4708
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstdlib>

using namespace std;

#define int long long

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

constexpr int TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); };

const int inf = TEN(18) + 10;

int N, X, D, sum;
int a[55];

int f(int y)
{
	int sousa = 0;

	rep(i, N) sousa += max((a[i] - y) / D, 0ll);

	return sousa;
}

signed main()
{
	cin >> N;

	rep(i, N) {
		cin >> a[i];
	}

	rep(i, N) {
		sum += a[i];
	}

	// X, D を定義する
	X = max(sum - (N-1) * N, 0ll);
	D = N + 1;
	
	// はじめに a[i] それぞれに X を足してしまう
	rep(i, N) a[i] += X;

	// 二分探索で f(Y) <= X となる最大の Y を求める(hi = Y となるようにしているつもり) 
	int lo = -1, hi = inf, step = -1;
	while (hi - lo > 1) {
		int mid = (hi + lo) / 2;

		if (f(mid) <= X) {
			step = f(mid); // それがf(Y) の値も念のため step に保存しておく
			hi = mid;
		} else {
			lo = mid;
		}
	}
	//cout<<step<<endl;
  
	// わかりやすさのため hi を max_Y とする
	int max_Y = hi;
  
	rep(i, N) {
      
		a[i] = a[i] - max((a[i] - max_Y) / D, 0ll) * D;
	}
	
	//cout<<step<<endl;
	// デバッグのために a を出力してる
	//rep(i, N) printf("%lld%c", a[i], i==N-1?'\n':' ');

	// すべての i について a[i] <= N - 1 を満たすまで愚直にシミュレーション
	while (true) {
		bool ok = true;
		rep(i, N) {
			if (a[i] >= N) ok = false;
		}

		if (ok) break;

		int mx = -inf, idx = -1;

		rep(i, N) {
			if (mx < a[i]) {
				mx = a[i];
				idx = i;
			}
		}
      	step++;
		if(step>X){
			a[idx] -=N;
      		rep(i, N) {
				if (idx!=i) {
					a[i]++;
				}
			}
        }else{
         a[idx]-=D; 
        }
        
      

		// デバッグ
		//rep(i, N) printf("%lld%c", a[i], i==N-1?'\n':' ');
	}

	printf("%lld\n", step);
}


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

int cnt[26];

int main(void){
  char buf[128];
  int ans = true;
  cin >> buf;
  for (char *p=buf; *p; p++){
    cnt[*p-'a']++;
  }
  for (int i=0; i<26; i++){
    if (cnt[i]%2) ans = false;
  }
  
  cout << (ans?"Yes":"No") << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
 
int sum(ll x){
    if (x == 0) return 1e9;
    int ret = 0;
    while (x){
        ret += x % 10;
        x /= 10;
    }
    return ret;
}
 
const int N = 100000;
// int dp[N], k, visit[N];
 
// int calc(int x){
//     if (dp[x] >= 0) return x;
//     visit[x] = 1;
//     int ret = sum(x);
//     REP(i,10){
//         int y = x + i * k;
//         if (visit[y/10] && dp[y/10] == -1) continue;
//         ret = min(ret, (y % 10) + calc(y/10));
//     }
//     cout << x << " " << ret << endl;
//     return dp[x] = ret;
// }
#define INF 1e15
 
struct edge{ll to,cost;};
 
void dijkstra(VL &d, vector<vector<edge> > graph){
    fill(ALL(d), INF);
    d[0] = 0;
    priority_queue<P, vector<P>, greater<P> > q;
    q.push(make_pair(0, 0));
    while (!q.empty()){
        P a = q.top();
        q.pop();
        int now = a.second;
        if(d[now] < a.first) continue;
        REP(i,graph[now].size()){
            edge e = graph[now][i];
            int next = e.to;
            if (d[next] > d[now] + e.cost){
                d[next] = d[now] + e.cost;
                q.push(make_pair(d[next], next));
            }
        }
    }
}
 
vector<vector<edge> > eg(N+10);
 
int main() {
    int k;
    cin >> k;
 
    REP(i,N){
        REP(j,10){
            int x = i + j * k;
            eg[i].push_back((edge){x/10, x%10});
        }
        eg[i].push_back((edge){N+1, sum(i)});
    }
 
    VL d(N+10);
    dijkstra(d, eg);
 
    cout << d[N+1] << endl;
 
    // REP(i,10) cout << d[i] << endl;
 
 
 
    // REP(i,N) dp[i] = -1;
    // cout << calc(0) << endl;
 
    // int ans = 1e9;
    // FOR(i,1,300000){
    //     ans = min(ans, sum((ll)k * i));
    //     // if (sum((ll)k*i) == 7) cout << i << endl;
    // }
    // cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 53240
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <cmath>

using namespace std;

int main(){
    int n; cin >> n;
    unordered_map<string, int> mp;
    for(int i=0; i<n; ++i){
        string s; cin >> s;
        sort(s.begin(), s.end());
        ++mp[s];
    }
    long long ans=0;
    for(auto p : mp){
        long long m=p.second;
        ans+=m*(m-1)/2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 10660
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//
//    #pragma GCC optimize("unroll-loops")
//    #pragma GCC optimize("Ofast")
//    #pragma GCC optimize("-O3")
//    #pragma GCC optimize("no-stack-protector")
//    #pragma GCC optimize("fast-math")

#define fi first
#define f first
#define se second
#define s second
#define vi_a vector<int>a;
#define p_b push_back
////////////////////////////////???????????????CHECK THIS OUT???????????????//////////////////////////////
#define ll long long
////////////////////////////////???????????????CHECK THIS OUT???????????????//////////////////////////////
#define ld long double
#define pll pair<ll,ll>
#define pii pair<int,int>
#define m_p make_pair
#define fast_io cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
#define all(x) x.begin(),x.end()
#define getfiles    ifstream cin("input.txt");ofstream cout("output.txt");
#define pw(x) (1ll << x)
#define sz(x) (ll)x.size()
#define endl "\n"
#define rall(x) x.rbegin(),x.rend()
#define len(a) (ll)a.size()
#define rep(x,l,r) for(ll x=l;x<r;x++)
//#define for(int i=0;i<n;i++) for(ll i=0;i<n;i++)
using namespace std;
//using namespace __gnu_pbds;
ld eps = (ld)1 / 1e6;
ll inf = 1e18, mod2 = 998244353, mod1 = 1e9 + 7;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//const ll to[5]={0,4,6,7,9};
//const ll N=2*1e5+1;
const ll R=1e4;
//const ll to[7]={1,2,3,1,3,2,1};
const ll tx[4]={0,0,-1,1};
const ll ty[4]={-1,1,0,0};
const char rev_to[4]={'E','W','N','S'};
const ll N=2*1e5+4;
//set<int> lol2[26][26];
set<int>ab;
set<int>ba;
signed main(){
    fast_io;
    ld a,b;
    cin>>a>>b;
    cout<<(ll)(a*b);
    return 0;
}
/*
    aa
    bb
    если WA , то чекер говно, поэтому почекай l8 строчку
    !x || !y x-проигрышная или выигрышная , y-колво таких позиций
    x==0 проигрышная
    y==0 четное проигрышных или четное выигрышных
    x==0 && y==0 четное проигрышных
*/


Measured memory_bytes: 3744
#include<stdio.h>
#include<math.h>
int IsPrime(int n);
int main(){
  int n,i,j,count,ans[1000000];
  j=0;
  while(1){
    scanf("%d",&n);
    if(n==0)
      break;
    count=0;
    for(i=n+1;i<=2*n;i++){
      if(IsPrime(i)){
	count++;
      }
    }
    ans[j]=count;
    j++;
  }
  for(i=0;i<j;i++)
    printf("%d\n",ans[i]);
  return 0;
}

int IsPrime(int n){
  int i,limit;
  if(n==2)
    return 1;
  if(n<2 || n%2==0)
      return 0;
  limit = (int)sqrt((double)n);
  for(i=3;i<=limit;i+=2)
    if(n%i==0) return 0;
  return 1;
}

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

int main()
{
    int N, M;
    cin >> N >> M;
    if(N%2==1){
        int a=0;
        int b=1;
        for(int i=0; i<M; i++){
            cout << (a+1) << " " << (b+1) << endl;
            a = (N+a-1)%N;
            b = (N+b+1)%N;
        }
    }else{
        int a=0;
        int b=1;
        for(int i=0; i<M; i++){
            cout << (a+1) << " " << (b+1) << endl;
            a = (N+a-1)%N;
            b = (N+b+1)%N;
            if(i == ((N-2)/2+1)/2-1){
                b = (N+b+1)%N;
            }
        }
    }

    return 0;
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "cycle"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 2e5 + 5;

vi g1[MAXN], g2[MAXN];

int used1[MAXN], used2[MAXN];

int dis1[MAXN], dis2[MAXN];

int tin2[MAXN], tout2[MAXN], _t, prv2[MAXN];

bool is_prv(int a, int b){
	return tin2[a] <= tin2[b] && tout2[b] <= tout2[a];
}

bool check_dis_le_2(int a, int b){
	if (abs(dis2[a] - dis2[b]) > 2){
		return false;
	}
	if (is_prv(a, b) || is_prv(b, a)){
		return true;
	}
	if (prv2[a] == prv2[b]){
		return true;
	}
	return false;
}

int ans;
int ans1;

void dfs1(int s){
	used1[s] = 1;
	ans = max(ans, 2 * dis2[s]);
	REP(i, 0, SZ(g1[s])){
		int to = g1[s][i];
		if (!used1[to]){
			dis1[to] = dis1[s] + 1;
			if (!check_dis_le_2(s, to)){
				ans1 = 1;
			}
			if (dis1[to] < dis2[to]){
				dfs1(to);
			}
		}
	}
}

void dfs2(int s){
	used2[s] = 1;
	tin2[s] = tout2[s] = _t++;
	REP(i, 0, SZ(g2[s])){
		int to = g2[s][i];
		if (!used2[to]){
			prv2[to] = s;
			dis2[to] = dis2[s] + 1;
			dfs2(to);
			tout2[s] = tout2[to];
		}
	}
}

void solve(){
	int n, a, b, s1, s2;
	scanf("%d%d%d", &n, &s1, &s2);
	REP(i, 1, n){
		scanf("%d%d", &a, &b);
		g1[a].pb(b);
		g1[b].pb(a);
	}
	REP(i, 1, n){
		scanf("%d%d", &a, &b);
		g2[a].pb(b);
		g2[b].pb(a);
	}
	dfs2(s2);
	dfs1(s1);
	if (ans1 == 1){
		ans = -1;
	}
	printf("%d\n", ans);
}	

int main(){

	//freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();	
	}
}

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

using namespace std;
int main()
{
  int a, b;
  cin >> a >> b;
  string answer;
  
  if (a > b) {
    for(int i = 0; i < a; i++) answer = answer + to_string(b);
  } else {
    for(int i = 0; i < b; i++) answer = answer + to_string(a);
  }
  
  cout << answer << endl;
}

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

string s;
int dp[2][3][10][500][501]; //[free][増減][prev][余り][index]
int m;

int solve( bool fr, int updw, int pre, int mod, int index){
  if( index == s.size() ) return !mod;
  if( dp[fr][updw][pre][mod][index] != -1 ) return dp[fr][updw][pre][mod][index];
  int ret = 0, end = fr ? 9 : s[index];
  for(int i = 0, u ; i <= end ; i++ ){
    switch(updw){
    case 0: //さいしょ
      if( pre && pre == i ) continue;
      else if( pre == 0 ) u = 0;
      else if( pre > i ) u = 1;
      else u = 2;
      break;
    case 1: //次あっぷ
      if( pre >= i ) continue;
      else u = 2;
      break;
    case 2: //次だうん
      if( pre <= i ) continue;
      else u = 1;
      break;
    }
    ret += solve( fr|(i!=s[index]), u, i, (mod*10+i)%m, index+1);
  }
  return dp[fr][updw][pre][mod][index] = ret % MOD;
}

void java(){
  for(int i = s.size() - 1 ; i >= 0 ; i-- ){
    if(s[i] == 0) s[i] = 9;
    else{
      s[i]--;
      break;
    }
  }
}

int main(){
  string s1;
  cin >> s >> s1 >> m;
  for(int i = 0 ; i < s.size() ; i++ ) s[i] -= '0';
  java();
  fill_n( ****dp, 2 * 3 * 10 * 500 * 501, -1);
  int an = solve( 0, 0, 0, 0, 0);
  s = s1;
  for(int i = 0 ; i < s.size() ; i++ ) s[i] -= '0';
  fill_n( ****dp, 2 * 3 * 10 * 500 * 501, -1);
  int bn = solve( 0, 0, 0, 0, 0);
  cout << ( bn - an + MOD ) % MOD << endl;
}

Measured memory_bytes: 59996
#include<iostream>
#include<cstdio>
#include<set>
#include<cstdlib>
using namespace std;
int n,m;
int a[200010];
int b[200010];
int ans;
int fg[200010]; 
int main()
{
	scanf("%d%d",&n,&m);
	ans=n;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",b+i);
		a[b[i]]++;
		int p=b[i]-a[b[i]]+1;
		if(p>=1)
		{
			fg[p]++;if(fg[p]==1)ans--;
		}
	}
	for(int k=1;k<=m;k++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		int p=b[x]-a[b[x]]+1;
		a[b[x]]--;
		if(p>=1)
		{
			fg[p]--;if(fg[p]==0)ans++;
		}
		a[y]++;
		b[x]=y;
		p=b[x]-a[b[x]]+1;
		if(p>=1)
		{
			fg[p]++;if(fg[p]==1)ans--;
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 3712
#include <stdio.h>

int main(void) {
	int n, x, i, j, k, m;
	scanf("%d%d", &n, &x);
	while (n!=0 || x!=0)
	{
		m=0;
		for (i=1; i<=n-2; i++)
		{
			for (j=i+1; j<=n-1; j++)
			{
				for (k=j+1; k<=n; k++)
				{
					if (i+j+k==x)
					{
						m+=1;
					}
				}
			}
		}
		printf("%d\n", m);
		scanf("%d%d", &n, &x);
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
ll n, m, t, a[100005];
vector< ll > adj[100005];
#define ari for( int i = 0 ; i < n ; i++ ) cin >> a[i];
#define ginp for( int i = 0 ; i < m ; i++ ){ int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u);}
#define pb push_back
#define ss second
#define ff first
#define fs first.second
#define fff first.first
#define sss second.second
#define sf second.first
#define mp make_pair

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    string s;
    cin >> s;
    string k = s;
    ll ctr = 0;
    sort(s.begin(), s.end());
    for(int i = 0 ; i < n ; i++){
    	if( s[i] == 'R' and k[i] != 'R' )
    		ctr++;
    }
    cout << ctr << endl;
	return(0);
}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    Int(n);
    vector<int> data(n-1);
    for (int i = 0; i < n-1; i++) {
        cin >> data[i];
    }
    
    vi ans(n, INF);
    rep(i, n-1) {
        ans[i] = min(ans[i], data[i]);
        ans[i+1] = min(ans[i+1], data[i]);
    }

    int ret = 0;
    rep(i, n) {
        ret += ans[i];
    }

    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){

int x,y,i;

while(1){
  scanf("%d %d",&x,&y);
  if(x == y && x == 0){
  break;
}else if(x > y){
i = x;
x = y;
y = i;
printf("%d %d\n",x,y);
}else{
printf("%d %d\n",x,y);
}
}

return 0;
}


Measured memory_bytes: 1988
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vecl = vector<ll>;
using Graph = vector<vector<int>>;
/* #1 想定解（queueを用いた解法）

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll K;
  cin >> K;
  ll num = 0;
  queue<ll> que;
  REP(i, 9) que.push(i + 1);
  while (K > 0) {
    num = que.front();
    //    cout << num << " ";
    if (num % 10 != 0) que.push(10 * num + num % 10 - 1);
    que.push(10 * num + num % 10);
    if (num % 10 != 9) que.push(10 * num + num % 10 + 1);
    que.pop();
    K--;
  }
  cout << num << endl;
  return 0;
}
*/

// #2 DFSを用いた解法
vector<ll> LIST;

void dfs(ll num, ll k) {
  if (k == 0) {
    LIST.push_back(num);
    return;
  } else if (num == 0) {
    REP(i, 10) dfs(i * pow(10, k - 1), k - 1);
    return;
  }
  ll p = pow(10, k);
  ll x = (num / p) % 10;
  if (x != 0) dfs(num + (x - 1) * pow(10, k - 1), k - 1);
  dfs(num + x * pow(10, k - 1), k - 1);
  if (x != 9) dfs(num + (x + 1) * pow(10, k - 1), k - 1);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll K;
  cin >> K;
  //  REP(i, 8) LIST.push_back(i + 2);
  dfs(0, 10);
  //sort(LIST.begin(), LIST.end());
  // REP(n, 30) cout << LIST.at(n) << " ";
  cout << LIST.at(K) << endl;
  return 0;
}


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

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector <int> A(n);
	vector <int> B(n);
	for (int i = 0; i < n; i++) {
		cin >> A[i];
		B[i] = A[i];
	}

	sort(B.begin(), B.end());
	for (int i = 0; i < n; i++) {
		if (A[i] == B[n - 1])  cout << B[n - 2] << endl;
		else  cout << B[n - 1] << endl;
	}

}



Measured memory_bytes: 3200