akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)

int main() {
    int n,x,y,dis=0;
    cin >>n>>x>>y;
    int ans[n]={0};
    x--;y--;
    rep(i,n) {
        for(int j = i+1;j<n;j++) {
            dis=min(j-i,abs(j-y)+1+abs(x-i));
            ans[dis]++;
        }
    }
    rep(i,n-1)cout << ans[i+1] <<"\n";
    return 0;
}

Measured memory_bytes: 256
// Written by newbiechd
#include <cstdio>
#include <cctype>
#include <cstring>
using namespace std;

const int BUF = 100003;
inline char getChar() {
  static char buf[BUF], *bufS, *bufT;
  if (bufS == bufT) {
    bufT = (bufS = buf) + fread(buf, 1, BUF, stdin);
    if (bufS == bufT) return EOF;
  }
  return *bufS++;
}
inline int read() {
  int f = 0;
  char ch;
  while (!isdigit(ch = getChar())) {}
  do f = f * 10 + (ch ^ 48);
  while (isdigit(ch = getChar()));
  return f;
}

const int maxN = 403, mod = 998244353;
int a[maxN], b[maxN], inv[maxN], fac[maxN], bin[maxN][maxN];
int p[maxN][maxN], temp[maxN][maxN];

inline int power(int x, int y) {
  int o = 1;
  while (y) {
    if (y & 1) o = 1ll * o * x % mod;
    x = 1ll * x * x % mod, y >>= 1;
  }
  return o;
}

int main() {
  int n = read(), i, j, k, t, A = 0, B = 0, ans = 0;
  for (i = 1; i <= n; ++i)
    A += a[i] = read(), b[i] = read();
  inv[1] = 1;
  for (i = 2; i < maxN; ++i)
    inv[i] = -1ll * (mod / i) * inv[mod % i] % mod;
  fac[0] = 1;
  for (i = 1; i < maxN; ++i)
    fac[i] = 1ll * fac[i - 1] * i % mod;
  k = power(A, mod - 2);
  for (i = 1; i <= n; ++i) {
    t = 1ll * k * a[i] % mod, bin[i][0] = 1;
    for (j = 1; j < b[i]; ++j)
      bin[i][j] = 1ll * bin[i][j - 1] * t % mod * inv[j] % mod;
  }
  
  p[0][0] = 1, A = 0;
  for (i = 1; i <= n; ++i) {
    for (j = 0; j <= A; ++j)
      for (k = 0; k <= B; ++k) {
        temp[j + a[i]][k] = (temp[j + a[i]][k] + p[j][k]) % mod;
        for (t = 0; t < b[i]; ++t)
          temp[j][k + t] = (-1ll * p[j][k] * bin[i][t] + temp[j][k + t]) % mod;
      }
    A += a[i], B += b[i];
    for (j = 0; j <= A; ++j) {
      memcpy(p[j], temp[j], sizeof(int) * B);
      memset(temp[j], 0, sizeof(int) * B);
    }
  }
  
  for (i = 0; i <= A; ++i)
    for (j = 0; j <= B; ++j)
      p[i][j] = -p[i][j];
  ++p[A][0];
  k = power(A, mod - 2);
  for (i = 0; i < A; ++i) {
    t = 1ll * k * i % mod;
    for (j = 0; j <= B; ++j)
      ans = (1ll * p[i][j] * fac[j] % mod * power(1 - t, mod - j - 2) + ans)
        % mod;
  }
  printf("%d\n", (ans + mod) % mod);
  return 0;
}


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

int d[100009];
bool vs[100009];
vector<int> v[100009];

int dp(int n)
{
	if (vs[n]) return d[n];
	vs[n] = true;
	for (int i = 0; i < v[n].size(); i++)
		d[n] = max(d[n], dp(v[n][i]) + 1);
	return d[n];
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int a, b; cin >> a >> b;
		v[b].push_back(a);
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (!vs[i])
			dp(i);
		ans = max(ans, d[i]);
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 10752
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <cmath>
#include <ios>
#include <ctype.h>
#include <stack>
#include <istream>
#include <stdio.h>
#include <map>
#include <set>
#include <queue>
#include <unordered_map>
#include <functional>
#include <bitset>
#include <list>
#include <deque>
#include <time.h>
#include <random>
#include <iomanip>
#include <fstream>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define RREP(i,a,b) for (int i = a; i > (b); --i)
#define all(x) (x).begin(),(x).end()
const long long INF = 1000000007;
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
int solve(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  vector<int>v(n);
  rep(i,n)v[i] = s[i] - '0';
  vector<int>cnt(1000);
  ll ans = 0;
  REP(i,0,1000){
    int tmp[3] = {i / 100,(i % 100) / 10,(i % 100) % 10};
    int can = 0;
    rep(j,n){
      if(can == 3){
        break;
      }
      if(v[j] == tmp[can])can++;
    }
    if(can == 3)ans++;
  }
  cout << ans << endl;
  return 0;
}
int main(){
  ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16);
  solve();
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;



#define INF 2000000000
#define MAX_V 10



bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<ll,ll> a,pair<ll,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

ll gcd(ll a,ll b) { return b ? gcd(b, a%b) : a; }

ll lcm(ll a,ll b){
   return a/gcd(a,b)*b;
}
const ll MAX = 5100000;
const ll MOD = 1000000007;
 
ll fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

using graph = vector<vector<ll>>;
pair<pair<ll,ll>,ll> p[100010];



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,k;
    cin>>n>>k;
    vec<ll> a(n);
    rep(i,n) {
        cin>>a[i];
    }
        
    sort(ALL(a));
    if(a[n-1]<k){
        cout<<"IMPOSSIBLE"<<endl;
        return 0;
    }
    ll sum=gcd(a[0],a[1]);
    for(ll i=2;i<n;i++) sum=gcd(sum,a[i]);
    
    if(k%sum==0) cout<<"POSSIBLE"<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
    return 0;
}

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

#define LL long long
#define Dl double
#define Pb push_back
#define Po pop_back
#define Mp make_pair
#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)

using namespace std;

typedef vector<LL> Vl;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef vector<Pll> Vpl;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
#define X first
#define Y second

LL binpow(LL b, LL a)
{
    LL res = 1;
    while(b > 0){
        if(b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    LL n, k;
    cin >> n >> k;

    LL ans = k;
    ans *= binpow(n - 1, k - 1);

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



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
int main() {
  int n, m, c;
  cin >> n >> m >> c;
  vector<int> b(m);
  REP(i, m) {
    cin >> b.at(i);
  }
  vector<vector<int>> a(n, vector<int>(m));
  REP(i, n) {
    REP(j, m) {
      cin >> a.at(i).at(j);
    }
  }
  int count = 0;
  int sum;
  REP(i, n) {
    sum = c;
    REP(j, m) {
      sum += a.at(i).at(j) * b.at(j);
    }
    if (sum > 0) {
      count++;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define llint long long
#define inf 1e18

using namespace std;

struct Edge{
	llint to, cost;
	Edge(){}
	Edge(llint a, llint b){
		to = a, cost = b;
	}
};

llint N;
llint L[105][3];
vector<Edge> g[105];

llint volume(llint x)
{
	llint ret = 1;
	for(llint i = 0; i < 3; i++) ret *= L[x][i];
	return ret;
}

bool compare(llint x, llint y)
{
	for(llint i = 0; i < 3; i++){
		if(L[x][i] <= L[y][i]) return false;
	}
	return true;
}


struct edge{
	llint to, cap, cost, rev;
	edge(){}
	edge(llint a, llint b, llint c, llint d){
		to = a, cap = b, cost = c, rev = d;
	}
};


llint S, T;
vector<edge> G[205];
llint dist[205];
llint prevv[205], preve[205];

void BellmanFord()
{
	for(llint i = 0; i <= T; i++) dist[i] = inf;
	dist[S] = 0, prevv[S] = -1;
	
	bool update = true;
	while(update){
		update = false;
		for(llint i = 0; i <= T; i++){
			for(llint j = 0; j < G[i].size(); j++){
				if(G[i][j].cap == 0) continue;
				if(dist[G[i][j].to] > dist[i] + G[i][j].cost){
					dist[G[i][j].to] = dist[i] + G[i][j].cost;
					prevv[G[i][j].to] = i;
					preve[G[i][j].to] = j;
					update = true;
				}
			}
		}
	}
}

void add_edge(llint from, llint to, llint cap, llint cost)
{
	G[from].push_back( edge(to, cap, cost, G[to].size()) );
	G[to].push_back( edge(from, 0, -cost, G[from].size()-1) );
}

int main(void)
{
	while(1){
		cin >> N;
		if(N == 0) break;
		for(llint i = 0; i < N; i++){
			for(llint j = 0; j < 3; j++){
				cin >> L[i][j];
			}
			sort(L[i], L[i]+3);
		}
		
		for(llint i = 0; i < N; i++) g[i].clear();
		for(llint i = 0; i < N; i++){
			for(llint j = 0; j < N; j++){
				if(compare(i, j)){
					g[i].push_back(Edge(j, volume(j)));
				}
			}
		}
		
		S = 2*N+1, T = 2*N+2;
		for(llint i = 0; i <= T; i++) G[i].clear();
		for(llint i = 0; i < N; i++){
			for(llint j = 0; j < g[i].size(); j++){
				add_edge(i, N+g[i][j].to, inf, -g[i][j].cost);
			}
		}
		for(llint i = 0; i < N; i++){
			add_edge(S, i, 1, 0);
			add_edge(i+N, T, 1, 0);
		}
		
		llint ans = 0;
		while(1){
			BellmanFord();
			if(dist[T] >= inf / 2) break;
			
			llint p = T, flow = N;
			while(prevv[p] != -1){
				flow = min(flow, G[prevv[p]][preve[p]].cap);
				p = prevv[p];
			}
			
			p = T;
			while(prevv[p] != -1){
				G[prevv[p]][preve[p]].cap -= flow;
				G[p][G[prevv[p]][preve[p]].rev].cap += flow;
				p = prevv[p];
			}
			ans += dist[T] * flow;
		}
		
		llint sum = 0;
		for(llint i = 0; i < N; i++) sum += volume(i);
		ans = sum + ans;
		cout << ans << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3664
#include <cstdio>
using namespace std;

int n, m;
int card[101000];


int main()
{
	int l, r, ans(0);
	
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; ++i) {
		scanf("%d%d", &l, &r);
		++card[l], --card[r + 1];
	}
	for (int i = 1; i <= n + 1; ++i)
		card[i] += card[i - 1];
	for (int i = 1; i <= n; ++i)
		if (card[i] == m)
			++ans;
	printf("%d\n", ans);
	return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
    int n,m,ans=1;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=sqrt(m);i++){
        if(m%i==0){
            int cur=0;
            if(i>=n){
                cur=m/i;
            }
            if(m/i>=n){
                cur=max(cur,i);
            }
            if(cur==0) continue;
            ans=max(cur,ans);
        }
    }
    printf("%d\n",ans);
    return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-6;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

const int64 mod = 1e9+7;

int main(void){
	int32 n, m;
	while(cin >> n >> m && n && m){
		vector<int32> a(n), b(m);
		int32 sa = 0, sb = 0;
		REP(i, n){
			cin >> a[i]; sa+=a[i];
		}
		REP(i, m){
			cin >> b[i]; sb+=b[i];
		}
		int32 x = INF, y = INF;
		REP(i, n){
			REP(j, m){
				if(sa-a[i]+b[j] == sb-b[j]+a[i]){
					if(x+y > a[i]+b[j]){
						x = a[i]; y = b[j];
					}
				}
			}
		}
		if(x == INF && y == INF) cout << -1 << endl;
		else cout << x << " " << y << endl;
	}
}


Measured memory_bytes: 3088
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define MAX_N 10000

using namespace std;
typedef pair<int, int> ipair;

int N;
string str[MAX_N];

int solve() {
    int res = 0;

    for(int i = 0; i < N; ++i) {
        for(int j = 0; j < str[i].size() - 1; ++j)
            if(str[i][j] == 'A' && str[i][j + 1] == 'B')
                ++res;
    }

    int _a = 0;
    int b_ = 0;
    int b_a = 0;
    for(int i = 0; i < N; ++i) {
        if(str[i][0] == 'B' && str[i][str[i].size() - 1] == 'A')
            ++b_a;
        else if(str[i][0] == 'B')
            ++b_;
        else if(str[i][str[i].size() - 1] == 'A')
            ++_a;
    }

    res += min(_a, b_);

    if(b_a > 0) {
        if(b_ < _a) {
            res += b_a;
        } else if (b_ > _a) {
            res += b_a;
        } else {
            if(_a == 0)
                res += b_a - 1;
            else {
                res += b_a;
            }
        }
    }

    return res;
}

int main(int argc, char **argv) {
    cin >> N;
    for(int i = 0; i < N; ++i)
        cin >> str[i];

    cout << solve() << endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 502;
int n, p[N * N];
int dx[4] = {-1,1,0,0};
int dy[4] = {0,0,-1,1};
int dis[N][N], vis[N][N];
struct Nod {
	int x, y, d;
	bool operator<(const Nod&o)const{
		return d > o.d;
	}
};
priority_queue<Nod> q;
void update() {
	while (q.size()) {
		Nod now = q.top(); q.pop();
		int x = now.x, y = now.y;
		if (now.d > dis[now.x][now.y]) continue;
		for (int i = 0; i < 4; i ++) {
			int nx = now.x + dx[i];
			int ny = now.y + dy[i];
			if (dis[nx][ny] > now.d + (vis[x][y] ? 0 : 1) ) {
				dis[nx][ny] = now.d + (vis[x][y] ? 0 : 1);
				// printf("# upd %d %d / %d\n", nx, ny, dis[nx][ny]);
				q.push((Nod){nx, ny, dis[nx][ny]});
			}
		}
	}
}
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n * n; i ++) scanf("%d", &p[i]);
	for (int i = 1; i <= n; i ++) {
		for (int j = 1; j <= n; j ++) {
			dis[i][j] = min(min(i, n-i+1), min(j, n-j+1)) - 1;
		}
	}
	LL ans = 0;
	for (int i = 1; i <= n * n; i ++) {
		int r = (p[i] - 1) / n + 1;
		int c = p[i] % n; if (c == 0) c = n;  
		ans += dis[r][c]; vis[r][c] = 1;
		// printf("%d %d %d\n", r, c, dis[r][c]);
		q.push((Nod){r, c, dis[r][c]});
		update();
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 7716
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define mp make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n) 
#define SIZE(x) ((int)(x).size())
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef pair<int, int> pint;
typedef pair<lint, lint> plint;
typedef vector<lint> vec;
typedef vector<vector<lint>> matrix;
typedef priority_queue<lint> p_que;
typedef priority_queue<lint, vector<lint>, greater<lint>> p_que_rev;
//const lint INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

const int sqrtN = 512;
struct SqrtDecomposition {
  int N, K;
  vector<int> data;
  vector<int> bucketAdd;
  SqrtDecomposition(int n) : N(n) {
    K = (N + sqrtN - 1) / sqrtN;
    data.assign(K * sqrtN, 0);
    bucketAdd.assign(K, 0);
  }
  // [s, t)
  void add(int s, int t, int x) {
    for (int k = 0; k < K; ++k) {
      int l = k * sqrtN, r = (k + 1) * sqrtN;
      if (r <= s || t <= l){continue;}
      if (s <= l && r <= t) {
        bucketAdd[k] += x;
      } else {
        for (int i = max(s, l); i < min(t, r); ++i) {
          data[i] += x;
        }
      }
    }
  }
  int get(int i) {
    int k = i / sqrtN;
    return data[i] + bucketAdd[k];
  }
};


int n, q;
int com, s, t, x, i;

void input(){
    cin >> n >> q;
    return;
}

void solve(){
    SqrtDecomposition koyaya(n);
    REP(query, q){
        cin >> com;
        if(com == 0){
            cin >> s >> t >> x;
            koyaya.add(s, t+1, x);
        }
        else {
            cin >> i;
            cout << koyaya.get(i) << endl;
        }
    }
    return;
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    input();
    solve();
    return 0;
}


Measured memory_bytes: 3356
#include <iostream>
  
using namespace std;
  
int main()
{
  int n;
  int cards[5][14] = { { 0 } };
  char pattern;
  int num;
  
  cin >> n;
  for ( int i = 0; i < n; i++ ) {
    cin >> pattern >> num;
    switch ( pattern ) {
      case 'S':
        cards[0][num-1]=true;
        break; 
      case 'H':
        cards[1][num-1]=true;
        break; 
      case 'C':
        cards[2][num-1]=true;
        break; 
      case 'D':
        cards[3][num-1]=true;
        break;
      }
  }
  for ( int i = 0; i < 4; i++ ) {
    for ( int j = 0; j < 13; j++ ) {
      if ( false == cards[i][j] ) {
        switch ( i ) {
          case 0:
            cout << "S "<<(j+1)<<endl;
            break;
          case 1:
            cout << "H "<<(j+1)<<endl;
            break;
          case 2:
            cout << "C "<<(j+1)<<endl;
            break;
          case 3:
            cout << "D "<<(j+1)<<endl;
            break;
        }
      }
    }
  }
   
  return 0;
}

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

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

int main(){
    int n,a;
    cin>>n>>a;
    vector<int> v(n);
    rep(i,0,n)cin>>v[i];
    vector<vector<vector<ll>>> dp(51,vector<vector<ll>>(51,vector<ll>(2501,0)));
    dp[0][0][0]=1;
    rep(i,0,n){
        rep(j,0,n){
            rep(k,0,2501){
                dp[i+1][j][k]+=dp[i][j][k];
                dp[i+1][j+1][k+v[i]]+=dp[i][j][k];
            }
        }
    }
    
    ll ans=0;
    rep(j,1,n+1){
        rep(k,1,2501){
            if(k%j==0 && k/j==a)ans+=dp[n][j][k];
        }
    }
    cout<<ans<<endl;

    
    
    return 0;
}


Measured memory_bytes: 52224
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#define ll long long int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
 
using namespace std;

int main (){
    char s[4];

	cin >> s;
	
	if((s[0]=='0' && s[1]=='0')&& !((s[2]=='0' && s[3]!='0') || (s[2]=='1' && (s[3]=='0' || s[3]=='1' || s[3]=='2'))) || 
	(s[2]=='0' && s[3]=='0') && !((s[0]=='0' && s[1]!='0') || (s[0]=='1' && (s[1]=='0' || s[1]=='1' || s[1]=='2')))){
		cout << "NA"<< endl;
	}
	else if((s[0]=='0' || s[0]=='1') &&
	(s[1]=='0' || s[1]=='1' || s[1]=='2') &&
	(s[2]=='0' || s[2]=='1') &&
	(s[3]=='0' || s[3]=='1' || s[3]=='2') &&
	!(s[0]=='0' && s[1]=='0') && 
	!(s[2]=='0' && s[3]=='0')){
		cout << "AMBIGUOUS" << endl;
	}
	else if((s[0]=='0') &&
	(s[2]=='0') &&
	!(s[0]=='0' && s[1]=='0') && 
	!(s[2]=='0' && s[3]=='0')){
		cout << "AMBIGUOUS" << endl;
	}
	else if(s[0]!='0' && s[0]!='1'){
		if((s[2]=='0' && s[3]!='0') || (s[2]=='1' && (s[3]=='0' || s[3]=='1' || s[3]=='2'))){
			cout << "YYMM" << endl;
		}
		else cout << "NA" << endl;
	}
    else if(s[2]!='0' && s[2]!='1'){
		if((s[0]=='0' && s[1]!='0') || (s[0]=='1' && (s[1]=='0' || s[1]=='1' || s[1]=='2'))){
			cout << "MMYY" << endl;
		}
		else cout << "NA" << endl;
	}
	else if((s[0]=='0' && s[1]!='0') || (s[0]=='1' && (s[1]=='0' || s[1]=='1' || s[1]=='2'))){
			cout << "MMYY" << endl;
	}
	else if((s[2]=='0' && s[3]!='0') || (s[2]=='1' && (s[3]=='0' || s[3]=='1' || s[3]=='2'))){
			cout << "YYMM" << endl;
	}
	else{
		cout << "NA" << endl;
	}
}

Measured memory_bytes: 256
integer D
integer(16) G
integer(16),allocatable,dimension(:)::p,c
integer ans,preans,point

integer pattern

read*,D,G
allocate(P(D),C(D))
do i=1,D
  read*,P(i),C(i)
end do

ans=huge(ans)
do i=1,2**D
  pattern=i
  preans=0;point=0
  do j=1,D
    if(mod(pattern,2)==1)then
      point=point+j*P(j)*100+C(j)
      preans=preans+P(j)
    endif
    pattern=pattern/2
  end do
  if(G>point)then
    pattern=i
    do j=1,D
      if(mod(pattern,2)==0)then
        if((G-point)/(j*100)<=P(j)-1)then
          preans=preans+(G-point)/(j*100)
          point=G
          exit
        endif
      endif
    pattern=pattern/2
    end do
  endif
  if(G<=point)ans=min(preans,ans)
end do

print"(I0)",ans

end

Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include<vector>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main() {
	int n;
	cin >> n;
	vector<int>x(n);
	int max = -1;
	
	rep(i, n){
		cin >> x[i];
	}
	rep(i, n){
		if (max < x[i]){
			max = x[i];
			continue;
		}
		if (max - x[i] >= 2){
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
	return 0;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

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

  cin >> a >> b >> c;

  if(a == 7){
    if(b == 5){
      if(c == 5){
        cout << "YES";
      }
      else{
        cout << "NO";
      }
    }
    else{
      cout << "NO";
    }
  }
  else if(a == 5){
    if(b == 7){
      if(c == 5){
        cout << "YES";
      }
      else{
        cout << "NO";
      }
    }
    else if(b == 5){
      if(c == 7){
        cout << "YES";
      }
      else{
        cout << "NO";
      }
    }
    else{
      cout << "NO";
    }
  }
  else{
    cout << "NO";
  }

  return 0;
}

Measured memory_bytes: 256
N = int(input())
S = input()
E = 'E'
W = 'W'

e = S.count(E)
w = N - e

pre_l = ''
ans = e
t = e
for l in S:
	if l == E:
		t -= 1
	if pre_l == W:
		t += 1
	pre_l = l
	ans = min([ans, t])

print(ans)

Measured memory_bytes: 3668
#!/usr/bin/env python3
# coding:utf-8

def main():
    line = int(input())
    xy = [map(int, input().split()) for _ in range(line)]
    x, y = [list(i) for i in zip(*xy)]
    stdOut = solve(line, x, y)
    print(stdOut)


"""
方針


"""


def solve(line, x, y):
    for i in range(line):
        if (line - i) <= 2:
            return 'No'
        if isDoublet(x[i], y[i]) and isDoublet(x[i + 1], y[i + 1]) and isDoublet(x[i + 2], y[i + 2]):
            return 'Yes'
    return 'No'


def isDoublet(xi, yi):
    return xi == yi


if __name__ == "__main__":
    main()


Measured memory_bytes: 9220
#include<stdio.h>
int main(void){
	int H,W,i,j;
	while(1){
		scanf("%d %d",&H,&W);
		if(H==0&&W==0){
			break;
		}
		for(i=0;i<H;i++){
			for(j=0;j<W;j++){
				if(i%2==0&&j%2==0){
					printf("#");
				}
				else if(i%2==1&&j%2==0){
					printf(".");
				}
				else if(i%2==0&&j%2==1){
					printf(".");
				}
				else if(i%2==1&&j%2==1){
					printf("#");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

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

#define MOD 1000000007


vector<ll> primes;

void getPrimes() {
  bool isPrime[1001];
  for(int i = 0; i < 1001; i++) isPrime[i] = true;
  isPrime[1] = false;
  for(int i = 2; i < 1001; i++) {
    if(isPrime[i]) {
      primes.push_back(i);
      for(int k = 2; i * k < 1001; k++) {
        isPrime[i * k] = false;
      }
    }
  }
}

vector< pair<ll, ll> > factors(ll x) {
  unordered_map<ll, ll> m;

  for(ll i = 0; primes[i] * primes[i] <= x && i < primes.size(); i++) {
    while(x % primes[i] == 0) {
      m[primes[i]] += 1;
      x /= primes[i];
    }
  }
  if(x > 1) {
    m[x] = 1;
  }


  vector< pair<ll, ll> > ret;
  for(auto i: m) {
    ret.push_back(i);
  }

  sort(ret.begin(), ret.end());

  return ret;
}

int main() {
  ll N;
  cin >> N;
  getPrimes();
  unordered_map<ll, ll> m;

  for(ll i = 2; i <= N; i++) {
    for(auto k: factors(i)) {
      m[k.first] += k.second;
    }
  }

  vector<pair<ll, ll> > v;

  for(auto i: m) {
    v.push_back(i);
  }


  ll ans = 1;
  for(auto i: v) {
    ans = ans * (i.second + 1) % MOD;
  }
  cout << ans << endl;

}


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

using namespace std;

typedef long long ll;
const int maxn = 505;
const int INF = 0x7f7f7f7f;

inline ll read() {
    reg ll s = 0, t = 0; reg char ch = getchar();
    while (!isdigit(ch)) t |= ch == '-', ch = getchar();
    while (isdigit(ch)) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
    return t ? -s : s;
}

int h, w;
char a[maxn][maxn], b[maxn][maxn], c[maxn][maxn];

int main() {
    h = read(), w = read();
    for (reg int i = 1; i <= h; i++)
        for (reg int j = 1; j <= w; j++) a[i][j] = b[i][j] = '.';
    for (reg int i = 1; i <= h; i++)
        for (reg int j = 1; j <= w; j++) cin >> c[i][j];
    for (reg int i = 1; i <= h; i += 2)
        for (reg int j = 2; j < w; j++) a[i][j] = '#';
    for (reg int i = 1; i <= h; i++) a[i][1] = '#';
    for (reg int i = 2; i <= h; i += 2)
        for (reg int j = 2; j < w; j++) b[i][j] = '#';
    for (reg int i = 1; i <= h; i++) b[i][w] = '#';
    for (reg int i = 1; i <= h; i++)
        for (reg int j = 1; j <= w; j++)
            if (c[i][j] == '#') {
                if (a[i][j] != '#') a[i][j] = '#';
                if (b[i][j] != '#') b[i][j] = '#';
            }
    for (reg int i = 1; i <= h; i++) {
        for (reg int j = 1; j <= w; j++) cout << a[i][j];
        cout << endl;
    }
    cout << endl;
    for (reg int i = 1; i <= h; i++) {
        for (reg int j = 1; j <= w; j++) cout << b[i][j];
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define MAX 5002
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define Mod 1000000007
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
using namespace __gnu_pbds; 
using namespace std;

typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> new_data_set; 


int main(){
	ios_base::sync_with_stdio(false);
	ll n;cin>>n;
	ll a,b;cin>>a>>b;
	ll p[n];For(i,0,n) cin>>p[i];
	ll x[3]={0};
	For(i,0,n){
		if(p[i]<=a) x[0]++;
		else if(p[i]>=a+1 && p[i]<=b) x[1]++;
		else if(p[i]>=b+1) x[2]++;
	}

	cout<<min(x[0],min(x[1],x[2]))<<endl;
	
}

Measured memory_bytes: 256
while (h,w = gets.split.collect{|item| item.to_i})
 
if h == 0 and w == 0
    break
end

for i in 1..h do
    for s in 1..w do
        if (i+s) % 2 ==0
            print "#"   
        else
            print "."
        end
    end
    puts "\n"   
end

puts "\n"

end


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

int main(){
  int x, y, z, k, s, i, ans=0;
  
  cin >> k >> s;
  
  for (x=0; x<=min(k,s); x++) {
    for (y=0; y<=min(k,s-x); y++) {
      z = s-(x+y);
      if ((z>=0) && (z<=k)) ans++;
    }
  }
  
  cout << ans << endl;
  
  return 0;  
}

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

using namespace std;

vector<vector<int> > graph(20);
int bridges[20][20];
bool used[20][20];

int calc_sum(int from)
{
    int sum = 0;

    for (int i = 0; i < graph[from].size(); ++i) {
        int to = graph[from][i];
        if (graph[to].size() == 1) continue;
        if (used[from][to]) continue;
        used[to][from] = true;
        sum += bridges[from][to] * 2 + calc_sum(to);
    }

    return sum;
}

int calc_max(int from)
{
    int ma = 0;

    for (int i = 0; i < graph[from].size(); ++i) {
        int to = graph[from][i];
        if (graph[to].size() == 1) continue;
        if (used[from][to]) continue;
        used[to][from] = true;
        ma = max(ma, bridges[from][to] + calc_max(to));
    }

    return ma;
}

int main()
{
    int n;
    while (cin >> n, n) {
        memset(bridges, 0, sizeof(bridges));
        for (int i = 0; i < 20; ++i) graph[i].clear();
        for (int i = 0; i < n - 1; ++i) {
            int a, b, t; cin >> a >> b >> t;
            a--; b--;
            bridges[a][b] = bridges[b][a] = t;
            graph[a].push_back(b); graph[b].push_back(a);
        }

        memset(used, 0, sizeof(used));
        int sum = calc_sum(0);
        memset(used, 0, sizeof(used));
        int ma = calc_max(0);

        cout << sum - ma << endl;
    }
}

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

//in
// A
//out
// T

//in
// G
//out
// C
const main = (inp: string) => {
    const tables :{[s:string]:string}= {
        A: 'T',
        T: 'A',
        G: 'C',
        C: 'G'
    };

    console.log(tables[inp]);
};

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


Measured memory_bytes: 7372
#include<iostream>
#include<vector>
#include<math.h>
#include<algorithm>
using namespace std;
typedef long long ll;

ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else { return gcd(b, a % b); } }

int main() {

	ll n, m, x;
	cin >> n >> m >> x;
	vector<ll> C(n);
	ll A[12][12];
	for (int i = 0; i < n; i++) {
		cin >> C[i];
		for (int j = 0; j < m; j++) {
			ll k;
			cin >> k;
			A[i][j] = k;
		}
	}
	ll ans = -1;

	for (int bit = 0; bit < (1 << n); bit++) {
		ll cost = 0;
		vector<ll> abr(m, 0);
		for (int i = 0; i < n; i++) {
			if (bit & (1 << i)) {
				cost += C[i];
				for (int j = 0; j < m; j++) {
					abr[j] += A[i][j];
				}
			}
		}
		bool flag = true;
		for (int i = 0; i < m; i++) {
			if (abr[i] < x) {
				flag = false;
				break;
			}
		}
		if (flag == true && ans == -1)ans = cost;
		else if (flag == true && ans != -1) ans = min(ans, cost);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
using namespace std;
#define INF 0x3f3f3f3f
#define LC(x) (x<<1)
#define RC(x) ((x<<1)+1)
#define MID(x,y) ((x+y)>>1)
#define pb(x) push_back(x)
#define sf(x) scanf("%d", &x)
#define sfl(x) scanf("%lld", &x)
#define all(a) (a).begin(),(a).end()
#define clr(arr,val) memset(arr,val,sizeof(arr))
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);
#define caseT int _T;scanf("%d",&_T);for (int q=1; q<=_T; ++q)
typedef pair<int, int> pii;
//typedef complex<double> cpx;
typedef long long ll;
const double PI = acos(-1.0);
const int N = 2002;
bitset<N * N> bit;
int n, a[N];

int main(void)
{
    sf(n);
    int v = 0;
    for (int i = 1; i <= n; ++i)
        sf(a[i]), v += a[i];
    bit[0] = 1;
    for (int i = 1; i <= n; ++i)
        bit |= (bit << a[i]);
    for (int i = ceil(v * 1.0 / 2);; ++i)
        if (bit[i])
        {
            printf("%d\n", i);
            break;
        }
    return 0;
}


Measured memory_bytes: 1792
//#include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<numeric>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<ctype.h>
#include <fstream>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}
int dy[4]={0,1,0,-1};
//----------program from here----------

int main(){
  int N=0;
  cin >> N;
  cout << N/3 << endl;

  return 0;
}

Measured memory_bytes: 256
/*
ID: zhaowei10
TASK:
LANG: C++
*/
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define pb push_back
#define MOD 1000000007
#define NDIG(x) floor(log10(x)) + 1
#define FOR(i, j, k, l) for (s32 i = j; i < k; i += l)
#define RFOR(i, j, k, l) for (s32 i = j; i >= k; i -= l)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(x) x.begin(), x.end()
#define MEAN(a, b) min(a, b) + (abs(b - a) >> 1)
#define FASTIO()    \
  cin.tie(nullptr); \
  ios::sync_with_stdio(false);

typedef long long ll;
typedef int64_t s64;
typedef uint64_t u64;
typedef int32_t s32;
typedef uint32_t u32;
typedef float f32;
typedef double f64;
typedef pair<s32, s32> II;
typedef pair<s64, s64> LL;
typedef vector<s32> VI;
typedef vector<II> VII;
typedef vector<char> VC;
typedef vector<VII> VVII;
typedef priority_queue<s32> PQI;
typedef priority_queue<s32, VI, greater<s32>> PQIA;
typedef priority_queue<s64> PQL;
typedef priority_queue<II> PQII;
typedef priority_queue<II, VII, greater<II>> PQIIA;
typedef priority_queue<LL> PQLL;
typedef unordered_set<s32> USI;
typedef unordered_set<s64> USL;
typedef set<II> SII;
typedef multiset<s32> MSI;

template <typename T, typename U>
inline void amin(T &x, U y) {
  if (y < x) x = y;
}
template <typename T, typename U>
inline void amax(T &x, U y) {
  if (x < y) x = y;
}

template <typename T>
inline s32 ndigits(T x, T b) {
  s32 r = 0;
  while (x) {
    x /= b;
    ++r;
  }
  return r;
}

int main() {
  FASTIO();

  int n;
  cin >> n;

  int cnt = 0;
  map<pair<int, int>, int> m;
  for (int i = 1; i <= n; ++i) {
    int e = i % 10;
    int s = i / pow(10, floor(log10(i)));
    auto p = make_pair(s, e);
    if (m.count(p)) {
      m[p]++;
    } else {
      m[p] = 1;
    }
  }

  for (int i = 1; i <= n; ++i) {
    int e = i % 10;
    int s = i / pow(10, floor(log10(i)));
    auto p1 = make_pair(e, s);
    if (m.count(p1)) {
      cnt += m[p1];
    }
  }
  cout << cnt;
}

Measured memory_bytes: 256
# coding: utf-8
import collections

n=int(input())
d=list(map(int,input().split()))
c = collections.Counter(d)
ans = 1
m=max(d)


for i in range(m):
    ans*=c[i]**c[i+1]
    ans = ans%998244353

if c[0]!=1:
    ans=0
if d[0] != 0:
    ans = 0

# print(c)
print(ans)


Measured memory_bytes: 62004
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = a;i < n;i++)
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

int main(){
	string s;
	cin >> s;
	int cnt = 0,memo = 0,ans = 1000000000;
	
	rep(i,0,26){
		rep(j,0,s.size()){
			if(s[j] == (char)(i+'a')){
				cnt = max(memo,cnt);
				memo = 0;
			}
			else{
				memo++;
			}
		}
		cnt = max(memo,cnt);
		memo = 0;
		//cout <<(char)(i+'a') << " " << cnt << endl;
		ans = min(ans,cnt);
		cnt = 0;
	}
	
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
# AGC038A - 01 Matrix
def main():
    H, W, A, B = tuple(map(int, input().split()))
    for i in range(H):
        if i < B:
            x = [0] * A + [1] * (W - A)
        else:
            x = [1] * A + [0] * (W - A)
        print(*x, sep="")


if __name__ == "__main__":
    main()

Measured memory_bytes: 5492
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;


typedef long long i64;
const int inf = (int)1.05e9;

i64 waf(i64 s)
{
	i64 lo = 1;
	i64 hi = 1.05e9;

	while(hi - lo > 1) {
		i64 mid = (lo + hi) / 2;
		i64 rev = (s - 1) / mid;
		if(mid < rev)
			lo = mid;
		else
			hi = mid;
	}

	return lo;
}

int main()
{
	int q;

	scanf("%d", &q);

	for(int q_i = 0; q_i < q; ++q_i) {

		i64 a, b;
		scanf("%lld%lld", &a, &b);

		if(a > b)
			swap(a, b);

		if(a * b <= 2) {
			printf("0\n");
			continue;
		}

		i64 r = waf(a * b);

		i64 ans = 2 * r;
		if((r + 1) * (r + 1) < a * b && a != r + 1)
			ans += 1;

		if(a <= r) {
			ans -= 1;
		}

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

	return 0;
}

/* waffle */


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <stack>
#include <map>
#include <iomanip>
using namespace std;

int64_t min(int64_t a,int64_t b) {
    if (a > b)
    {
        return b ;
    }else
    {
        return a ;
    }
}


int main(){
    int n,x ;
    cin >> n >> x ;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a.at(i) ;
    }
    int ans = 0;
    sort(a.begin(),a.end()) ;
    for (int i = 0; i < n; i++)
    {
        x -= a.at(i) ;
        if (x >= 0)
        {
            ans ++ ;
        }else
        {

            break;
        }
        
        
    }
    if (x > 0)
    {
        ans -- ;
    }
    
    cout << ans << endl ;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main{

	public static void main(String[] args) throws NumberFormatException,
			IOException {
		 BufferedReader br = new BufferedReader(new
		 InputStreamReader(System.in));
		//BufferedReader br = new BufferedReader(new FileReader("sample.txt"));
		int n = Integer.parseInt(br.readLine());
		StringTokenizer st = new StringTokenizer(br.readLine());
		String[] bubble = new String[n];
		String[] select = new String[n];
		for (int i = 0; i < n; i++) {
			String str = st.nextToken();
			bubble[i] = str;
			select[i] = str;
		}
		boolean con=true;
		bubblesort(bubble);
		selectsort(select);
		StringBuilder stb1 = new StringBuilder(bubble[0]);
		StringBuilder stb2 = new StringBuilder(select[0]);
		for (int i = 1; i < n; i++){
			stb1.append(" " + bubble[i]);
			stb2.append(" " + select[i]);
			if(con&&!(bubble[i].equals(select[i]))) con=false;
				}
		System.out.println(stb1+"\r\n"+"Stable");			
		System.out.println(stb2+"\r\n"+(con?"Stable":"Not stable"));

	}

	static void bubblesort(String[] in) {
		int count = 0;
		for (int i = in.length; i > 0; i--) {
			for (int j = 1; j < i; j++) {

				if (in[j - 1].charAt(1) > in[j].charAt(1)) {
					count++;
					String tmp = in[j - 1];
					in[j - 1] = in[j];
					in[j] = tmp;
				}
			}
		}
		
	}

	static void selectsort(String[] in) {
		int count=0;
		for(int i=0;i<in.length-1;i++){
			int mini=i;
			for(int j=i+1;j<in.length;j++){
				if(in[mini].charAt(1)>in[j].charAt(1)){
					mini=j;
				}
				}
			if(mini!=i){
				count++;
			String tmp=in[i];
			in[i]=in[mini];
			in[mini]=tmp;}
		}}
}

Measured memory_bytes: 17076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v) v.begin(), v.end()
#define revall(v) v.rbegin(), v.rend()
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true; } return false; }






int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	string s;cin >> s;
	int ans = 1;
	rep(i,n - 1) if(s.at(i + 1) != s.at(i)) ans++;
	cout << ans << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int n;
int m;
int b,c;
multiset<int> a;
pair<int,int> quer[100100];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>m;
	int x;
	for(int i=0;i<n;i++)
	{
		cin>>x;
		a.insert(x);
	}
	for(int j=1;j<=m;j++){
		cin>>quer[j].second>>quer[j].first;
	}
	sort(quer+1,quer+m+1);
	reverse(quer+1,quer+m+1);
	for(int j=1;j<=m;j++){
		b=quer[j].second;
		c=quer[j].first;
		int cur=0;
		while(cur<b&&*a.begin()<c){
			cur++;
			a.erase(a.begin());
			a.insert(c);
		}
	}
	long long tot=0;
	for(__typeof(a.begin()) it=a.begin();it!=a.end();it++)
		tot+=(long long)(*it);
	cout<<tot<<endl;
	return 0;
}


Measured memory_bytes: 5760
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	ll n, x;
	cin >> n >> x;
	ll a[n];
	for(ll i=0; i<n; i++){
		cin >> a[i];
	}
	ll ans=0;
	if(a[0]>x){
		ans=a[0]-x;
		a[0]=x;
	}
	for(ll i=1; i<n; i++){
		ll d=a[i-1]+a[i]-x;
		if(d>0){
			ans+=d;
			a[i]-=d;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <random>
#include <vector>
#include <string>
#include <cstring>
#include <cassert>
#include <complex>
#include <ctime>
#include <numeric>
using namespace std;

#define pb push_back
#define pii pair <int, int>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define reunique(x) (x).resize(unique(all(x)) - (x).begin())
#define ld long double
#define int long long
const int mod = 1e9 + 7;

int bpow(int a, int n) {
	int ret = 1;
	while (n) {
		if (n & 1)
			(ret *= a) %= mod;
		(a *= a) %= mod;
		n /= 2;
	}
	return ret;
}

int dp[100500];

void SOLVE() {
	int n, k;
	cin >> n >> k;

	int ans = 0;
	for (int g = k; g >= 1; g--) {
		int cur = bpow(k / g, n);
		for (int i = 2 * g; i <= k; i += g) {
			cur = (cur - dp[i] + mod) % mod;
		}
		dp[g] = cur;
		(ans += cur * g % mod) %= mod;
	}

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

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cout << fixed;
	cout.precision(10);
	int Q = 1;
	//cin >> Q;
	while (Q--) {
		SOLVE();
	}

	return 0;
}

Measured memory_bytes: 4328
#include <iostream>
#include <math.h>
using namespace std;

const int mxN = 11;
int grid[mxN][mxN];

int main() {
	int n, d;
	cin >> n >> d;
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= d; ++j)
			cin >> grid[i][j];
	int answer = 0;
	for(int i = 1; i <= n; ++i) {
		for(int j = i + 1; j <= n; ++j) {
			int cur = 0;
			for(int k = 1; k <= d; ++k)
				cur += (grid[i][k] - grid[j][k]) * (grid[i][k] - grid[j][k]);
			double x = sqrt(cur);
			int temp = x;
			bool ok = (temp * temp) == cur;
			answer += ok;
		}
	}
	cout << answer;
}


Measured memory_bytes: 3664
#include <iostream>
#include <string>
#include <vector>
#include <cmath>

#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define REPI(i, a, b) for (int(i) = int(a); (i) < int(b); ++(i))

using namespace std;

int main()
{
    int Z;           //入力待ち
    int j, k;        //for文用
    string to = ","; //デバッグ用
    int e_count = 0; //演算回数を数える
    int count = 0;   //よくあるカウント
    //----------

    //int n;
    //cin >> n;

    string s;
    cin >> s;
    REP(i, 3)
    {
        if (s[i] == '1')
            count++;
    }

    cout << count << endl;

    //-----------
    cin >> Z;
    return 0;
}

Measured memory_bytes: 256
//Author rahuliitkgp
/*A thing of beauty is a joy forever,
Its loveliness increases,
it will never pass into nothingness.*/
//Men at Work :)
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;

#define ff              first
#define ss              second
#define SZ(x)           ((int)(x).size())
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void cpp() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

void dfs(vector<ll>* adjList, vector<ll>& dp, ll curr, ll par, vector<bool>& visited) {
	visited[curr] = true;
	if (adjList[curr].empty()) {
		dp[curr] = 0;
		return;
	}
	for (auto ch : adjList[curr]) {
		if (!visited[ch]) dfs(adjList, dp, ch, curr, visited);
		dp[curr] = max(dp[curr], dp[ch] + 1);
	}
}

int main() {
	cpp();
	ll n, m;
	cin >> n >> m;
	vector<ll>* adjList = new vector<ll>[n];
	for (ll i = 0; i < m; i++) {
		ll u, v;
		cin >> u >> v;
		--u;
		--v;
		adjList[u].push_back(v);
	}
	vector<ll> dp(n, 0);
	vector<bool> visited(n);
	for (ll i = 0; i < n; i++) {
		if (!visited[i]) {
			dfs(adjList, dp, i, -1, visited);
		}
	}
	cout << *max_element(dp.begin(), dp.end()) << endl;
	return 0;
}








Measured memory_bytes: 10624
#include <bits/stdc++.h>
typedef long long ll;

#define rep(i, a, b) for (ll i = a; i < (ll)b; ++i)
#define INF 10e12
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

const long long MOD = 1e9 + 7;

int main(void)
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> v(n), w(n);
    rep(i, 0, n) cin >> v[i], v[i]--, w[v[i]] = i + 1;
    vector<ll> a(n), b(n);
    ll m = 25000;
    rep(i, 0, n)
    {
        a[i] = m * (i + 1);
        b[i] = m * (n - 1 - i) + w[i];
    }
    //ここでaは，単調増加，bは単調現象
    rep(i, 0, n) cout << a[i] << " ";
    cout << endl;
    rep(i, 0, n) cout << b[i] << " ";
    cout << endl;
}

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

int main() {
  int a, b, c, d; cin >> a >> b >> c >> d;
  
  if (a-c <= d && a-c >= -d) cout << "Yes" << endl;
  else if ((a-b <= d && a-b >= -d) && (b-c <= d && b-c >= -d)) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256