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

using namespace std;

#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;

void solve() {
    int n;
    cin >> n;

    int sum = 0;
    vector<int> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
        sum += v[i];
    }
    double avg = (sum * 1.0) / (n * 1.0);
    double diff = 1e10;
    int id = -1;
    for (int i = 0; i < n; i++) {
        if (diff > abs(v[i] - avg)) {
            diff = abs(v[i] - avg);
            id = i;
        }
    }
    cout << id << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<map>
#include<queue>
#include<cmath>
using namespace std;

#define N 3
#define N2 9

const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

int MDT[N2][N2];

struct Puzzle
{
	int f[N2], space, MD;
	int cost;
	bool operator < (const Puzzle &p) const
	{
		for(int i = 0; i < N2; i++){
			if(f[i] == p.f[i]) continue;
			return f[i] > p.f[i];
		}
		return false;
	}
};

int getallMD(const Puzzle &p)
{
	int h = 0;
	for(int i = 0; i < N2; i++){
	if(i == p.space) continue;
		h += MDT[i][p.f[i] - 1];
	}
	return h;
}

struct State
{
	Puzzle pz;
	int estimated;
	bool operator < (const State &s) const
	{
		return estimated > s.estimated;
	}
};

int astar(Puzzle p)
{
	priority_queue<State> A;
	map<Puzzle, bool> USED;

	State initial;
	initial.pz = p;
	initial.estimated = p.MD;
	A.push(initial);
	USED[p] = true;

	Puzzle u, v;
	int sx, sy, tx, ty, r;

	while(!A.empty())
	{
		u = A.top().pz; A.pop();
		if(u.MD == 0) return u.cost;

		sx = u.space / N;
		sy = u.space % N;
		for(r = 0; r < 4; r++){
			tx = sx + dx[r];
			ty = sy + dy[r];
			if(tx < 0 || tx >= N || ty < 0 || ty >= N) continue;
			v = u;
			v.MD -= MDT[tx * N + ty][u.f[tx * N + ty] - 1];
			v.MD += MDT[sx * N + sy][u.f[tx * N + ty] - 1];
			swap(v.f[sx * N + sy], v.f[tx * N + ty]);
			v.space = tx * N + ty;
			
			if(!USED[v]){
				v.cost++;
				USED[v] = true;
				State new_s;
				new_s.pz = v;
				new_s.estimated = v.cost + v.MD;
				A.push(new_s);
			}
		}
	};
	return -1;
}

int main()
{
	
	for(int i = 0; i < N2; i++){
		for(int j = 0; j < N2; j++){
			MDT[i][j] = abs((i / N) - (j / N)) + abs((i % N) - (j % N));
		}
	}

	Puzzle in;

	for(int i = 0; i < N2; i++){
		scanf("%d", &in.f[i]);
		if(in.f[i] == 0) in.space = i;
	}
	in.cost = 0;
	in.MD = getallMD(in);

	cout << astar(in) << endl;

	return 0;
}

Measured memory_bytes: 3012
#include <iostream>
#include <algorithm>
using namespace std;
double a[55];
int main()
{
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i];	
	}
	sort(a,a+n);
	for(int i = 0; i < n - 1; i++){
		a[i + 1] = (a[i] + a[i + 1])/2;
		a[i] = 0;
		sort(a,a+n);
	}
	printf("%lf",a[n - 1]);
	return 0;
}

Measured memory_bytes: 256
m,_ = gets.split().map(&:to_i)
a = gets.split().map(&:to_i).sort

r = [0] + [*1..m]
a.each do |c|
	c.upto(m) do |ri|
		if r[ri] > r[ri-c]+1
			r[ri] = r[ri-c]+1
		end
	end
end

p r[m]

Measured memory_bytes: 9984
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<map>
#include <algorithm>
#include<cstdlib>
#include<cmath>
#include<deque>
#include <numeric>
typedef unsigned long long ull;
typedef  long long ll;

int main() {
	ll a, b, c;

	std::cin >> a >>b >>c;

	std::cout << std::min(b / a, c) << std::endl;

	return 0;
}

Measured memory_bytes: 256
def f(k,c,x,a,d)
	if k==0
		c
	elsif d==a.size
		Float::INFINITY
	elsif x<a[d]
		f(k-1,c,a[d],a,d+1)
	else
		[f(k,c,x,a,d+1),f(k-1,c+x+1-a[d],x+1,a,d+1)].min
	end
end
n,k,*a=`dd`.split.map &:to_i
p f(k-1,0,a[0],a,1)

Measured memory_bytes: 2044
n = int(input())
a =[0]*n
x = [[0] *n for i in range(n)]
y = [[0] *n for i in range(n)]
ans = []
for i in range(n):
    a[i] = int(input())
    for j in range(a[i]):
        x[i][j],y[i][j] = map(int,input().split())
        x[i][j]-=1
        
ishonest= [-1]*n + [0]
def check(ishonest):
    for i in range(n):
        if not ishonest[i]:continue
        for j in range(a[i]):
            if y[i][j] == 1 and ishonest[x[i][j]] == 0:
                return False
            if y[i][j] == 0 and ishonest[x[i][j]] == 1:
                return False
    return True

def dfs(now,h_or_not= -1):
    ishonest[now] = h_or_not
    if now == n-1:
        if check(ishonest):
      
            return sum(ishonest)+1
        else:
            return 0
  
    return max(dfs(now+1,0),dfs(now+1,1))

print(dfs(-1))



    
            
            
            

Measured memory_bytes: 3064
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(void)
{
    int n, x, d = 0;
    int ans = 1;
    scanf("%d%d", &n, &x);
    rep(i, n)
    {
        int l;
        scanf("%d", &l);
        d += l;
        if (d <= x)
            ans++;
    }

    printf("%d\n", ans);
    return 0;
}

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

int read(){
    int x=0;bool f=0;char c=getchar();
    while(c<'0'||c>'9') f|=c=='-',c=getchar();
    while(c>='0'&&c<='9') x=x*10+(c^48),c=getchar();
    return f?-x:x;
}

#define int long long

signed main(){
    long long N;
    scanf("%lld",&N);
    long long Ans=1ll<<50;
    for(int i=1;(long long)i*i<=N;i++){
        if(N%i==0){
            int j=N/i;
            Ans=min(Ans,(long long)(i+j-2));
        }
    }
    printf("%lld",Ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

bool flag = true;
bitset<100010> bit;
int black,white,col[100010];
vector<int> G[100010];
vector<P> vec;

void dfs(int v,int c){
	col[v] = c;
	(c ? black : white) += 1;
	for(int to : G[v]){
		if(col[to] == -1){
			dfs(to,(c + 1) % 2);
		}else if(col[to] != (c + 1) % 2){
			flag = false;
			return;
		}
	}
}

signed main(){
	int n,m,ma = 0;
	cin >> n >> m;
	for(int i = 0;i < m;i++){
		int a,b;
		cin >> a >> b; a--;b--;
		G[a].pb(b);
		G[b].pb(a);
	}
	for(int i = 0;i < n;i++) col[i] = -1;
	for(int i = 0;i < n;i++){
		if(col[i] == -1){
			black = 0;
			white = 0;
			dfs(i,0);
			if(!flag){
				cout << -1 << endl;
				return 0;
			}
			vec.pb(P(black,white));
		}
	}
	bit.set(0);
	for(P p : vec){
		bit = (bit << p.first) | (bit << p.second);
	}
	for(int i = 0;i < 100005;i++){
		if(bit[i]) chmax(ma,i * (n - i));
	}
	cout << ma - m << endl;
}


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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

array<int, 3> go(auto& adj, const string& st, int loc, int par) {
    int stones = 0;
    int sum_lo = 0, sum_hi = 0;

    vector<array<int, 2>> cres;
    for (int nbr : adj[loc]) if (nbr != par) {
        auto cr = go(adj, st, nbr, loc);

        stones += cr[2];
        sum_lo += cr[0] + cr[2];
        sum_hi += cr[1] + cr[2];
        cres.push_back({ cr[0] + cr[2], cr[1] + cr[2] });
    }

    int lo = sum_lo, hi = sum_hi;
    if (cres.size()) {
        sort(all(cres));
        auto big = cres.back();
        if (big[0] <= sum_hi - big[1]) {
            lo = sum_lo & 1;
        } else {
            lo = big[0] - (sum_hi - big[1]);
        }
    }

    stones += st[loc] == '1';
    return { lo, hi, stones };
}

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

    int N;
    string str;
    cin >> N >> str;

    vvi adj(N);
    vi u(N - 1), v(N - 1);

    for (int i = 0; i < N - 1; i++) {
        cin >> u[i] >> v[i];
        --u[i], --v[i];
        adj[u[i]].push_back(v[i]);
        adj[v[i]].push_back(u[i]);
    }

    int ans = INT_MAX;
    for (int i = 0; i < N; i++) {
        auto r = go(adj, str, i, i);
        if (r[0] == 0) ans = min(ans, r[1] / 2);
    }
    cout << (ans < INT_MAX ? ans : -1) << endl;

    return 0;
}



Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
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; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main(){
    int x,y;
    cin >> x >> y;
    for(int i =0;i<101;i++){
        for(int j=0;j<101;j++){
            if(i+j==x and 2*i+4*j==y){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" <<endl;
    return 0;

}


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

using namespace std;

#define int long long

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

    map<pair<int, int>, int> mp;
    int n;
    cin >> n;
    vector<pair<int, int>> vec(n);
    for (int i = 0; i < n; i++)
        cin >> vec[i].first >> vec[i].second;
    for (int i = 0; i < n; i++)
        for (int j = i + 1; j < n; j++)
        {
            mp[{vec[i].first - vec[j].first, vec[i].second - vec[j].second}]++;
            mp[{vec[j].first - vec[i].first, vec[j].second - vec[i].second}]++;
        }
    int ans = 0;
    for (auto i: mp)
        ans = max(ans, i.second);
    cout << n - ans << endl;

    return 0;
}


Measured memory_bytes: 384
def prime_factorize(n):
    a = []
    a.append(1)
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

A, B = map(int, input().split())
a_prime = set(prime_factorize(A))
b_prime = set(prime_factorize(B))
prime = a_prime & b_prime
print(len(prime))


Measured memory_bytes: 3064
loop do
  h, w = gets.split(" ").map{|x| x.to_i}
  if h != 0 && w != 0
    (h / 2).times {
      puts (("#" + ".") * w)[0..(w - 1)]
      puts (("." + "#") * w)[0..(w - 1)]
    }
    puts (("#" + ".") * w)[0..(w - 1)] if h % 2 == 1
    puts ""
  else
    break
  end
end

Measured memory_bytes: 6120
import sys
N = int(input())
s = []
for i in range(N):
    s.append(input())
for i, s0 in enumerate(s):
    for j, s1 in enumerate(s):
        if i != j and s0 == s1:
            print('No')
            sys.exit()
s0 = s[0]
for i in range(1, len(s)):
    s1 = s[i]
    if s0[-1] != s1[0]:
        print('No')
        sys.exit()
    s0 = s1
print('Yes')


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

#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
#define int long long
//for set
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;   
// for multiset
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_set;

#define ff first
#define ss second
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x.size())
#define PI 3.1415926535897932384626433832795
int MOD=1e9+7;
int powmod(int a,int l, int md){int res=1;while(l){if(l&1)res=res*a%md;l/=2;a=a*a%md;}return res;}
int binpow(int a,int l){int res=1;while(l){if(l&1)res=res*a;l/=2;a=a*a;}return res;}
typedef long long ll; typedef vector<ll> vi; typedef pair<ll, ll> ii; typedef vector<ii> vii;
#define pb push_back
int __set(int b, int i) {return b|(1<<i);} //set ith bit
int __unset(int b, int i) {return b&(~(1UL<<i));}
int __check(int b, int i) {return b&(1<<i);} //returns 0 if ith bit is 0
int mulmod(int a, int b, int md) {return ((a%md)*(b%md))%md;}
int addmod(int a, int b, int md) {return (a+b)%md;}
int submod(int a, int b, int md) {return (((a-b)%md)+md)%md;}
int divmod(int a, int b, int md) {return mulmod(a, powmod(b, md-2, md), md);} //if md is prime;
const ll inf = 0xFFFFFFFFFFFFFFFL; //very large number
// priority_queue<int, vector<int>, greater<int> > pq; //for min priority_queue
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}

signed main(void)
{
	IOS;
	int n; cin>>n;
	vii s(n);
	for(int i = 0; i < n; i++) {
		int x,l; cin>>x>>l;
		s[i]={x-l,x+l};
	}
	sort(all(s));
	priority_queue<int> pq1;
	pq1.push(s[0].ss);
	int cnt=n;
	for(int i = 1; i < n; i++) {
		int rr  = pq1.top();
		if(rr > s[i].ff) {
			pq1.push(s[i].ss);
			pq1.pop();
		} else
			pq1.push(s[i].ss);
	}
	cout<<sz(pq1)<<endl;
	time();
	return 0;
}

Measured memory_bytes: 2936
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <cmath>
#define endl "\n"
using namespace std;

void solve()
{   int x,y; cin >> x >> y;
    cout << x*y;
}

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


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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int X, A, B; cin >> X >> A >> B;
    X -= A;
    X %= B;
    cout << X << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

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

namespace ConsoleApp3
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var input1 = Console.ReadLine().Split(" ");
            var count = int.Parse(input1.First());
            var distance = long.Parse(input1.Last());

            var result = Enumerable.Range(0, count).Select(_ =>
            {
                var inputN = Console.ReadLine().Split(" ");
                return (X: long.Parse(inputN.First()), Y: long.Parse(inputN.Last()));
            })
            .Count(ab => (ab.X * ab.X + ab.Y * ab.Y) <= distance * distance);

            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 41256
n = int(input())
a, b, c = [input() for i in range(3)]
ans = 0
for i in range(n):
    if a[i] == b[i] == c[i]:
        ans += 0
    elif a[i] != b[i] != c[i] != a[i]:
        ans += 2
    else:
        ans += 1
print(ans) 

Measured memory_bytes: 3064
#!/usr/bin/env python3
import sys
import itertools

def solve(N: int, M: int, R: int, r: "List[int]", A: "List[int]", B: "List[int]", C: "List[int]"):
    from scipy.sparse import csr_matrix
    from scipy.sparse.csgraph import floyd_warshall
    matrix = [[0]*N for _ in range(N)]
    for i in range(M):
        matrix[A[i]-1][B[i]-1] = C[i]
        matrix[B[i]-1][A[i]-1] = C[i]
    
    dist_matrix = floyd_warshall(csgraph=matrix, directed=False)

    perm = list(itertools.permutations(r)) 

    answer = float('inf')
    for p in perm:
        a = 0
        for index in range(len(p)-1):
            a += dist_matrix[p[index]-1][p[index+1]-1]
        answer = min(answer,a)
    print(int(answer))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    R = int(next(tokens))  # type: int
    r = [int(next(tokens)) for _ in range(R)]  # type: "List[int]"
    A = [int()] * (M)  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    C = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
        C[i] = int(next(tokens))
    solve(N, M, R, r, A, B, C)

if __name__ == '__main__':
    main()


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

#define all(v) v.begin(), v.end()
typedef long long ll;

int main() {
    ll x; cin >> x;

    for(int i = 0; i <= 120; i++){
        ll w = pow(i, 5);
        for(int j = 0; j <= 120; j++){
            ll t = pow(j, 5);
            if(x == w - t){
                cout << i << " " << j << endl;
                return 0;
            }
            if(x == w + t){
                cout << i << " " << j * -1 << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 4100
# include <bits/stdc++.h>
# define int long long
# define endl "\n"
using namespace std;

void solve() {

	int k;
	cin >> k;
	map <int, int> mp;
	int rem, left = 7, count = 1;
	while (true) {
		rem = left % k;
		if (rem == 0) {
			cout << count;
			return;
		}
		if (mp.count(rem)) {
			cout << -1;
			return;
		}
		mp[rem]++;
		left = 10 * rem + 7;
		count++;
	}
}
signed main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);

# ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
# endif

	// int t;
	// cin >> t;
	// while (t--)
	solve();

	return 0;
}

Measured memory_bytes: 66060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
        int N;
        long[] A, B;
        long ans = 0;

        void solve(InputReader in, PrintWriter out) {
            N = in.nextInt();
            A = in.nextLongArray(N + 1);
            B = in.nextLongArray(N);

            for (int i = 0; i < N; ++i) {
                ans += Math.min(A[i], B[i]);
                if (A[i] < B[i] && A[i + 1] > 0) {
                    long sub = Math.min(A[i + 1], B[i] - A[i]);
                    A[i + 1] -= sub;
                    ans += sub;
                }
            }

            out.println(ans);
        }

    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int size) {
            int[] arr = new int[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        long[] nextLongArray(int size) {
            long[] arr = new long[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }
    }
}

Measured memory_bytes: 47916
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;  // y, x;
int H, W;

int maze(const vector<string> &S, P start) {
  queue<P> que;
  vector<vector<int>> dist(H, vector<int>(W, -1));
  vector<int> dw = {0, 1, 0, -1};
  vector<int> dh = {1, 0, -1, 0};
  dist[start.first][start.second] = 0;
  que.push(start);
  while (!que.empty()) {
    P top = que.front();
    que.pop();
    for (int d = 0; d < 4; d++) {
      int nh = top.first + dh[d];
      int nw = top.second + dw[d];
      if (0 <= nw && nw < W && 0 <= nh && nh < H) {
        if (S[nh][nw] != '.') continue;
        if (dist[nh][nw] != -1) continue;
        dist[nh][nw] = dist[top.first][top.second] + 1;
        que.push(P(nh, nw));
      }
    }
  }

  int ret = -1;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      ret = max(ret, dist[i][j]);
    }
  }
  return ret;
}

int main(void) {
  cin >> H >> W;
  vector<string> S(H);
  for (int i = 0; i < H; i++) {
    cin >> S[i];
  }
  int ans = -1;
  for (int h = 0; h < H; h++) {
    for (int w = 0; w < W; w++) {
      if (S[h][w] != '#') ans = max(ans, maze(S, P(h, w)));
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
'use strict'
function main(inp) {
  inp = inp.trim().split('\n')
  const N = Number(inp.shift())
  let G = [...new Array(N)].map(a => [])
  let vp = new Array()
  
  inp.forEach(r => {
    r = r.split(' ').map(n => n - 1)
    G[r[0]].push(r[1])
    G[r[1]].push(r[0])
    vp.push(r[0]+'-'+r[1])
  })

  let K = 0;
  let I = new Map()
  let cs = new Array(N).fill(0)
  let used = new Array(N).fill(0)
  let que = new Array()

  used[0] = 1
  que.push(0)

  while(que.length) {
    let v = que.shift()
    if (K < G[v].length) K = G[v].length
    let cur = 1
    for (const u of G[v]) {
      if (used[u]) continue;
      if (cur === cs[v]) cur++
      cs[u] = I[u+'-'+v] = I[v+'-'+u] = cur++
      used[u] = 1
      que.push(u)
    }
  }

  console.log(K)
  vp.forEach(v => {
    console.log(I[v])
  })
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 128516
#include <iostream>
#include <math.h>
#include <string>

#define MIN(x, y) (x < y ? x : y)
#define MAX(x, y) (x > y ? x : y)

using namespace std;

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

	int sum = 0;
	int pre_n = N;
	for(long i = 100000000; i > 0; i /= 10){
		sum += pre_n / i;
		pre_n %= i;
		//cout << sum << " ";
	}
	//cout << (N % sum) << endl;
	string flag = "No";
	if(N % sum == 0){
		flag = "Yes";
	}
	cout << flag << endl;	
}



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

int main() {
	int D, N;
	cin >> D >> N;
	int k = 1;
	if (N <= 99) k = N;
	else k = 101;
	for (int i = 0; i < D; i++) k *= 100;
	cout << k << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

int n, q;
map<int, vector<string>> vs;
map<int, vector<string>> buf;
map<int, int> id;
vector<pair<string, int>> A;

int Partition(int p, int r) {
	int x = A[r].second;
	int i = p - 1;
	for (int j = p; j < r; j++) {
		if (A[j].second <= x) {
			i = i + 1;
			swap(A[i], A[j]);
		}
	}
	swap(A[i + 1], A[r]);
	return i + 1;
}

void quickSort(int p, int r) {
	if (p < r) {
		int q = Partition(p, r);
		quickSort(p, q - 1);
		quickSort(q + 1, r);
	}
}

int main() {
	cin >> n;
	rep(i, n) {
		string s;
		int num;
		cin >> s >> num;
		buf[num].push_back(s);
		A.push_back({ s, num });
	}
	quickSort(0, n - 1);
	bool f = 1;
	rep(i, n) {
		if (A[i].first != buf[A[i].second][id[A[i].second]]) {
			//cout << A[i].first << " " << buf[A[i].second][id[A[i].second]] << " " << i << endl;
			f = 0;
			break;
		}
		else id[A[i].second]++;
	}
	if (f)cout << "Stable" << endl;
	else cout << "Not stable" << endl;
	rep(i, n) {
		cout << A[i].first << " " << A[i].second << endl;
	}
}

Measured memory_bytes: 12816
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
ll N, C;
ll D[40][40];
ll c[1000][1000];
map<ll, ll> m[3];

int main() {
  cin >> N >> C;
  repe(i, 1, C) {
    repe(j, 1, C) { cin >> D[i][j]; }
  }
  repe(i, 1, N) {
    repe(j, 1, N) {
      cin >> c[i][j];
      m[(i + j) % 3][c[i][j]]++;
    }
  }

  ll ans = INF;
  repe(i, 1, C) {
    repe(j, 1, C) {
      if (j == i) continue;
      repe(k, 1, C) {
        if (k == i || k == j) continue;

        ll d = 0;
        for (auto e : m[0]) {
          ll color = e.first;
          ll num = e.second;
          d += D[color][i] * num;
        }
        for (auto e : m[1]) {
          d += D[e.first][j] * e.second;
        }
        for (auto e : m[2]) {
          d += D[e.first][k] * e.second;
        }
        chmin(ans, d);
      }
    }
  }

  cout << ans << endl;
}


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

int N;
vector<int> A;

int main(void) {
	cin >> N;
	A.resize(N);
	for (int i = 0; i < N; ++i)
		cin >> A[i];

	int k = 0;
	for (int i = 0; i < N; ++i) {
		if (A[i] == k + 1)
			++k;
	}
	int ans = (k == 0) ? -1 : (N - k);

	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 1024
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/


int main() {
	
	int n, k;
	string s;
	scanf("%d", &n);
	scans(s);
	scanf("%d", &k);
	for(auto aa : s)printf("%c", (aa == s[k - 1] ? aa : '*'));
	
	Please AC;
}


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

namespace ITP1_7_D
{
    class Program
    {
        static void Main(string[] args)
        {
            List<long[]> a = new List<long[]>();
            List<long[]> b = new List<long[]>();

            int[] _input = Console.ReadLine().Split(' ').Select(e => int.Parse(e)).ToArray();
            int n = _input[0];
            int m = _input[1];
            int l = _input[2];

            for(int i = 0; i < n; i++)
                a.Add(Console.ReadLine().Split(' ').Select(e => long.Parse(e)).ToArray());      
            for(int j = 0; j < m; j++)
                b.Add(Console.ReadLine().Split(' ').Select(e => long.Parse(e)).ToArray());
            
            for(int i = 0; i < n; i++)
            {
                for(int j = 0; j < l; j++)
                {
                    long sum = 0;
                    for(int k = 0; k < m; k++)
                        sum += a[i][k] * b[k][j];
                    if(j != 0)
                      Console.Write(" ");
                    Console.Write("{0}", sum);
                }
                Console.WriteLine();
            }
        }
    }
}

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


string s;

void read() {
    int dummy;
    cin >> dummy >> s;
}


void work() {
    int ans = 0;
    int L = 0, R = s.size() - 1;
    while (L < R) {
        if (s[L] == 'W') {
            while (L < R && s[R] == 'W') R--;
            if (L == R) break;
            swap(s[L++], s[R--]);
            ++ans;
        } else {
            ++L;
        }
    }
    cout << ans << endl;
}


int main() {
    read();
    work();
    return 0;
}


Measured memory_bytes: 3700
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

typedef long long ll;

const int MAX_N = 200010;
int par[MAX_N];
int rnk[MAX_N];

void init(int n) {
    rep(i,n) {
        par[i] = i;
        rnk[i] = 0;
    }
}

int find(int x) {
    if (par[x] == x) {
        return x;
    } else {
        return par[x] = find(par[x]);
    }
}

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (rnk[x] < rnk[y]) {
        par[x] = y;
    } else {
        par[y] = x;
        if (rnk[x] == rnk[y]) rnk[x]++;
    }
}

bool same(int x, int y) {
    return find(x) == find(y);
}

void solve() {
    int N, M, K, L;
    cin >> N >> M;
    init(N + M);
    rep(i, N) {
        cin >> K;
        rep(j, K) {
            cin >> L;
            unite(i, L - 1 + N);
        }
    }
    string ans = "YES";
    rep(i, N) if (!same(0, i)) ans = "NO";
    cout << ans << endl;
    return;
}

int main() {
    solve();
}

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

int main(){
    int H, W;
    cin >> H >> W;
    for (int i = 0; i < W+2; i++) cout << "#";
    cout << endl;
    for (int i = 0; i < H; i++) {
        cout << "#";
        string s;
        cin >> s;
        cout << s;
        cout << "#\n";
    }
    for (int i = 0; i < W+2; i++) cout << "#";
    cout << endl;
    return 0;
}

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

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

	int count=0,sum=0;

	for (int i = 0; i < n; ++i){
		sum=1;
		while(sum<=d){
			sum+=a[i];
			if(sum<=d)
			count++;
		}
	}

	cout<<count+x+n<<endl;
	


}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#pragma GCC optimize("O3")

#include <iostream>
#include <algorithm>
#include <vector>
#include <cassert>
#include <cstring>
#include <numeric>
#include <set>
#include <queue>
#include <deque>
#include <array>
#include <string>
#include <cmath>
#include <random>
#include <ctime>
#include <map>
#include <functional>
#include <bitset>
#include <complex>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>

#define sz(a) (int)((a).size())
#define all(a) (a).begin(), (a).end()
#define pb push_back

using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
using ld = long double;

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n, k;
	cin >> n >> k;
	vi a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	const int inf = 1e9 + 228;
	vi dp(n, inf);
	dp[0] = 0;
	for (int i = 1; i < n; i++) {
		for (int j = 1; j < k + 1; j++) {
			if (i - j >= 0) {
				dp[i] = min(dp[i], dp[i - j] + abs(a[i] - a[i - j]));
			}
		}
	}
	cout << dp[n - 1];
}


Measured memory_bytes: 1024
n = int(input())
a = [(int(input()), "a") for i in range(n)]
b = [(int(input()), "b") for i in range(n)]
li = sorted((a+b))
MOD = 10**9 + 7

def solve(li):
    ans = 1
    for i in range(len(li) - 1):
        if abs(li[i]) < abs(li[i+1]):
            ans *= abs(li[i+1])
            ans %= MOD
    return ans

num = 0
ans = 1
tmp = []
for i in range(2*n):
    if li[i][1] == "a":
        num += 1
    else:
        num -= 1
    if num == 0:
        ans *= solve(tmp)
        ans %= MOD
        tmp = []
    else:
        tmp.append(num)
print(ans)

Measured memory_bytes: 33108
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    string S,T;
    cin>>S>>T;
    int ss=S.size();
    int ts=T.size();
    int ans=ts;
    for (int i=0;i<=ss-ts;i++){
        int yuuy=0;
        for (int k=0;k<ts;k++){
            if(S[i+k]!=T[k])yuuy++;
        }
        ans=min(ans,yuuy);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
const long long mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
const int ddx[4] = {1,1,-1, -1};
const int ddy[4] = {1,-1,-1,1};
//////////////////////////////////

string ss[3] = {"Sunny", "Cloudy", "Rainy"};

int main() {
    string s; cin >> s;
    for(int i=0; i<3; i++) {
        if(s == ss[i]) {
            cout << ss[(i+1)%3] << endl;
            return 0;
        }
    }

    return 0;
}

// EOF


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };




void solve() {
    int N; cin >> N;
    vec p(N), q(N);
    rep(i, N) cin >> p[i];
    rep(i, N) cin >> q[i];

    auto tmp = p;
    sort(all(tmp));
    int a=0, b=0, cnt=0;
    do{
        if(tmp == p) a = cnt;
        if(tmp == q) b = cnt;
        cnt++;
    }while(next_permutation(all(tmp)));

    cout << abs(a-b) << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

using ll    = long long;
using vll   = vector<ll>;
using pll   = pair<ll,ll>;
using ld    = long double;

const ll mod = (ll)1e9 + 7;
const ll mxN = (ll)4e5 + 3;

void solve() {
	ll n;cin>>n;
	if(n%10==3) cout<<"bon\n";
	else if(n%10==0 || n%10==1 || n%10==6 || n%10==8) cout<<"pon\n";
	else cout<<"hon\n";
}


int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(20);
	cout << fixed;
//	pre();
//	ll t;cin>>t;while (t--)
		solve();
}


Measured memory_bytes: 3600
#include<iostream>
using namespace std;
int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(a < c)
        a = c;
    if(b > d)
        b = d;
    if(b - a > 0)
        cout << b - a;
    else
        cout << 0;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int64;
int main(){
	int64 n; cin >> n;
    set<int64> ret;
    for(int64 i = 1; i * i <= (n - 1); i++){
    	if((n - 1) % i == 0){
        	if(i != 1) ret.insert(i);
            if(((n - 1) / i) != 1) ret.insert((n - 1)/ i);
        }
    }
    vector<int64> F;
    for(int64 i = 1; i * i <= n; i++){
    	if(n % i == 0){
        	if(i != 1) F.push_back(i);
            if((n / i) != i) F.push_back(n / i);
        }
    }
  
    for(int64 f : F){
    	for(int64 p = f; ; p *= f){
        	if((n / p) % f == 1) ret.insert(f);
            if((n / p) % f) break;
        }
    }
    cout << ret.size() << endl;
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<cstdio>

using namespace std;

typedef pair<int,bool> Pair;

int main(){

  int P,Q,R;
  int ans = 1000;
  int sum[6];
  
  cin >> P >> Q >> R;

  sum[0] = R + Q;
  sum[1] = P + Q;
  sum[2] = P + R;
  sum[3] = Q + R;
  sum[4] = R + P;
  sum[5] = Q + P;
  
  for(int i = 0; i < 6; ++i){

	if(sum[i] < ans) ans = sum[i];

  }
    cout << ans << endl;

  return 0;

}

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

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
typedef deque<LL> Dl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

LL dx[] = {1, -1, 0, 0, -1, -1, 1, 1};
LL dy[] = {0, 0, 1, -1, -1, 1, -1, 1};

///**************************DONE****************************///

int main()
{
    int n, h, w;
    cin >> n >> h >> w;

    int ans = 0;
    for(int i = 0; i < n; i++){
        int a, b;
        cin >> a >> b;

        if(a >= h && b >= w)
            ans++;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
import scipy.sparse.csgraph as c,numpy
_,*s=open(0)
s=numpy.int8([list(t[:-1])for t in s])
m=c.floyd_warshall(s)
i=m[0]%2<1
j=i^True
print((s[i][:,i].any()|s[j][:,j].any()or~int(m.max()))*-1)

Measured memory_bytes: 14492
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template<typename T>
struct Kruskal{

  struct edge{
    Int from,to;
    T cost;
    Int used;
    edge(Int from,Int to,T cost):
      from(from),to(to),cost(cost),used(0){}
    bool operator<(const edge& e) const{
      return cost<e.cost;
    }
  };

  Int n;
  vector<Int> r,p;
  vector<edge> es;

  Kruskal(){}
  Kruskal(Int n):n(n),r(n,1),p(n){
    iota(p.begin(),p.end(),0);
  }

  Int find(Int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }

  bool same(Int x,Int y){
    return find(x)==find(y);
  }

  void unite(Int x,Int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
  }

  void add_edge(Int u,Int v,T c){
    es.emplace_back(u,v,c);
  }

  T build(){
    sort(es.begin(),es.end());
    T res=0;
    for(auto &e:es){
      if(!same(e.from,e.to)){
        res+=e.cost;
        unite(e.from,e.to);
        e.used=1;
      }
    }
    return res;
  }
};

//INSERT ABOVE HERE
signed main(){
  Int n,q;
  cin>>n>>q;
  Kruskal<Int> G(n);
  const Int INF = 1e15;
  vector<Int> dp(n,INF);
  for(Int i=0;i<q;i++){
    Int a,b,c;
    cin>>a>>b>>c;
    G.add_edge(a,b,c);
    chmin(dp[a],c+1);
    chmin(dp[b],c+2);
  }

  for(Int t=0;t<2;t++)
    for(Int i=0;i<n;i++)
      chmin(dp[(i+1)%n],dp[i]+2);

  for(Int i=0;i<n;i++)
    G.add_edge(i,(i+1)%n,dp[i]);

  cout<<G.build()<<endl;
  return 0;
}


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

int A, B;

int main () {
  cin >> A >> B;

  int c = 1;
  int ans = 0;
  while(B > c) {
    c += A - 1;
    ans++;
  }

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


Measured memory_bytes: 256
N=int(input())
W=list(input() for i in range(N))
p=W[0][0]
res=0
for w in W:
  if W.count(w)<2:
    if w[0]==p:
      res+=1
    else:
      break
  else:
    break
  p=w[-1]
if res==N:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>

int
main(int argc, char *argv[])
{
  int N; char s[10000][11];
  scanf("%d", &N);
  for(int i = 0; i < N; i++) scanf("%s", s[i]);

  int acnt = 0, bcnt = 0, abcnt = 0, bacnt = 0;

  for(int i = 0; i < N; i++){
    if(s[i][0] == 'B' && s[i][strlen(s[i]) - 1] != 'A') bcnt++;
    if(s[i][0] != 'B' && s[i][strlen(s[i]) - 1] == 'A') acnt++;
    if(s[i][0] == 'B' && s[i][strlen(s[i]) - 1] == 'A') bacnt++;
    for(int j = 0; j < strlen(s[i]) - 1; j++){
      if(s[i][j] == 'A' && s[i][j + 1] == 'B') abcnt++;
    }
  }

  int l = bacnt, m = bcnt, n = acnt;

  int ans;

  if(l != 0){
    if(n >= 1 && m >= 1) ans = l + 1 + (m < n ? m : n) - 1;
    else if(n >= 1 || m >= 1) ans = l + 1 - 1;
    if(n == 0 && m == 0) ans = l + 1 - 2;
  }

  else{
    ans = (m < n ? m : n);
  }

  ans += abcnt;

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

  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <functional>
#include <map>

#define M 101

using namespace std;

int d[M];

int main()
{
	int n, sum = 0;
	cin >> n;

	for (int i = 1; i <= n; i++)
		cin >> d[i];

	for (int i = 1; i <= n; i++)
		for (int j = i + 1; j <= n; j++)
			sum += d[i] * d[j];

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
a,b,c,d = gets.chomp.split.map &:to_i

c_num = b / c - (a-1)  / c
d_num = b / d - (a-1)  / d
lcm = c.lcm(d)
num = b / lcm - (a-1) / lcm

p b - a + 1 - (c_num + d_num - num)


Measured memory_bytes: 1916
import static java.lang.System.out;
import static java.lang.Integer.parseInt;
import java.math.BigDecimal;
import java.io.File;
import java.util.Scanner;

public class Main extends BaseExe {

    public static void main(String[] args) {
        new Main().exeSysIn();
    }

    @Override
    protected void execute() {
        int dataCount = parseInt(nextLine());
        for (int count = 0; count < dataCount; count++) {
            BigDecimal x = new BigDecimal(nextLine());
            BigDecimal y = new BigDecimal(nextLine());
            BigDecimal sum = x.add(y);
            if (sum.precision() > 80) {
                out.println("overflow");
            } else {
                out.println(sum);
            }
        }
    }
}

abstract class BaseExe {

    private Scanner scan;

    private String inData;

    public void exeSysIn() {
        try (Scanner scan = new Scanner(System.in)) {
            exeCtrl(scan);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void exeFileIn(String inDataPath) {
        try (Scanner scan = new Scanner(new File(inDataPath))) {
            exeCtrl(scan);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void exeCtrl(Scanner scan) {
        this.scan = scan;
        execute();
    }

    protected abstract void execute();

    protected String nextLine() {
        return scan.nextLine();
    }

    protected boolean judgeInData() {
        return hasNextLine() && isNotEmptyInData();
    }

    protected boolean hasNextLine() {
        return scan.hasNextLine();
    }

    protected boolean isNotEmptyInData() {
        return !"".equals(inData = nextLine());
    }

    protected String getInData() {
        return inData;
    }

}

Measured memory_bytes: 26176