akhauriyash/Code-Regression huggingface dataset:
n = int(input())
a_list = sorted([int(x) for x in input().split()], reverse=True)
ans = 0
temp = 0
count = 0
e = None
for i in range(n):
    if a_list[i] == temp:
        count += 1
        if count == 2:
            if e is None:
                e = temp
                count -= 2
            else:
                ans = e * temp
                break
    else:
        temp = a_list[i]
        count = 1
print(ans)

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int n, m;
    cin >> n >> m;
    priority_queue<ll, vector<ll>, less<ll>> que;
    REP(i, n){
        ll a;
        cin >> a;
        que.push(a);
    }

    REP(i, m){
        ll a = que.top();
        que.pop();
        a >>= 1;
        que.push(a);
    }

    ll ans = 0;

    while(!que.empty()){
        ans += que.top();
        que.pop();
    }

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


Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,y;
	cin>>n>>y;
	for(register long long i=0;i<=n;i++)
		for(register long long j=0;j<=n-i;j++){
			int k=n-i-j;
			if(10000*i+5000*j+1000*k==y){
				cout<<i<<' '<<j<<' '<<k;
				return 0;
			}
		}
	cout<<"-1 -1 -1";
			
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int gcd(int x, int y){

    while(y != 0){
        int r = x % y;
        x = y;
        y = r;
    }
    return x;
}

int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int ans = a[0];
    for(int i = 1; i < n; i++){
        ans = gcd(a[i], ans);
        // cout << ans << '\n';

    }
    cout << ans << '\n';
    // cout << gcd(13, 5) << '\n';
}

Measured memory_bytes: 640
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

n = int(input())
divisors = make_divisors(n)
#print(divisors)
if len(divisors)%2==1:
    print(divisors[len(divisors)//2]*2-2)
else:
    m = len(divisors)//2
    print(divisors[m-1]+divisors[m]-2)

Measured memory_bytes: 9188
def getdata_input():
    while True:
        yield input()
def callFunc2(it):
    A0,B0,K=map(int, next(it).split())
    A=[0]
    B=[0]
    
    t=min(K,A0)
    A.append(t)
    t=min(K-t,B0)
    B.append(min(t,B0))
    return(" ".join([str(A0-sum(A)), str(B0-sum(B))]))
  
it=getdata_input()
print(callFunc2(it))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

typedef double D;
int n;
D dp[310][310][310];

D solve(int a, int b, int c)
{
    if (dp[a][b][c] != -1)
        return dp[a][b][c];
    D res = 1;
    if (a != 0)
        res += D(a) / D(n) * solve(a - 1, b, c);
    if (b != 0)
        res += D(b) / D(n) * solve(a + 1, b - 1, c);
    if (c != 0)
        res += D(c) / D(n) * solve(a, b + 1, c - 1);
    res *= D(n) / D(a + b + c);
    return dp[a][b][c] = res;
}

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

    cin >> n;
    int cnt[4] = {};
    rep(i, n)
    {
        int a;
        cin >> a;
        cnt[a]++;
    }
    rep(i, n + 1) rep(j, n + 1) rep(k, n + 1) dp[i][j][k] = -1;
    dp[0][0][0] = 0;
    D ans = solve(cnt[1], cnt[2], cnt[3]);
    printf("%.10lf\n", ans);
}

Measured memory_bytes: 227584
H, W = map(int, input().split())

matrix = []
ans = "Yes"

for _ in range(H):
    siw = list(input())
    matrix.append(siw)

memo = []

for h in range(H):
    for w in range(W):
        if matrix[h][w] == "#":
            if w == 0:
                if matrix[h][w+1] == ".":
                    memo.append((h,w))
            elif w == W-1:
                if matrix[h][w-1] == ".":
                    memo.append((h,w))
            else:
                if matrix[h][w-1] == "." and matrix[h][w+1] == ".":
                    memo.append((h,w))

for h, w in memo:
    if h == 0:
        if matrix[h+1][w] == ".":
            ans = "No"
            break
    elif h == H-1:
        if matrix[h-1][w] == ".":
            ans = "No"
            break
    else:
        if matrix[h-1][w] == "." and matrix[h+1][w] == ".":
            ans = "No"
            break

print(ans)


Measured memory_bytes: 3064
"use strict";

main(require("fs").readFileSync("/dev/stdin", "utf8"));

function main(input) {
  const [[groupCount], ...groups] = input.trim().split("\n").map(s => s.split(" ").map(Number));

  const ans = groups.reduce((p, [from, to]) => (to - from + 1 + p), 0);
  console.log(ans);
}

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

int solve(int a, int b, int c) {
    for (int i = 0; i < 100; i++) {
        if (a & 1 || b & 1 || c & 1) return i;
        int na = b / 2 + c / 2;
        int nb = a / 2 + c / 2;
        int nc = a / 2 + b / 2;
        a = na, b = nb, c = nc;
    }
    return -1;
}

int main() {
    int a, b, c; cin >> a >> b >> c;
    cout << solve(a, b, c) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
  ll q; cin >> q;
  ll accb=0, qi=0, mid=-1, sum=0;
  multiset<ll> lset, rset;
  REP(i, q) {
    ll v; cin >> v;
    if (v == 1) {
      ll a, b; cin >> a >> b;
      accb += b; qi++;
      if (qi==1) {
        rset.insert(a);
        mid = a;
      } else if (qi == 2) {
        ll w = *rset.begin();
        if (w <= a) lset.insert(a);
        else {
          rset.clear();
          rset.insert(a); lset.insert(w);
        }
        mid = *rset.begin();
        sum = *lset.begin() - mid;
      } else {
        ll mss1 = rset.size(), mss2 = lset.size();
        if (*rset.rbegin() >= a) {
          rset.insert(a);
          if (rset.size()-2 >= lset.size()) {
            ll w = *rset.rbegin();
            rset.erase(--rset.end());
            lset.insert(w);
          }
        } else {
          lset.insert(a);
          if (lset.size() > rset.size()) {
            ll w = *lset.begin();
            lset.erase(lset.begin());
            rset.insert(w);
          }
        }
        ll tmp = *rset.rbegin();
        sum += abs(tmp - a);
        sum += abs((tmp - mid) * (mss1 - mss2));
        mid = tmp;
      }
    } else {
      cout << mid << ' ' << sum+accb << endl;
    }
  }
  return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, pair<ll, ll> > P3;

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_N = int(2e3) + 5;
const double EPS = 1e-8;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)

int main() {
    int h, w;
    string s[55];
    cin >> h >> w;
    REP(i, h) {
        cin >> s[i];
        REP(j, w) {
            if (s[i][j] == '.') s[i][j] = '0';
        }
    }
    REP(i, h) {
        REP(j, w) {
            if (s[i][j] == '#') {
                for (int y = -1; y <= 1; y++) {
                    for (int x = -1; x <= 1; x++) {
                        int ni = i + y, nj = j + x;
                        if (ni < 0 || ni >= h || nj < 0 || nj >= w ||
                            s[ni][nj] == '#')
                            continue;
                        s[ni][nj]++;
                    }
                }
            }    
        }
    }
    REP(i, h) {
         cout << s[i] << endl;
        }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
 
int N, M;
int a[1050], b[1050], c[1050][20];
 
void input() {
    cin >> N >> M;
    for(int i = 1; i <= M; i++) {
        cin >> a[i] >> b[i];
        for(int j = 1; j <= b[i]; j++) cin >> c[i][j];
    }
}
 
void solve() {
    input();
    const int INF = 1e9;
    vector<int> dp(5000, INF);
    dp[0] = 0;
    for(int item = 1; item <= M; item++) {
        int now = 0;
        for(int j = 1; j <= b[item]; j++) {
            now |= (1 << (c[item][j] - 1));
        }
        for(int bits = 0; bits < (1 << N); bits++) {
            chmin(dp[bits | now], dp[bits] + a[item]);
        }
    }
    if(dp[(1 << N) - 1] == INF) dp[(1 << N) - 1] = -1;
    cout << dp[(1 << N) - 1] << endl;
    return;
}
 
int main() {
    solve();
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stdint.h>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
typedef pair<int ,int> pp;
typedef long long ll;
const ll MOD = 1000000007;

int main(){
    string s;
    cin>>s;
    int ans;
    if(s == "SUN") ans = 7;
    if(s == "MON") ans = 6;
    if(s == "TUE") ans = 5;
    if(s == "WED") ans = 4;
    if(s == "THU") ans = 3;
    if(s == "FRI") ans = 2;
    if(s == "SAT") ans = 1;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
var
  s:array[0..100] of string;
  n,l,i,j:longint;
begin
  readln(n,l);
  for i:=1 to n do readln(s[i]);
  for i:=1 to n-1 do
   for j:=i+1 to n do
    if s[i]>s[j] then begin s[0]:=s[i];s[i]:=s[j];s[j]:=s[0]; end;
  for i:=1 to n do write(s[i]);
end.

Measured memory_bytes: 128
N = int(input())
for i in range(N):
    x,y,b,p = list(map(int,input().split()))


    def calc(x,y,b,p):
        m = min(p//2,b//5)
        #return 0.8*(5*m*x + 2*m*y) + (b-5*m)*x + (p-2*m)*y
        c = x*b + y*p
        return 0.8*c if m > 0 else c
    
    v = []
    v.append(calc(x,y,b,p))
    add_p = 2 - p % 2
    add_b = 5 - b % 5
    v.append(calc(x,y,b+add_b,p))
    v.append(calc(x,y,b,p+add_p))
    v.append(calc(x,y,b+add_b,p+add_p))
    print(int(min(v)))
    #print(v)

Measured memory_bytes: 6752
from collections import *
import sys
try: inp = raw_input
except: inp = input
def err(s):
    sys.stderr.write('{}\n'.format(s))

def ni():
    return int(inp())

def nl():
    return [int(_) for _ in inp().split()]

K = ni()

def gcd(a, b):
    return a if b == 0 else gcd(b, a%b)


DP = {}
def gcd_SUM(K, a):
    if (K, a) in DP: return DP[K, a]
    sm = 0
    for i in range(1, K+1):
        sm += gcd(i, a)
    DP[K, a] = sm
    return sm


S = 0

for a in range(1, K+1):
    for b in range(1, K+1):
        S += gcd_SUM(K, gcd(a, b))
print(S)



Measured memory_bytes: 9484
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i, n) for (int i = 0; i < n; i++)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
int dxx[8] = { 1, 1, 1, 0, 0, -1, -1, -1 }, dyy[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };

int n;
int main() {
    cin >> n;
    int a[n], x[n][n], y[n][n];
    rep (i, n) {
        cin >> a[i];
        rep (j, a[i]) {
            cin >> x[i][j] >> y[i][j];
        }
    }
    int ans = 0;
    for (int bit = 0; bit < (1 << n); bit++) {
        vector<int> vec;
        rep (i, n) if (bit & (1 << i)) vec.push_back (i);
        bool chk = 1;
        //for (auto i : vec) cout << i << " ";
        for (auto i : vec) {
            rep (j, a[i]) {
                if (find (vec.begin(), vec.end(), x[i][j] - 1) == vec.end() && y[i][j] == 1) {
                    chk = 0;
                    break;
                } else if (find (vec.begin(), vec.end(), x[i][j] - 1) != vec.end() && y[i][j] == 0) {
                    chk = 0;
                    break;
                }
            }
            if (!chk) break;
        }
        if (chk) {
            int sum = vec.size();
            ans = max (sum, ans);
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
bool s[10];
ll x,y,z;
ll dp[105][10];
int h,w,k;
const ll mod = 1e9 + 7;
void f(int i, int j) {
  if(i == w) {
    if(s[j-1]) x++;
    else if (s[j]) z++;
    else y++;
    return;
  }

  if(!s[i-1]) {
    s[i] = false;
    f(i+1,j);
    s[i] = true;
    f(i+1,j);
  }
  else {
    s[i] = false;
    f(i+1,j);
  }
  return;
}

int main() {
 
  cin >> h >> w >> k;
  dp[1][1] = 1;
  for(int i = 1; i <= h; i++) {
    for(int j = 1; j <= w; j++) {
      x = 0;
      y = 0;
      z = 0;
      fill(s,s+9,false);
      f(1,j);
      // cout << x <<"  "<< y <<"  "<< z<<endl;
      dp[i+1][j-1] = (dp[i+1][j-1] + dp[i][j] * x % mod) % mod;
      dp[i+1][j] = (dp[i+1][j] + dp[i][j] * y % mod) % mod;
      dp[i+1][j+1] = (dp[i+1][j+1] + dp[i][j] * z % mod) % mod;
    }
  }

  /*for(int i = 1; i <= h+1; i++) {
    for(int j = 1; j <= w; j++) {
      cout << dp[i][j] << endl;
    }
    }*/

  cout << dp[h+1][k] << endl;
}

  
      


Measured memory_bytes: 256
# coding: utf-8


def main():

    cake_count = int(input())
    own_cakes = []
    for _ in range(cake_count):
        own_cakes.append(int(input()))
    own_cakes = sorted(own_cakes, reverse=True)

    kagami_cakes = [own_cakes.pop(0)]
    for i, cake in enumerate(own_cakes):
        if cake < kagami_cakes[-1]:
            kagami_cakes.append(own_cakes[i])
        else:
            continue

    print(len(kagami_cakes))

    return 0


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline int read()
{
	int f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
const int MAXMASK=(1<<15);
const int MAXN=20;
const int mod=1e9+7;
void ad(int &x,int y){x+=y;if(x>=mod)x-=mod;}
int f[MAXN][MAXMASK][3];
int n,m,nx[MAXN],bin[MAXN],ct[MAXMASK];
int tot[MAXN],ln;
int main()
{
	bin[1]=1;for(int i=2;i<20;i++)bin[i]=bin[i-1]<<1;
	n=read();m=read();
	for(int i=1;i<=m;i++)
	{
		int x=read(),y=read();
		nx[x]|=bin[y];
	}
	for(int i=1;i<bin[n+1];i++)ct[i]=ct[i-(i&-i)]+1;
	f[0][bin[n+1]-1][0]=1;
	for(int i=0;i<n;i++)for(int j=1;j<bin[n+1];j++)for(int k=0;k<3;k++)if(f[i][j][k]&&k!=1)
	{
		ln=0;
		for(int l=1;l<=n;l++)if(j&bin[l])tot[++ln]=l;
		for(int S=j;S;S=(S-1)&j)
		{
			int cnt=1;
			for(int l=1;l<=ln;l++)
			{
				if(!(S&bin[tot[l]]))
				{
					int o=nx[tot[l]]&S;
					if(!o){cnt=0;break;}
					cnt=1LL*cnt*(bin[ct[o]+1]-1)%mod;
				}
				else
				{
					int o=nx[tot[l]]&(j^S);
					cnt=1LL*cnt*bin[ct[o]+1]%mod;
				}
			}
			if(k)ad(f[i+1][j^S][k],1LL*f[i][j][k]*cnt%mod);
			else
			{
				if((S&bin[1])&&(S&bin[2]))ad(f[i+1][j^S][1],1LL*f[i][j][k]*cnt%mod);
				else if((S&bin[1])||(S&bin[2]))ad(f[i+1][j^S][2],1LL*f[i][j][k]*cnt%mod);
				else ad(f[i+1][j^S][0],1LL*f[i][j][k]*cnt%mod);
			}
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++)ad(ans,f[i][0][2]%mod);
	pr2(ans);
	return 0;
}

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

int main() {
  int X,Y;
  cin >> X >> Y;
  
  int crane = 0;
  int turtle =0;
  bool can = false;
  
  for(int i=0; i<X+1; i++){
    if( 2*i + 4*(X-i) == Y) can = true;
  }
  
  if(can) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3628
N = int(input())


def gcd(a, b):
    x = max(a, b)
    y = min(a, b)
    mod = x % y
    if mod == 0:
        return y

    return gcd(y, mod)


def lcm(a, b):
    return a*b//gcd(a, b)


print(lcm(2, N))


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

string s[300];
int dx[8] = {0,0,1,-1,-1,-1,1,1};
int dy[8] = {1,-1,0,0,-1,1,-1,1}; 

int dfs( int i , int j , int n ){

  int cnt = 0;
  for( int k = 0 ; k < 8 ; k++ ){
    int cnt2 = 0;
    int x = i;
    int y = j;
    while( 0 <= x && x < n && 0 <= y && y < n ){
      if( s[x][y] == '1' ){
	x += dx[k];
      y += dy[k];
      cnt2++;
      }
      else break;
    }
    cnt = max( cnt , cnt2 ); 
    //８方向動かして、カウント
  }
  return cnt;
}

int main(void){
  
  while(1){

    int n;
    cin >> n;
    if( n == 0 ) break;
    
    for( int i = 0 ; i < n ; i++ ){
      cin >> s[i];
    }
    
    int ans = 0;
    for( int i = 0 ; i < n ; i++ ){
      for( int j = 0 ; j < n ; j++ ){
	if( s[i][j] == '1' ){
	  ans = max( ans , dfs(i,j,n) );
	}
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1292
#include <iostream>
#include <math.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <map>
using namespace std;
 
int main() {
	string S;
	cin >> S;
	long long int dp[100010][13] = {},len=S.length();
	dp[0][0] = 1;
	for (int i = 1; i <= len; i++)
	{
		int num = S[i - 1] - '0';
		for (int j = 0; j < 13; j++)
		{
			if (num != '?' - '0') {
				dp[i][(j * 10 + num) % 13] += dp[i - 1][j];
			}
			else
			{
				for (int k = 0; k < 10; k++)
				{
					dp[i][(j * 10 + k)%13] += dp[i - 1][j];
				}
			}
		}
		for (int j = 0; j < 13; j++)dp[i][j] %= 1000000007;
	}
	cout << dp[len][5];
}

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int main() {
	int m, n;
	cin >> m >> n;
	
	vector< int > deg(m, 0);
	vector< vector< int > > adj(m, vector< int >());
	
	for_(i,0,n) {
		int x, y;
		cin >> x >> y;
		--x; --y;
		
		++deg[y];
		adj[x].push_back(y);
	}
	
	queue< int > que;
	for_(i,0,m) if (deg[i] == 0) que.push(i);
	
	vector< int > order;
	
	while (!que.empty()) {
		int v = que.front(); que.pop();
		order.push_back(v);
		
		int adj_num = (int)adj[v].size();
		for_(i,0,adj_num) {
			int u = adj[v][i];
			--deg[u];
			if (deg[u] == 0) que.push(u);
		}
	}
	
	for_(i,0,m) cout << order[i] + 1 << endl;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

using ll = long long;
ll mod = pow(10, 9) + 7;

template <typename T> void output(T, ll);
ll gcd(ll, ll);
ll lcm(ll, ll);
Bint comb(Bint, Bint);
void prime_map(map<ll, ll> &, ll);

int main() {
    // source
    string s, t;
    cin >> s >> t;
    vector<ll> q[26];
    ll s_len = s.size();
    rep(i, s_len) {
        int num = s[i] - 'a';
        q[num].push_back(i + 1);
    }

    ll t_len = t.size();
    ll ans = 0;
    ll loop = 0;
    ll look = 0;
    rep(i, t_len) {
        int num = t[i] - 'a';
        if (q[num].size() == 0) {
            ans = -1;
            break;
        } else {
            auto iter = lower_bound(q[num].begin(), q[num].end(), look + 1);
            if (iter == q[num].end()) {
                iter = q[num].begin();
                loop++;
            }
            look = *iter;
            ans = loop * s_len + look;
        }
    }

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

Bint comb(Bint a, Bint b) {
    Bint ans = 1;

    if (a < b) {
        return 0;
    }

    rep(i, b) {
        ans *= a - i;
        ans /= i + 1;
    }

    return ans;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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

ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

void prime_map(map<ll, ll> &m, ll num) {
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }

    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }
        return;
    } else {
        prime_map(m, num);
    }
}


Measured memory_bytes: 1724
n,k = map(int, input().split())
max_connect = (n-1)*(n-2)//2
if k > max_connect:
    print(-1)
else:
    print(n+max_connect - k -1)
    for i in range(n-1):
        print(i+1,n)

    end = max_connect - k
    cnt = 0
    cntflg = end > 0
    for i in range(n-1):
        for j in range(i+1,n-1):
            if cntflg:
                print(i+1,j+1)
                cnt += 1
            if cnt == end:
                cntflg = False

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
typedef long long ll;
const int INF = 1<<29;
const int N = 1e6 + 9;
ll a[N];
bool cmp(const pair<double, ll> &a, const pair<double, ll> &b)
{
    if(a.first == b.first){
        return a.second < b.second;
    }
    return a.second > b.second;
}
int main()
{
    fio;
   // cout <<
    string s;
    cin >> s;
    ll st = -1, fin = -1;
    if(s.size() == 2 && s[0] == s[1]){
        cout << 1 << " " << 2;
        return 0;
    }
    for(int i = 0; i < s.size() - 2; i ++)
    {
        set <char> se;
        se.insert(s[i]);
        se.insert(s[i + 1]);
        se.insert(s[i + 2]);
        if(se.size() < 3){
            cout << i + 1 << " " << i + 3;
            return 0;
        }
    }
    cout << st << " " << fin;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#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> a(n);
  rep(i, n) {
    cin >> a[i];
    a[i]--;
  };
  vector<int> b(n);
  rep(i, n) cin >> b[i];
  vector<int> c(n);
  rep(i, n - 1) cin >> c[i];

  int ans = 0;
  rep(i, n) {
    ans += b[a[i]];
    if (i != n - 1 && a[i] + 1 == a[i + 1]) {
      ans += c[a[i]];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define itn int
#define fi first
#define se second
#define be begin()
#define en end()
#define reverse
const int mod=1000000007;
const int INFi=2147483647;
const long long INFl=9223372036854775807LL;
template<typename T> T abs(T a,T b){
  return max(a,b)-min(a,b);
}
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,m,ans=0,j=0;
  int h[10000000];
  itn a,b,f;
  vector<int> d[1000000];
  cin>>n>>m;
  for(int i=1;i<=n;i++){
    cin>>h[i];
  }
  for(int i=0;i<m;i++){
    cin>>a>>b;
    d[a].push_back(b);
    d[b].push_back(a);
  }
  for(int i=1;i<=n;i++){
    f=1;
    for(int j=0;j<d[i].size();j++){
      if(h[i]<=h[d[i][j]]){
	   f=0;
        break;
      }
    }
    if(f) ans++;
  }
  cout<<ans<<"\n";
}
      

Measured memory_bytes: 31264
nums = [int(i) for i in input().split()]
x = nums[0]
y = nums[1]
z = nums[2]

capacity = y + 2 * z
ans = 0
while(capacity <= x):
    if capacity == x:
        ans += 1
        break
    else:
        capacity += y + z
        ans += 1
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);};};
const int MOD = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<62;


ll add(ll a, ll b){
    if(a == 0){
        return 0;
    } else if(a<=b){
        return b-a;
    } else if(a%b==0){
        return 0;
    }else {
        //9 4;
        return b-(a-a/b*b);
    }
}


int main(void) {

    int n;
    cin>>n;
    vll a(n),b(n);
    rep(i,n){
        cin>>a[i]>>b[i];
    }
    ll ans=0;

    for(int i=n-1;i>=0;i--){
        a[i]+=ans;
        ll tmp =add(a[i],b[i]);
        ans+=tmp;
        a[i]+=tmp;
    }
    fin(ans);

}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

int E[5001], n[5001], C[5001], H[2501];
bool vis[2501];
void dfs(int v) {
	vis[v] = true;
	for (int p = H[v]; p; p = n[p]) {
		int to = E[p];
		if (!vis[to]) dfs(to);
	}
}

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


	int N, M, P;
	cin >> N >> M >> P;
	rep1(i, M) {
		int a;
		cin >> a >> E[i] >> C[i];
		n[i] = H[a];
		H[a] = i;
	}
	ll D[2501];
	rep1(i, N) D[i] = -2e9;
	D[1] = 0;
	int q[2501] = {};
	q[1] = 1;

	rep1(k, N) {
		rep1(i, N) {
			if (q[i] == k) {
				for (int p = H[i]; p; p = n[p]) {
					int to = E[p];
					ll d = D[i] + C[p] - P;
					if (D[to] < d) {
						D[to] = d;
						q[to] = k + 1;
					}
				}
			}
		}
	}

	rep1(i, N) {
		if (q[i] == N + 1 && !vis[i]) dfs(i);
	}

	if (vis[N]) co(-1);
	else co(max(0ll, D[N]));


	Would you please return 0;
}

Measured memory_bytes: 384
def number_of_divisors(x: int) -> int:
    count = 0
    for i in range(1, x + 1):
        if x % i == 0:
            count += 1

    return count


def answer(n: int) -> int:
    if n < 105:
        return 0

    count = 0
    for i in range(105, n + 1, 2):
        if number_of_divisors(i) == 8:
            count += 1

    return count


def main():
    n = int(input())
    print(answer(n))


if __name__ == '__main__':
    main()


Measured memory_bytes: 9148
def num_combinations_mod(n, r, mod, num_max=10**6):
    # if this functions is called twice or more, init process should be placed before calling this function to
    # save time.
    if r > n:
        return 0
    elif r == n:
        return 1
    elif r < 0 or n < 0:
        return 0
    f_mod, f_mod_inv = num_combinations_mod_init(num_max, mod)
    return f_mod[n] * (f_mod_inv[r] * f_mod_inv[n-r] % mod) % mod


def num_combinations_mod_init(num_max, mod):
    factorials_mod = dict()
    factorials_mod_inv = dict()
    factorials_mod[0] = 1
    factorials_mod[1] = 1
    factorials_mod_inv[0] = 1
    factorials_mod_inv[1] = 1
    mod_inv = dict()
    mod_inv[1] = 1
    for i in range(2, num_max):
        factorials_mod[i] = factorials_mod[i - 1] * i % mod
        mod_inv[i] = mod - mod_inv[mod % i] * (mod // i) % mod
        factorials_mod_inv[i] = factorials_mod_inv[i - 1] * mod_inv[i] % mod
    return factorials_mod, factorials_mod_inv


def get(num1, num2):
    if num1 > num2:
        num = num2
    else:
        num = num1
    return num_combinations_mod(num1+num2, num, 10**9+7)


def main(X, Y):
    if (X + Y) % 3 != 0:
        return 0

    total = (X + Y) // 3
    n_moveB = (2 * X - Y) // 3
    n_moveA = total - n_moveB
    answer = get(n_moveA, n_moveB)

    return answer


X, Y = map(int, input().split(" "))
print(main(X, Y))



Measured memory_bytes: 277596
#include <bits/stdc++.h>
#define int long long
#define range(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;
const int INF = sizeof(int) == sizeof(long long) ? 1e18 : 1e9;
const int MOD = 1000000007;
const long double EPS = 1e-8;

signed main() {
	int n;
	cin >> n;
	int a[n + 2];
	a[0] = a[n + 1] = 0;
	rep (i, n) cin >> a[i + 1];
	int sum = 0;
	rep (i, n + 1) sum += abs(a[i + 1] - a[i]);
	rep (i, n) cout << sum - abs(a[i + 1] - a[i]) - abs(a[i + 2] - a[i + 1]) + abs(a[i + 2] - a[i]) << endl;
	return 0;
}

Measured memory_bytes: 2048
s = input()
k = int(input())
series_one_end = 0
for i in range(len(s)):
    if s[i] == '1':
        series_one_end = int(i + 1)
    else:
        break
if k <= series_one_end:
    print(1)
else:
    print(s[series_one_end])

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  string S,T;
  cin >> N >> S >> T;
  string ans="";
  for(int i=0; i<N; i++){
  	ans+=S.at(i);
    ans+=T.at(i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <utility>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
int n;
int p[65001],j[65001];
int main()
{
	while(cin>>n&&n){
		ll ans=0,sum=0;
		for(int i=0;i<n;i++){
			cin>>p[i];
			sum+=p[i];
		}
		for(int i=0;i<n-1;i++)cin>>j[i];
		sort(j,j+(n-1),greater<int>());
		for(int k=0,num=n;num>=1;){
			//printf("k:%4d num:%4d sum:%4d\n",k,num,sum);
			ans=max(ans,sum*num);
			num--;
			sum+=j[k++];
		}
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1672
#22:24
s = input()
mod = 10 ** 9 + 7
cum = [[0],[0],[0],[0]]
for i in range(len(s)):
  tmp = ord(s[i]) - 65
  if tmp == -2:
    tmp = 3
  for j in range(4):
    if j == tmp:
      cum[j].append(cum[j][-1]+1)
    else:
      cum[j].append(cum[j][-1])
q = cum[3][-1]
tri = [1]
for _ in range(len(s)):
  tri.append(tri[-1] * 3 % mod)
ans = 0
for i in range(len(s)):
  if s[i] == 'B':
    ans += cum[0][i] * (cum[2][-1]-cum[2][i+1]) * tri[q]
    ans += cum[0][i] * (cum[3][-1]-cum[3][i+1]) * tri[q-1]
    ans += cum[3][i] * (cum[2][-1]-cum[2][i+1]) * tri[q-1]
    ans += cum[3][i] * (cum[3][-1]-cum[3][i+1]) * tri[q-2]
  if s[i] == '?':
    ans += cum[0][i] * (cum[2][-1]-cum[2][i+1]) * tri[q-1]
    ans += cum[0][i] * (cum[3][-1]-cum[3][i+1]) * tri[q-2]
    ans += cum[3][i] * (cum[2][-1]-cum[2][i+1]) * tri[q-2]
    ans += cum[3][i] * (cum[3][-1]-cum[3][i+1]) * tri[q-3]
  ans %= mod
print(ans)

Measured memory_bytes: 13716
#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 FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()
#define BETWEEN(a, x, b) (a) <= (x) && (x) <= (b) 

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<string> vs;

int n;
vi a;

int cost(int y)
{
    int res = 0;
    REP(i, a.size()) res += (a[i] - y) * (a[i] - y);
    return res;
}

void solve()
{
    cin >> n;
    a = vi(n);
    REP(i, n) cin >> a[i];

    sort(ALL(a));
    
    int ans = cost(a[0]);
    FOR(i, a[0], a[a.size()-1]) ans = min(ans, cost(i));
    cout << ans << endl;
}

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

    return 0;
}

Measured memory_bytes: 256
while True:
  counter = 0
  try:
    n = int(input())
  except EOFError:
    break
  for a in range(10):
    for b in range(10):
      for c in range(10):
        for d in range(10):
          if a+b+c+d == n:
            counter += 1
  print(counter)


Measured memory_bytes: 5588
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int main() {
  string s;
  while(cin>>s) {
    int a=0,b=0;
    REP(i,s.size()-2) {
      string ss=s.substr(i,3);
      if (ss == "JOI") a++;
      else if (ss == "IOI") b++;
    }
    cout << a << endl << b << endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

const int oo = 1e9;
const int N = 2e5 + 6;
const int LOG = 16;

int n;
int arr[N][2];
long long dp[2][N][LOG];

long long solve(int t, int i, int taken)
{
  if (i >= n)
    return 0;
  long long& r = dp[t][i][taken];
  if(r != -1)
    return r;
  int p = 0;
  long long tmp = arr[i][t];
  long long prv = arr[i - 1][t] * (1LL << (2 * taken));
  while(tmp * (1LL << (2 * p)) < prv)
    p++;
  int rem = max(0, p - 15);
  return r = rem * (n - i - 1) + p + solve(t, i + 1, p - rem);
}

long long solve(int t, int i)
{
  if(i >= n)
    return 0;
  return solve(t, i + 1, 0);
}

int main()
{
  while(~scanf("%d", &n) && n){
    for(int i = 0 ; i < n ; i++){
      int a;
      scanf("%d", &a);
      arr[i][0] = a;
      arr[n - 1 - i][1] = a;
    }
    // for(int i = 0 ; i < n ; i++)
    //   cout << arr[i][0] << "\t";
    // cout << endl;
    // for(int i = 0 ; i < n ; i++)
    //   cout << solve(0, i) << "\t";
    // cout << endl;
    // for(int i = 0 ; i < n ; i++)
    //   cout << solve(1, n - i - 1) << "\t";
    // cout << endl;

    memset(dp, -1, sizeof dp);
    long long ans = solve(0, 0) * 2;
    for(int i = 0 ; i < n ; i++){
      long long cur = (solve(0, i + 1) + solve(1, n - i - 1)) * 2 + i + 1;
      // cout << i << " " << cur << endl;
      ans = min(ans, cur);
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 61184
import sys
sys.setrecursionlimit(10 ** 9)

def rec(v):
 if memo[v]!=-1:
  return memo[v]

 res=0
 for nv in tree[v]:
  res=max(res,rec(nv)+1)

 memo[v]=res
 return res

n,m=map(int,input().split())

tree=[[] for i in range(n)]
memo=[-1 for i in range(n)]

for i in range(m):
 x,y=map(int,input().split())
 x-=1
 y-=1
 tree[x].append(y)

ans=0
for v in range(n):
 ans=max(ans,rec(v))
print(ans)

Measured memory_bytes: 59008
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <map>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;
typedef long double ld;

vector<ll> prime_list(ll n){
    vector<ll> list;
    FOR(i,2,n){
        if(i==2){list.push_back(i);continue;}
        if(i%2==0)continue;
        bool is=true;
        FOR(j,2,sqrt(i)){
            if(i%j==0){
                is=false;
                break;
            }else{
                is=true;
            }
        }
        if(is){
            list.push_back(i);
        }
    }
    return list;
}

int main(){
    ll n,cnt=0;
    cin>>n;
    vector<ll> primes=prime_list(n);
    vector<ll> v(1001,1);
    FOR(i,2,n){
        ll p;
        REP(j,SIZE(primes)){
            p=primes[j];
            if(i%p==0){
                ll num=i;
                while(num%p==0){
                    num/=p;
                    v[p]++;
                }
            }
            if(p>i)break;
        }
    }
    ll prd=1;
    REP(i, 1001){
        prd*=v[i];
        prd%=1000000007;
    }
    cout<< prd <<endl;
    return 0;
}


Measured memory_bytes: 3612
//daddy's back in town, back to rolling the damn hash yoooo babeeeeees//
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define x first
#define y second
#define pi pair <int, int>
#define vi vector <int>
#define L nod<<1
#define R ((nod<<1)|1)
#define int ll
const ll mod = 998244353;
int n, m, d[100010];
bool viz[100010];
vector<pi> g[100010];

bool dfs(int nod){
	viz[nod]=1;
	for(pi i: g[nod]){
		if(viz[i.x]==0){
			d[i.x]=d[nod]+i.y;
			if(dfs(i.x)==0) return 0;
		}
		else{
			if(d[nod]+i.y!=d[i.x]) return 0;
		}
	}
	return 1;
}

int32_t main(){
	ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	cin>>n>>m;
	for(int i=1; i<=m; i++){
		int l, r, x;
		cin>>l>>r>>x;
		g[l].pb({r, x});
		g[r].pb({l, -x});
	}
	for(int i=1; i<=n; i++){
		if(viz[i]==0 && dfs(i)==0) return cout<<"No", 0;
	}
	cout<<"Yes";
}

Measured memory_bytes: 15616
def main():
    H, W = map(int, input().split())
    g = []
    q = []
    cnt = 0
    for h in range(H):
        A = str(input())
        row = []
        for w in range(W):
            row.append(A[w])
            if A[w] == '#':
                cnt += 1
                q.append([h, w])
        g.append(row)
    ans = 0
    dh = [1, 0, 0, -1]
    dw = [0, -1, 1, 0]
    while cnt < H * W:
        ans += 1
        nextq = []
        while q:
            h, w = q.pop()
            for i in range(4):
                nh = h + dh[i]
                nw = w + dw[i]
                if 0 <= nh < H and 0 <= nw < W and g[nh][nw] == '.':
                    g[nh][nw] = '#'
                    nextq.append([nh, nw])
                    cnt += 1
        q = nextq
    print(ans)
main()


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

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

const int INF = 1001001001;
const int di[] = {-1, 0,  1, 0};
const int dj[] = { 0, -1, 0, 1};

int main() {
    int h, w; cin >> h >> w;
    vector<string> s(h);
    for (int i = 0; i < h; i++) {
        cin >> s[i];
    }

    int ans = 0;
    for (int hi = 0; hi < h; hi++) {
        for (int wj = 0; wj < w; wj++) {
            if (s[hi][wj] == '#') continue;
            vector<vector<int>> dist(h, vector<int>(w, INF));
            queue<P> q;
            auto update = [&](int i, int j, int x) {
                if (dist[i][j] != INF) return;
                dist[i][j] = x;
                q.push(P(i, j));
            };
            update(hi, wj, 0);
            while (!q.empty()) {
                int i = q.front().first;
                int j = q.front().second;
                q.pop();
                for (int dir = 0; dir < 4; dir++) {
                    int ni = i + di[dir];
                    int nj = j + dj[dir];
                    if (ni < 0 || ni >= h) continue;
                    if (nj < 0 || nj >= w) continue;
                    if (s[ni][nj] == '#') continue;
                    update(ni, nj, dist[i][j] + 1);
                }
            }
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    if (dist[i][j] == INF) continue;
                    ans = max(ans, dist[i][j]);
                }
            }
        }
    }
    cout << ans << endl;

    return 0;
}


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

int n,a[200100];
bool chk(int x){
	int tag=(a[1]>=x),delta=n*2;
	for(int i=2;i<2*n;++i)
		if((a[i-1]>=x)==(a[i]>=x)){
			int op=(a[i-1]>=x),d=abs(2*i-2*n-1);
			if(d<delta||(d==delta&&!op))tag=op,delta=d;
		}
	return tag;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<2*n;++i)cin>>a[i];
	int l=1,r=2*n-1;
	while(l<r){
		int mid=(l+r+1)/2;
		if(chk(mid))l=mid;
		else r=mid-1;
	}
	cout<<l<<'\n';
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)

int main() {
	string S;
	cin >> S;
	if (S == "hi" || S == "hihi" || S == "hihihi" || S == "hihihihi" || S == "hihihihihi") {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


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

vector<int> forintinput(int n) {
	vector<int> x;
	for(int i = 0;i < n;i++){
		int ia;
		cin >> ia;
		x.push_back(ia);
	}
	return x;
}
int main(){
	int x,y;
	cin >> x >> y;
	if(x * 2 <= y && x * 4 >= y && y % 2 == 0){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 3592
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>

using namespace std;

int main(){

int N,M;
cin>>N>>M;
int a,b;
bool ans=false;

vector<int>media;
map<int,int>last;

for(int i=0;i<M;i++){
cin>>a>>b;
if(a==1){
media.push_back(b);
}
if(b==N){
last.insert(make_pair(a,b));
}

}

int iter=0;
while(iter!=media.size()){

if(last.find(media[iter])!=last.end()){
    ans=true;
    break;
}
iter++;

}

if(ans){
    cout<<"POSSIBLE"<<endl;
}
else{
    cout<<"IMPOSSIBLE"<<endl;
}
 return 0;
}

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

int g[15][15];

int main() {
    int n; cin >> n;
    rep(i, n)rep(j, n) g[i][j] = -1;
    rep(i, n){
        int m; cin >> m;
        rep(j, m){
            int a, x;
            cin >> a >> x;
            a--;
            g[i][a] = x;
        }
    }
    int ans = 0;
    rep(i, 1<<n){
        vector<int> d(n);
        rep(j, n) if(i>>j & 1){
            d[j] = 1;
        }
        bool ok = true;
        rep(j, n){
            if(d[j]){
                rep(k, n){
                    if(g[j][k] == -1) continue;
                    if(g[j][k] != d[k]) ok = false;
                }
            }
        }
        if(ok) ans = max(ans, __builtin_popcount(i));
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
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 (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
const int mod=1e9+7;

int main(){
  int n;cin>>n;
  int n0=(1<<n);
  multiset<int> ideal;
  rep(i,n0){
    int tmp;cin>>tmp;
    ideal.insert(tmp);
  }
  vector<int> ans;
  auto ite=ideal.end();
  ans.push_back(*(--ite));ideal.erase(ite);
  rep(I,n){
    vector<int> children=ans;
    rep(i,ans.size()){
      int t=ans[i];
      auto it=ideal.lower_bound(t);
      if(ideal.begin()==it){
        cout<<"No"<<endl;exit(0);
      }
      it--;
      children.push_back(*it);
      ideal.erase(it);
    }
    swap(ans,children);
  }
  cout<<"Yes"<<endl;
}


Measured memory_bytes: 14200
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

int main() {
  int A, B;

  scanf("%2d%2d", &A, &B);

  bool YYMM = 1 <= B && B <= 12;
  bool MMYY = 1 <= A && A <= 12;

  if (YYMM && MMYY) {
    cout << "AMBIGUOUS" << endl;
  } else if (YYMM) {
    cout << "YYMM" << endl;
  } else if (MMYY) {
    cout << "MMYY" << endl;
  } else {
    cout << "NA" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    string expected, actual;
    
    std::cin >> expected >> actual;
    
    int result = 0;
    for (int i = 0; i < 3; i++) {
        if (expected[i] == actual[i]) {
            result++;
        }
    }

    std::cout << result << std::endl;
}


Measured memory_bytes: 256