akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define ll long long 

int main() {
    ios::sync_with_stdio(0); 

    ll n, k;
    cin >> n >> k;

    if (k == 1 or n == k) cout << 0;
    else {
        if (n < k) cout << min(n, k-n);
        else if (n % k == 0) cout << 0;
        else cout << min(n % k, k - (n % k));
    }

    cout << endl;

    return 0; 
}



Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long int> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long int>> vvl;
typedef pair<int, int> pii;
typedef pair<long long int, long long int> pll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long int, long long int>> vll;
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test() long long int t; cin >> t; cin.ignore(); while(t--) 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define MOD 1000000007
#define SMOD 998244353
#define pq priority_queue
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sp " "
#define inp(a) ll a;cin>>a;cin.ignore()
#define inps(a,b) ll a,b;cin>>a>>b;cin.ignore()
#define out(a) cout<<SP(20)<<a<<'\n'
#define outs(a,b) cout<<SP(20)<<a<<" "<<b<<'\n'
#define ins insert
#define er erase
#define lb lower_bound
#define ub upper_bound
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define inpa(a,n) ll a[n]; for(int i=0; i<n; i++){cin>>a[i];}
#define inpv(a,n) vl a; for(int i=0; i<n; i++){inp(x);a.pb(x);}
#define outa(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}cout<<'\n';
#define outv(v) for(auto i:v){cout<<i<<" ";}cout<<'\n';
set<char> vow = {'a','e','i','o','u','A','E','I','O','U'};
ll xpow(ll n, ll m){if(m==0){return 1;}else{ll x = xpow(n, m/2);if(m&1){return x*x*n;}else{return x*x;}}}
ll xmod(ll a, ll m){return (((a%m)+m)%m);}
ll xmodpow(ll n, ll m, ll y){if(m==0){return 1;}else{ll x = xmodpow(n, m/2, y);if(m&1){return xmod((xmod((xmod(x,y)*xmod(x,y)),y)*xmod(n,y)),y);}else{return xmod((xmod(x,y)*xmod(x,y)),y);}}}

// ld PI = 3.141592653589793238462643383279502884197169399375105820974944592307816406286;
ld PI = acos(-1);

int main(){
    fast();

/* you get what you work for not what you wish for */

    ld a, b, x;
    cin >> a >> b >> x;
    ld h1 = x/(a*a);
    ld h2 = b-h1;
    if(((a*b)/2)==h1*a){
        ld ans = 45;
        cout << SP(30) << 45 << endl;
    }
    else if(((a*b)/2)>h1*a){
        ld x = 2*h1*a/b;
        ld ang = (ld)atan(b/x)*180/PI;
        cout << SP(30) << ang << endl;
    }
    else{
        ld x = 2*h1 - b;
        ld y = b-x;
        ld ang = (ld)atan(y/a)*180/PI;
        cout << SP(30) << ang << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (rint i = 1; i <= int(n); i ++)
#define re0(i, n) for (rint i = 0; i < (int) n; i ++)
#define travel(i, u) for (rint i = head[u]; i; i = e[i].nxt)
#define rint register int
using namespace std;

typedef long long lo;

template<typename tp> inline void read(tp &x) {
    x = 0; char c = getchar(); int f = 0;
    for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
    for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
    if (f) x = -x;
}

namespace {
    const int mo = 1e9 + 7;
    inline int add(int x, int y) { x += y; return x >= mo ? x - mo : x; }
    inline int sub(int x, int y) { x -= y; return x < 0 ? x + mo : x; }
    inline int mul(int x, int y) { return (lo) x * y % mo; }
    inline int power(int a, int k = mo - 2) {
		int ans = 1;
		for (; k; k >>= 1, a = mul(a, a))
			if (k & 1) ans = mul(ans, a);
		return ans;
    }
	inline void U(int &x, int y) { x = add(x, y); } 
}

const int N = 1e6 + 233;
int n, fac[N], ifac[N], dp[N][3];
inline int C(int n, int m) {
	return n < m ? 0 : mul(fac[n], mul(ifac[m], ifac[n - m]));
}

int main(void) {
	read(n);
	int m = n + 2;
	fac[0] = 1;
	rep (i, m) fac[i] = mul(fac[i - 1], i);
	ifac[m] = power(fac[m]);
	for (int i = m - 1; i >= 0; i--)
		ifac[i] = mul(ifac[i + 1], i + 1);
	dp[0][0] = 1;
	rep (i, n) re0 (pre, 3) re0 (cur, 3)
		if (cur != pre) U(dp[i][cur], dp[i - 1][pre]);
	int ans = 0;
	rep (k, n) {
		int F = mul(dp[k][1], mul(C(n, k), power(power(3), n - 1)));
		int G = power(mul(3, mul(n, k)));
		U(ans, mul(F, G));
	}
	cout << ans << "\n";
}


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

typedef int i32;
typedef long long i64;
typedef unsigned int u32;
typedef unsigned long long u64;


template<typename First, typename Second, typename Third>
struct triple {
   First first;
   Second second;
   Third third;
};


#define debug(x)  cerr<<x<<"\n";
#define loop(i,n) for(i32 i = 0; i < n; ++i)
#define pi  pair<i32,i32>
#define ti  triple<i32,i32,i32>
#define mk  make_pair
#define vi  vector<i32>
#define vll vector<i64>
#define fastInOut ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pr(a) for(auto x:a) cout<<x<<" ";
#define prmap(m) for(auto x:m) cout<<x.first<<" "<<x.second<<"\n";
using namespace std;

bool isPrime(i64 x){
	
	for(i64 i=2;i*i<=x;i++)
		if(x%i==0)
			return false;
	return true;
}

vi V;
const i32 N=7e7+9;
bool prime[N]; 
void SieveOfEratosthenes() 
{
    for (int  p=2; p*p<=N; p++){ 
        if (prime[p] == false){ 
            for (int  i=p*p; i<=N; i += p) 
                prime[i] = true; 
        } 
    } 
    int u=0,mx=0;
    for (int p=2; p<=N; p++) 
      if (!prime[p]) {
         V.push_back(p);
    }
   
}
i32 H,W;
void solve(){
        cin >> H >> W;
        char c[H+1][W+1];
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++)
                    cin >> c[i][j];
	}
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			if (c[i][j] == '#' && c[i][j - 1] != '#' && c[i - 1][j] != '#' && c[i][j + 1] != '#' && c[i + 1][j] != '#'){
                             cout<<"No";return ;
                        }
		}
	}
	cout << "Yes";
}
int main(){
    fastInOut
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
	int A,B,C;
	cin>>A>>B>>C;
	int X=C-(A-B);
	if (X>0){
		cout<<X<<endl;
	}else{
		cout<<0<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define all(vec) vec.begin(),vec.end()
#define ggr getchar(); getchar();return 0;
#define ll long long
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 1)return 1;
	return kai(x - 1)*x%mod;
}

int mod_pow(int x, int y, int moder) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%moder;
		x = x * x%moder;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	if (x == y)return 1;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}

string s;
int ans = INF;

signed main() {
	cin >> s;
	rep(i, (int)s.size() - 1) {
		if (s[i] != s[i + 1])ans = min(ans, max(i + 1, (int)s.size() - i - 1));
	}
	if (ans == INF)ans = s.size();
	cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <climits>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <map>
#include <tuple>
#include <iostream>
#include <deque>
#include <array>
#include <set>
#include <functional>
#include <memory>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <numeric>


struct NextHead {
	int index, step;
	NextHead() {};
	NextHead(const int i, const int s) : index{ i }, step{ s }{};
};
std::vector<NextHead> cal_next(const std::vector<int>& series) {
	std::vector<int> prev_index(2000000 + 1, -1);
	std::vector<NextHead> result(series.size());
	for (auto i = 0; i < series.size(); ++i) {
		if (prev_index[series[i]] != -1) {
			result[prev_index[series[i]]] = NextHead((i + 1) % series.size(), i - prev_index[series[i]] + 1 );
		}
		prev_index[series[i]] = i;
	}
	for (auto i = 0; i < series.size(); ++i) {
		if (prev_index[series[i]] != -1) {
			result[prev_index[series[i]]] = NextHead( (i + 1) % series.size(), (i == prev_index[series[i]]) ? series.size() + 1 : (i - prev_index[series[i]] + 1 + series.size()) % series.size() );
			prev_index[series[i]] = -1;
		}
	}
	return result;
}
int main() {
	int n; long long int k; std::cin >> n >> k;
	k *= n;
	std::vector<int> series(n); for (auto& s : series) std::cin >> s;
	std::vector<NextHead> nexts = cal_next(series);
	std::vector<long long int> loop_count(n, -1);
	int current = 0;
	long long int current_step = 0LL;
	while (loop_count[current] == -1 && current_step + nexts[current].step <= k) {
		loop_count[current] = current_step;
		current_step += nexts[current].step;
		current = nexts[current].index;
	}
	long long int rest = k - current_step;
	if (loop_count[current] != -1) {
		rest %= current_step - loop_count[current];
		while (nexts[current].step <= rest) {
			loop_count[current] = current_step;
			rest -= nexts[current].step;
			current = nexts[current].index;
		}
	}
	std::vector<bool> set(200000 + 1, false);
	std::vector<int> result;
	for (auto i = 0; i < rest; ++i) {
		if (!set[series[current]]) {
			set[series[current]] = true;
			result.push_back(series[current]);
		}
		else {
			while (result.back() != series[current]) {
				set[result.back()] = false;
				result.pop_back();
			}
			set[result.back()] = false;
			result.pop_back();
		}
		current = (current + 1) % series.size();
	}
	for (auto i = 0; i < result.size(); ++i) {
		if (i != 0) std::cout << ' ';
		std::cout << result[i];
	}
	std::cout << std::endl;
}

Measured memory_bytes: 10368
#include <stdio.h>

int main() {
    int i=0, j=0;
    int N, f=0;
    scanf("%d",&N);
    int A[N];

    for(i=0;i<N;++i){
        scanf("%d",&A[i]);
        A[i] -= 1;
        f += A[i];
    }
    printf("%d", f);
    return 0;
}

Measured memory_bytes: 128
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE RankNTypes #-}
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
-- import Data.List
-- import qualified Data.Vector.Unboxed as VU
-- import qualified Data.Vector.Unboxed.Mutable as VUM
-- import Control.Monad
-- import Control.Monad.ST
-- import Debug.Trace
-- trace _ = id

data Edge = Init | One | Two

solve :: Int -> String -> String -> Int
solve bN sA sB = calc 1 Init (zip sA sB)
  where
  calc !acc edge [] = acc
  calc !acc edge ((s,t):ps) = calc (mMul acc (coe edge newEdge)) newEdge newPs
    where
      (newEdge, newPs) | s == t    = (One, ps)
                       | otherwise = (Two, tail ps)
      coe Init One = 3
      coe Init Two = 6
      coe One One = 2
      coe One Two = 2
      coe Two One = 1
      coe Two Two = 3

-------------------------------------------------------------------------------

mPrime = 10^9 + 7

mAdd :: Int -> Int -> Int
mAdd x y = let w = x + y in if w < mPrime then w else w - mPrime
-- mAdd x y = (x + y) `mod` mPrime

mSub :: Int -> Int -> Int
mSub x y = let w = x - y in if w >= 0 then w else w + mPrime
-- mSub x y = (x - y) `mod` mPrime    -- ok even if x < y

mMul :: Int -> Int -> Int
mMul x y = (x * y) `mod` mPrime

readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

tmain :: B.ByteString -> Int
tmain cont =
  let remLines0 = map B.words (B.lines cont)
      [bs_bN]:remLines1 = remLines0
      bN = readBInt bs_bN
      [bs_sA]:remLines2 = remLines1
      sA = B.unpack bs_sA
      [bs_sB]:remLines3 = remLines2
      sB = B.unpack bs_sB
  in solve bN sA sB

outAnswer :: Int -> IO ()
outAnswer = putStrLn . show

main :: IO ()
main = outAnswer . tmain =<< B.getContents


-------------------------------------------------------------------------------

inp1 = "3\naab\nccb\n"
inp2 = "1\nZ\nZ\n"
inp3 = "52\nRvvttdWIyyPPQFFZZssffEEkkaSSDKqcibbeYrhAljCCGGJppHHn\nRLLwwdWIxxNNQUUXXVVMMooBBaggDKqcimmeYrhAljOOTTJuuzzn\n"
tv1 = tmain $ B.pack inp1
tv2 = tmain $ B.pack inp2
tv3 = tmain $ B.pack inp3
test1 = tv1 == 6
test2 = tv2 == 3
test3 = tv3 == 958681902
alltest = test1 && test2 && test3



Measured memory_bytes: 380
#!/usr/bin/env ruby

while (h, w = gets.chomp.split.map(&:to_i)) != [0, 0]
  maps = []
  h.times do
    maps << gets.chomp.split('')
  end

  x = 0
  y = 0
  while maps[y][x] != '.' && maps[y][x] != 'x'
    k = maps[y][x]
    maps[y][x] = 'x'
    case k
    when '>'
      x += 1
    when '<'
      x -= 1
    when '^'
      y -= 1
    when 'v'
      y += 1
    end
  end

  if maps[y][x] == '.'
    puts "#{x} #{y}"
  else
    puts 'LOOP'
  end
end

Measured memory_bytes: 7000
#include <iostream>
using namespace std;
typedef long long ll;
ll n,m,a,b,c,dp[10][10],ans,MAX=1e18;
int main(void){
    cin>>n>>m;
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            cin>>dp[i][j];
        }
    }
    for(int k=0;k<10;k++){
        for(int i=0;i<10;i++){
            for(int j=0;j<10;j++){
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
            }
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>a;
            if(a==-1)continue;
            ans+=dp[a][1];
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int main(void){
	char s[11];
	scanf("%s",s);
	printf("2018/01/%c%c\n",s[8],s[9]);
	return 0;
}

Measured memory_bytes: 128
//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e2);

//Required Functions

ll power(ll x,ll y) 
{ 
	if (y == 0) 
		return 1; 
	ll p = power(x, y/2) % MOD; 
	p = (p * p) % MOD; 
  
	return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work


ll dp[INIT][11];
int main()
{
	#ifndef ONLINE_JUDGE
	if (fopen("INPUT.txt", "r"))
	{
		freopen ("INPUT.txt" , "r" , stdin);
		//freopen ("OUTPUT.txt" , "w" , stdout);
	}
	#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	clock_t clk;
	clk = clock();
//-----------------------------------------------------------------------------------------------------------//

	READV(K);
	FORI(i,0,10)
	{
		dp[0][i]=1;
	}
	vector<ll> ans;
	ll tot=0;
	if(K<=9)
	{
		cout<<K<<endl;
		return 0;
	}
	tot+=9;
	FORI(i,1,INIT)
	{
		FORI(j,1,10)
		{
			dp[i][j]=(dp[i-1][j-1]+dp[i-1][j]+dp[i-1][j+1]);
		}
		FORI(j,1,10)
		{
			tot+=dp[i][j];
			if(tot>=K)
			{
				ans.pb(j);
				tot=tot-dp[i][j];
				K-=tot;
				ll curr=i-1;
				ll currv=j;
				while (curr>=0)
				{
					tot=0;
					FORI(l,currv-1,currv+2)
					{
						tot+=dp[curr][l];
						if(tot>=K)
						{
							tot=tot-dp[curr][l];
							K-=tot;
							currv=l;
							ans.pb(l);
							curr--;
							break;
						}
					}
				}
				break;
			}
		}
		if(sz(ans)>0)
		{
			break;
		}
		dp[i][0]=dp[i-1][0]+dp[i-1][1];
	}
	for(auto x:ans)
	{
		cout<<x;
	}
	cout<<endl;

//-----------------------------------------------------------------------------------------------------------//


	clk = clock() - clk;
	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int n,m;
	scanf("%d %d",&n,&m);
	int a[n];
	int sum=0;
	int c=0;
	for(int i=0; i<n; i++){
		scanf("%d",&a[i]);
		sum+=a[i];
	}
	double line=sum/(4.0*m);
	for(int i=0; i<n; i++){
		if(a[i]>=line){
			c++;
		}
	}
	if(c>=m){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 128
//#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;

#define boost ios::sync_with_stdio(0); cin.tie(0)

#define fi first
#define se second

typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;

const int N = 1e6 + 5;

/***************************************************************************/

int main() {

	boost;
	string S; cin>>S;
	ll k; cin>>k;

	int p = S.length();
	for(int i=0; i<p; i++) {
		if(S[i] != '1') {
			p = i;
			break;
		}
	}

	if(k <= p) cout<<"1\n";
	else cout<<S[p]<<"\n";
	
	return 0;
}

Measured memory_bytes: 256
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
from fractions import gcd
import math
def resolve():
    A,B=pin()
    X=lispin()
    temp=abs(B-X[0])
    for x in X:
        temp=gcd(temp,abs(B-x))
    print(temp)
    
#%%submit!
resolve()

Measured memory_bytes: 88172
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int x,a,b;
cin >> x >> a >> b;
int x_a = abs(x-a);
int x_b = abs(x-b);
if(x_a>x_b) {
  cout << "B" << endl;
} else {
  cout << "A" << endl;
}
return 0;
}


Measured memory_bytes: 256
//g++ -std=gnu++14 a.cpp
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i,N){
    cin >> A.at(i);
  }
  int cnt = 0;
  int num = 1;
  while(num != 2 && cnt <= 3*N){
    num = A.at(num-1);
    cnt++;
    //if(num == 2) break;
  }
  if(num == 2){
    cout << cnt <<endl;
  }
  else{
    cout << -1 <<endl;
  }


}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
const int N=5003,M=1000000007;
int n,to[N*2],hd[N*2],lk[N],cnt,
f[N][N],sz[N],co[N];
inline void add(int u,int v){
	to[++cnt]=v,hd[cnt]=lk[u],lk[u]=cnt;
}int u,v;
void dfs(int x,int y){
	f[x][1]=sz[x]=1;
	for(int s,i=lk[x];i;i=hd[i])
	if((s=to[i])^y){
		dfs(s,x);
		for(int j=sz[x]+sz[s];j;j--){
			f[x][j]=(M-1ll*f[x][j]*f[s][0])%M;
			for(int k=max(j-sz[x],1);k<=sz[s]&&k<=j;k++)
			f[x][j]=(f[x][j]+1ll*f[x][j-k]*f[s][k])%M;
		}
		sz[x]+=sz[s];
	}
	for(int i=2;i<=sz[x];i+=2)
	f[x][0]=(f[x][0]+1ll*f[x][i]*co[i])%M;
}
int main(){
	scanf("%d",&n);
	for(int i=2;i<=n;i+=2){
		co[i]=1;
		for(int j=i;j>i>>1;j--)
		co[i]=1ll*co[i]*j%M*(M+1>>1)%M;
	}
	for(int i=1;i<n;i++)
	scanf("%d%d",&u,&v),
	add(u,v),add(v,u);
	dfs(1,0);
	printf("%d",f[1][0]);
}

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

using namespace std;

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

#define TT template<typename T>
TT T    sq(T x){ return x*x; }
TT int  ubnd(vector<T>& v,T x){ return upper_bound(v.begin(), v.end(), x) - v.begin(); }
TT int  lbnd(vector<T>& v,T x){ return lower_bound(v.begin(), v.end(), x) - v.begin(); }
TT void sort(T& v){ sort(v.begin(), v.end()); }
TT void revs(T& v){ reverse(v.begin(), v.end()); }
TT void uniq(T& v){ sort(v); v.erase(unique(v.begin(), v.end()), v.end()); }
TT void show(T& v,char d=' ',char e='\n'){for(int i=0;i<v.size();++i)cout<<v[i]<<((i==v.size()-1)?e:d);}
TT void inpt(vector<T>& v,int n){ v.reserve(n);for(int i=0;i<n;++i){T x; cin>>x; v.push_back(x);} }
TT T In(){ T x; cin >> x; return x; }

static inline void fast_io(){ ios::sync_with_stdio(0); cin.tie(0); }
static inline int in(){ int x; scanf("%d", &x); return x; }
static inline string instr(){ string x; cin >> x; return x; }
static const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
static const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};

int main()
{
  while (int e = in()){
    int m = 1e8;
    for (int z = 0; z <= 100; ++z){
      for (int y = 0; y <= 1000; ++y){
        int x = e - (sq(z) * z + sq(y));
        if (x < 0) continue;
        m = min(m, z + y + x);
      }
    }
    printf("%d\n", m);
  }
  return (0);
}

Measured memory_bytes: 1188
#include <stdio.h>
#include <stdlib.h>

int a[50], b[50];
int c[50], d[50];

int dist(int i, int j) {
	return abs(a[i] - c[j]) + abs(b[i] - d[j]);
}

void core() {
	int N, M;
	scanf("%d", &N);
	scanf("%d", &M);
	for (int i = 0; i < N; i++) {
		scanf("%d", &a[i]);
		scanf("%d", &b[i]);
	}
	for (int i = 0; i < M; i++) {
		scanf("%d", &c[i]);
		scanf("%d", &d[i]);
	}
	//
	for (int i = 0; i < N; i++) {
		int n = 0;
		int d = dist(i, 0);
		for (int j = 1; j < M; j++) {
			int dj = dist(i, j);
			if (d > dj) {
				n = j;
				d = dj;
			}
		}
		printf("%d\n", n + 1);
	}
}

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



Measured memory_bytes: 128
a=input()
if a=='SUN':
 b=7
if a=="MON":
 b=6
if a=="TUE":
 b=5
if a=="WED":
 b=4
if a=="THU":
 b=3
if a=="FRI":
 b=2
if a=="SAT":
 b=1
print(b)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  cin >> N >> K;
  
  vector <double> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p[i];
  }
  
  vector <double> exp(N);
  for (int i = 0; i < N; i++) {
    exp[i] = (1.0 + double(p[i])) / 2.0;
  }
  
  vector <double> s(N+1, 0);
  for (int i = 0; i < N; i++) {
    s[i+1] = s[i] + exp[i];
  }
  
  double ans = 0;
  for (int i = 0; i < N-K+1; i++) {
    ans = max(s[i+K] - s[i], ans);
  }
  
  cout << fixed;
  cout << setprecision(9);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4992
#!/usr/bin/env python

from collections import deque
import itertools as ite
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

def rev_mod(num):
	pow_num = MOD - 2
	mod_num = MOD
	pow_cur = num
	ret = 1
	while pow_num > 0:
		if pow_num % 2 == 1:
			ret *= pow_cur
			ret %= mod_num
		pow_cur *= pow_cur
		pow_cur %= mod_num
		pow_num /= 2
	return ret

N, A, B, C = map(int, raw_input().split())

ans = 0

for loop in range(2):
    cnt = 0
    P = 1
    comb = 1
    PA = (A * rev_mod(A + B)) % MOD
    PB = (B * rev_mod(A + B)) % MOD
    PCm = 100 * rev_mod(100 - C) % MOD
    for i in range(N - 1):
        P *= PA
        P %= MOD

    for i in range(N):
        ans += PCm * (N + i) % MOD * P % MOD * comb % MOD * PA
        ans %= MOD
        P *= PB
        P %= MOD
        comb *= N + i
        comb *= rev_mod(i + 1)
        comb %= MOD
    A, B = B, A
print ans

Measured memory_bytes: 7928
from itertools import combinations
N = int(input())
grid = tuple(tuple(input()) for _ in range(N))

res = 0
for d in range(N):
  for x,y in combinations(range(N), 2):
    if grid[(x+d)%N][y] != grid[(y+d)%N][x]:
      break
  else:
    res += 1
print(res*N)

Measured memory_bytes: 49104
# 最小全域木（mininum spanning tree）の問題

# 頂点、辺どちらの数もO(WH)なので、木を求めるアルゴリズムを直接適用するのは不可能（TLE）。
# 計算の工夫で計算量を減らす。
# クラスカル法（コストの小さい順に、閉路ができないように辺を追加）を用いる。
# 縦向きの辺は、最初はW+1本全てを選択する。「それまで選択された横の辺（の組）」の数だけ減る。その数だけ横がひと繋がりになっているので。
# 横向きの辺は、最初はH+1本全てを選択する。「それまで選択された縦の辺（の組）」の数だけ減る。その数だけ縦がひと繋がりになっているので。
# 縦と横の長さを一緒にしてソートするにはどうする?
# - 縦と横を独立にソートして、どちらが小さいか管理しながら左から見る。尺取り的なやり方。
# - 縦横情報を入れて長さで一緒にソートする。 →こっちが簡単そう。

w, h = list(map(int, input().split()))

yoko = [(int(input()), 'yoko') for _ in range(w)]
tate = [(int(input()), 'tate') for _ in range(h)]

sorted_edge = sorted(yoko + tate, key=lambda x: x[0])

ans = 0
tate_num = 0
yoko_num = 0
for length, direction in sorted_edge:
    if direction == 'tate':
        ans += length * (w + 1 - yoko_num)
        tate_num += 1
    else:
        ans += length * (h + 1 - tate_num)
        yoko_num += 1

print(ans)


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

int n;
int k;
int64_t h;

int main(){
    cin >> n >> k;
    vector<int64_t> hp(n);

    for(int i=0;i<n;i++){
        cin >> h;
        hp[i] = h;
    }
    sort(hp.begin(), hp.end());

    vector<int64_t> s(n+1, 0);
    for(int i=0;i<n;i++) s[i+1] = s[i] + hp[i];

    int64_t min=0;
    if(k >= n){
        min = 0;
    }
    else{
        min = s[n-k];
    }
    cout << min << endl;
}

Measured memory_bytes: 3328
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n, l, r,ans = 0;
		n = sc.nextInt();
		for(int i = 0; i < n; ++i) {
			l = sc.nextInt();
			r = sc.nextInt();
			ans += r - l + 1;
		}
		sc.close();
			System.out.println(ans);
	}

}


Measured memory_bytes: 26824
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	string s;
	cin>>s;
	map<char, int> x;
	x['E']=x['W']=0;
	map<char, int> y;
	for(int i=0; i<n; i++)
	{
		if(s[i]=='E')
			y['E']++;
		else
			y['W']++;
	}
	int cnt =0;
	int min = INT_MAX;
	for(int i=0; i<n; i++)
	{
		char lead_dir = s[i];
		y[lead_dir]--;
		cnt = y['E']+x['W'];
		if(cnt<min)
			min = cnt;
		x[lead_dir]++;
	}
	cout<<min;
	return 0;

}

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

using namespace std;

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

  if (R < 1200) {
    cout << "ABC" << endl;
  } else if (R < 2800) {
    cout << "ARC" << endl;
  } else {
    cout << "AGC" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import itertools

from math import sqrt


def actual(n, d, X):
    count = 0

    for p1, p2 in itertools.combinations(X, 2):
        d_float = sqrt(sum([(y - z) ** 2 for (y, z) in zip(p1, p2)]))

        if d_float % 1 == 0.0:
            count += 1

    return count

n, d = map(int, input().split())
X = []
for _ in range(n):
	X.append(list(map(int, input().split())))

print(actual(n, d, X))

Measured memory_bytes: 3064
import * as fs from 'fs';

//in
// 2
// 1 4
//out
// 5
const main = (inp: string) => {
    // (xi -p)2
    const n = parseInt(inp.split('\n')[0]);
    const x: number[] = inp.split('\n')[1].split(' ').map(Number);
    let ans: number = Number.MAX_VALUE;
    let tmp: number = 0;
    for (let i: number = Math.min(...x); i <= Math.max(...x); i++) {
        tmp = 0;
        for (let j: number = 0; j < n; j++) {
            tmp += (x[j] - i)*(x[j] - i);
        }
        if (ans >= tmp) {
            ans = tmp;
        }
    }
    console.log(ans);
};

main(fs.readFileSync('/dev/stdin', 'utf8').trim());


Measured memory_bytes: 7484
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
  int n,m,a,b;
  map<int,int> mp;
int main() {
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> a;
    mp[a]++;
  }
  cin >> m;
  for(int i=0; i<m; i++) {
    cin >> b;
    mp[b]--;
    if(mp[b]<0) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}


Measured memory_bytes: 9600
SX,SY,TX,TY=map(int,input().split())
NX=TX-SX
NY=TY-SY
ans=[]
for i in range(NX):
  ans.append('R')
for i in range(NY):
  ans.append('U')
for i in range(NX):
  ans.append('L')
for i in range(NY):
  ans.append('D')
ans.append('D')
for i in range(NX+1):
  ans.append('R')
for i in range(NY+1):
  ans.append('U')
ans.append('L')
ans.append('U')
for i in range(NX+1):
  ans.append('L')
for i in range(NY+1):
  ans.append('D')
ans.append('R')
print(''.join(ans))

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <vector>
using namespace std;
int main(){
    int n,t,v[200000];
    cin>>n>>t;
    int c=0;
    for(int i=0;i<n;i++)cin>>v[i];
    for(int i=0;i<n-1;i++){
        c+=min(t,v[i+1]-v[i]);
    }
    cout<<c+t<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>

#define ll long long 

using namespace std;

ll fact(ll n) {
    if(n == 1) {
        return 1;
    }
    
    return n * fact(n - 1);
}

int main() {
    int num;
    
    cin >> num;
    
    if(0 <= num && num <= 20) {
        cout << fact((ll)num) << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3068
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
#define pb(n,m) n.push_back(m)
#define fix(n) cout<<fixed<<setprecision(n);
using namespace std;
//using bint=boost::multiprecision::cpp_int;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  vector<int> c(26);
  char z,x='a';
  while(cin>>z){
    z=tolower(z);
    c[z-97]++;
  }
  rep(i,0,26){
    co(x<<" : "<<c[i]);
    x++;
  }
  
  return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
#include <stack>
#include <bitset>
#include <map>
#include <ctime>
#include <numeric>


#ifndef M_PI
#define M_PI 3.141592653589
#endif
#define int long long
#define double long double

#ifdef TIME
#define start cin.tie(NULL); cout.tie(NULL); cout.setf(ios::fixed); cout.precision(10); ios_base::sync_with_stdio(false);int32_t START = clock()
#define finish cout << "\ntime: " << (clock() - START) / (CLOCKS_PER_SEC * 1.0); return 0
#endif

#ifndef TIME
#define start cin.tie(NULL); cout.tie(NULL); cout.setf(ios::fixed); cout.precision(10); ios_base::sync_with_stdio(false)
#define finish return 0
#endif

using namespace std;


//vector input
template<typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &i : vec) {
        cin >> i;
    }
    return is;
}

//pair output
template<typename E>
ostream &operator<<(ostream &os, pair<E, E> &t) {
    os << t.first << ' ' << t.second;
    return os;
}

//"map" pair output
template<typename E>
ostream &operator<<(ostream &os, pair<const E, E> &t) {
    os << t.first << ' ' << t.second;
    return os;
}

//vector output
template<typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
    for (T i : vec) {
        os << i << ' ';
    }
    return os;
}

//2 dimensional vector output
template<typename T>
ostream &operator<<(ostream &os, vector<vector<T> > &vec) {
    for (vector<T> i : vec) {
        os << i << '\n';
    }
    return os;
}

vector<vector<int>> g;
vector<int> d;

vector<int> col;

void dfs(int v, int c) {
    col[v] = c;
    for (auto u : g[v]) {
        if (col[u] == 0) {
            dfs(u, c);
        }
    }
}

int32_t main() {
    start;

    int n, m;
    cin >> n >> m;
    g.resize(n);
    d.resize(n);
    col.resize(n);

    for (int i = 0; i < m; ++i) {
        int x, y;
        cin >> x >> y;
        g[x - 1].push_back(y - 1);
        g[y - 1].push_back(x - 1);
    }

    int cc = 1;

    for (int i = 0; i < n; ++i) {
        if (col[i] == 0) {
            dfs(i, cc);
            cc += 1;
        }
    }

    map<int, int> ma;

    for (int i = 0; i < n; ++i) {
        ma[col[i]] += 1;
    }

    int ans = 0;

    for (auto e : ma) {
        if (e.second > ans) {
            ans = e.second;
        }
    }

    cout << ans << '\n';

    finish;
}

Measured memory_bytes: 23524
#pragma GCC optimize("O2")
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<unordered_map>
#include<set>
#include<cmath>
#include<climits>
#include<random>
#include <iomanip>
#include <bitset>
using namespace std;
 
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define fast ios::sync_with_stdio(false); cin.tie(NULL);
 
/////////////////////////////////////////////
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
///////////////////////////////
// #define int long long

const int N = 1e7 + 1;
int prime[N];
void sieve(){

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

		if(prime[i])
			continue;
		for(int j = i ; j < N ; j+=i){

			if(!prime[j])
				prime[j] = i;
		}
	}
}

void solve(){

	sieve();
	int n;
	cin>>n;

	long long ans = 1;

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

		int x = i;
		vector<int> tmp;
		while(x > 1){

			int cnt = 0;
			int val = prime[x];

			while(x%val==0)
				x/=val , ++cnt;

			tmp.pb(cnt);

		}

		long long tot = 1;

		for(int it : tmp)
			tot*=(it+1);

		ans += 1LL*i*tot;
	}
	cout<<ans<<endl;
}
 
signed main(){
 
	fast;
	int t = 1;
	//cin>>t;
	for(int i = 1 ; i <= t ; ++i)
		solve();
}


Measured memory_bytes: 42680
#include<bits/stdc++.h>
using namespace std;
int main(){
    while(true){
        int m,f,r;
        cin >> m >> f >> r;
        if(m == -1 && f == -1 && r ==  -1) break;

        if(m == -1 || f == -1) cout << 'F' << endl;
        else if((m+f) >= 80) cout << 'A' << endl;
        else if((m+f) >= 65) cout << 'B' << endl;
        else if((m+f) >= 50) cout << 'C' << endl;
        else if((m+f) >= 30){
            if(r >= 50)  cout << 'C' << endl;
            else cout << 'D' << endl;
        }else cout << 'F' << endl;
    }
}


Measured memory_bytes: 3088
#include <cctype>
#include <string>
#include <iostream>

using namespace std;

string LowerCamelCaseDiv2(string S)
{
    string T;
    
    for(int i = 0; i < S.size(); i++)
    {
        if(i == 0)
        {
            T += tolower(S[i]);
        }  
        else if(S[i - 1] == '_')
        {
            T += toupper(S[i]);
        }
        else if(S[i] != '_')
        {
            T += S[i];
        }
    }
    
    return T;
}

string UpperCamelCaseDiv2(string S)
{
    string T;
    
    for(int i = 0; i < S.size(); i++)
    {
        if(i == 0)
        {
            T += toupper(S[i]);
        }  
        else if(S[i - 1] == '_')
        {
            T += toupper(S[i]);
        }
        else if(S[i] != '_')
        {
            T += S[i];
        }
    }
    
    return T;
}

string UnderLineDiv2(string S)
{
    string T;
    
    for(int i = 0; i < S.size(); i++)
    {
        if(i != 0 && isupper(S[i]))
        {
            T += '_';
        }
        
        T += tolower(S[i]);
    }
    
    return T;
}

int main()
{
    string S, T;
    
    while(true)
    {
        cin >> S >> T;
        
        if(T == "X") { break; }
        
        if(T == "L") { cout << LowerCamelCaseDiv2(S) << endl; }
        if(T == "U") { cout << UpperCamelCaseDiv2(S) << endl; }
        if(T == "D") { cout << UnderLineDiv2(S) << endl; }
    }
    
    return 0;
}

Measured memory_bytes: 3160
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,n,s) for(int i=(int)(s);i<(int)(n);++i)
#define RREP(i,n,s) for(int i=(int)(s);i>=(int)(n);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
    int n,y;cin>>n>>y;
    y /= 1000;

    REP(i, n+1) {
        REP(j, n+1) {
            if (i+j > n) break;
            int k = n-i-j;

            if (i*10 + j*5 + k == y) {
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }
    }

    cout << "-1 -1 -1" << endl;
}


Measured memory_bytes: 256
def minkowski(xlst,ylst,p):
  d = list()
  for i in range(len(xlst)):
    d.append((abs(xlst[i] - ylst[i]))**p)
  D = sum(d) ** (1/p)
  return D

def mugen(xlst,ylst):
  d = list()
  for i in range(len(xlst)):
    d.append((abs(xlst[i] - ylst[i])))
  m = max(d)
  D = m
  return D

n = int(input())
xl = list(map(int,input().split()))
yl = list(map(int,input().split()))

D1 = minkowski(xl, yl, 1)
D2 = minkowski(xl, yl, 2)
D3 = minkowski(xl, yl, 3)
Dm = mugen(xl, yl)

print(D1)
print(D2)
print(D3)
print(Dm)


Measured memory_bytes: 5648
// Problem : αlphabet
// Contest : Virtual Judge - AtCoder
// URL : https://vjudge.net/problem/AtCoder-abc171_a
// Memory Limit : 1048 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")  // disable
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define lll __int128
#define lp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define vec(v, type, sz) vector<type> v(sz)
#define in(v) \
    for (auto &i : v) cin >> i
#define all(v) v.begin(), v.end()
#define prv(v)                         \
    for (auto i : v) cout << i << " "; \
    cout << "\n"
#define MOD 1000000007
#define INF 1000000000
#define INFL 1000000000000000000ll
#define fast_io                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define vi vector<int>
#define vl vector<ll>
#define vii(v, n, m, val) vector<vector<int>> v(n, vector<int>(m, val))
#define viii(v, i, j, k, val)        \
    vector<vector<vector<int>>> v(i, \
                                  vector<vector<int>>(j, vector<int>(k, val)))
#define pii pair<int, int>
#define pb push_back
#define file_io                       \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define testcases \
    int tcc;      \
    cin >> tcc;   \
    for (int tc = 1; tc <= tcc; tc++)
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while (!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(vector<string> __attribute__((unused)) args,
               __attribute__((unused)) int idx,
               __attribute__((unused)) int LINE_NUM) {
    cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if (idx > 0)
        cerr << ", ";
    else
        cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss;
    ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef DB
#define debug(...) \
    debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

int main() {
    fast_io;
    char c; cin>>c;
    cout<<(isupper(c)?'A':'a');
}

Measured memory_bytes: 3592
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    m,d = LI()
    ans = 0
    for i in range(1,m+1):
        for j in range(1,d+1):
            d1 = j%10
            d2 = j//10
            if d1 >= 2 and d2 >= 2 and d1*d2 == i:
                ans += 1
    print(ans)
    return

#B
def B():

    return

#C
def C():

    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

#Solve
if __name__ == "__main__":
    A()


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define F first
#define S second
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define sz size()
#define all(A)    A.begin(), A.end()
#define mem(a, b) memset(a, b, sizeof(a))   // all elements of A are b=0 or b=-1 else don't work
#define f0(i,b)   for(ll i=0;i<(b);i++)
#define f1(i,b)   for(ll i=1;i<=(b);i++)
#define f2(i,a,b) for(ll i=(a);i<=(b);i++)
#define f3(i,b,a) for(ll i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(ll i=(a);i!=(b);i+=(c))
#define mod 1000000007

#define whilee(i,t)  while(i!=t)
#define  sl(a)  scanf("%lld",&a)
#define  pl(a)  printf("%lld\n",a)

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;

//for(auto it =A.begin(); it!=A.end(); it++)
//sort(A.begin(),A.end());
//binary_search(A.begin(),A.end(),x);
//reverse(A.begin(), A.end());
//cout << *max_element(A.begin(), A.end());
//cout << *min_element(A.begin(), A.end());
//count(A.begin(), A.end(), X); //counts the occurrences of X
//distance(A.begin(),A.end());  //distance between first to last element
//accumulate(A.begin(), A.end(), 0); //add
//next_permutation(A.begin(), A.end());
//prev_permutation(A.begin(), A.end());
//swap(S[0], T[0]);

//scanf("%lld",&x);
//printf("%lld\n",x);
//while (scanf("%lld %lld", &a, &b) == 2)
//printf("Case %lld: %lld\n", t++, a);

//vector <ll> A;
//deque <ll> A;
//queue <ll> A;
//stack <ll> A;
//list <int> A;
//set <ll> A;
//map <ll,ll> A;
//pair <ll,ll> A ;
//vector <pair <ll,ll>> A ;
//bitset<32> bset1;
//char ch;
//string S, T, U;
ll i, j, k, a, b, c, d, e, f, g, h, l, m, n, o, p, q, r, s, t=1, u, v, w, x, y, z, maxx=INT_MIN, minn=INT_MAX, ans=0, sum=0, cnt=0;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);//NULL
    cout.tie(nullptr);//NULL

    //scan(n);
    cin>>n>>d;
    double x = (double)n/(d+d+1);
    y=ceil(x);
    cout<<y<<endl;
    return 0;
}


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

int N,K;
int dp[11][2010] ={};
vector<vector<int>> C(11);

int main(){
	cin >> N >> K;
	int c,g;
	for(int i=1;i<=N;i++){
		cin >> c >> g;
		C[g].push_back(c);
	}
	for(int i=1;i<=10;i++){
		C[i].push_back(0);
		if(C[i].size()!=0) sort(C[i].begin(),C[i].end());
		reverse(C[i].begin()+1,C[i].end());
		for(int j=1;j<C[i].size();j++) C[i][j] += C[i][j-1];
	}
	for(int i=1;i<=10;i++){
		for(int j=1;j<=K;j++){
			if(C[i].size()!=1){
				for(int k=1;k<C[i].size();k++){
					dp[i][k] = max(max(dp[i][k],dp[i-1][k]),C[i][k]+k*(k-1));
					if(j-k>=0) dp[i][j] = max(max(dp[i][j],dp[i-1][j]),dp[i-1][j-k]+C[i][k]+k*(k-1));
				}
			}else{
				dp[i][j] = dp[i-1][j];
			}
		}
	}
	cout << dp[10][K] << endl;
}


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

int main(){
  ll N, i, min = 10000000000, count = 0, x;
  cin >> N;
  rep(i, N){
    cin >> x;
    if(min >= x){
      min = x;
      count++;
    }
  }
  
  cout << count << endl;
  return 0;
}

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

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

    long long max[2], pending = 0;
    max[0] = 0, max[1] = 0;
    int flag = 0;
    sort(a, a + n);

    for (int i = n-1; i >= 0; i--) {
        if (flag >= 2) break;
        if (pending == a[i]) {
            if (flag < 2) max[flag] = a[i];
            flag++;
            pending = 0;
        } else {
            pending = a[i];
        }
    }

    cout << max[0] * max[1] << endl;

    return 0;
}

Measured memory_bytes: 1024
fun main(args: Array<String>) {
    val (A, B, C, X, Y) = readLine()!!.split(" ").map { it.toLong() }

    //

    // assume buying C * 2i
    var sum = X * A + Y * B
    var min = sum
    var a = X
    var b = Y
    var c = 0L
    while (!(a == 0L && b == 0L)) {
        if (a > 0) {
            sum = sum - A
            a--
        }

        if (b > 0) {
            sum = sum - B
            b--
        }
        c += 2
        sum = sum + C * 2
        min = Math.min(min, sum)
    }
    println(min)
}


Measured memory_bytes: 37936