akhauriyash/Code-Regression huggingface dataset:
hw = list(map(int, input().split()))
h = hw[0]
w = hw[1]

tile = []
for i in range(h):
    tile.append(list(map(int, input().split())))

c = [[0] * w for i in range(h)]

for i in range(w):
    if tile[0][i] == 0:
        c[0][i] = 1
    else:
        c[0][i] = 0

for i in range(h):
    if tile[i][0] == 0:
        c[i][0] = 1
    else:
        c[i][0] = 0

r = 0
for j in range(1, w):
    for i in range(1, h):
        if tile[i][j] == 0:
            c[i][j] = min([c[i-1][j-1], c[i][j-1], c[i-1][j]]) + 1
        else:
            c[i][j] = 0

for j in range(w):
    for i in range(h):
        if r < c[i][j]:
            r = c[i][j]

print(r**2)


Measured memory_bytes: 55196
mod = 10 ** 9 + 7


def mod_pow(a, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        half_p = p // 2
        half = mod_pow(a, half_p)
        return half * half % mod
    else:
        return a * mod_pow(a, p - 1) % mod


def calc_comb(a, b):
    if b > a - b:
        return calc_comb(a, a - b)

    ans_mul = 1
    ans_div = 1
    for i in range(b):
        ans_mul *= (a - i)
        ans_div *= (i + 1)
        ans_mul %= mod
        ans_div %= mod

    ans = ans_mul * mod_pow(ans_div, mod - 2) % mod
    return ans


X, Y = map(int, input().split())
if (X + Y) % 3 != 0:
    print(0)
    exit()
n = (2 * X - Y) // 3
m = (- X + 2 * Y) // 3
if n < 0 or m < 0:
    print(0)
    exit()
print(calc_comb(n + m, n))


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

# define x first
# define y second
# define mp make_pair
// everything goes according to my plan
# define pb push_back
# define sz(a) (int)(a.size())
# define vec vector
// shimkenttin kyzdary, dzyn, dzyn, dzyn...
# define y1    Y_U_NO_y1
# define left  Y_U_NO_left
# define right Y_U_NO_right

# ifdef Local
# define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
# else
# define debug(...) (__VA_ARGS__)
# define cerr if(0)cout
# endif

using namespace std;

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

const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const ll MXLL = 4e18;
const int Sz = 1110111;
// a pinch of soul
inline void Read_rap () {
  ios_base :: sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}
inline void randomizer3000 () {
  unsigned int seed;
  asm ("rdtsc" : "=A"(seed));
  srand (seed);
}
void files (string problem) {
  if (fopen ((problem + ".in").c_str(),"r")) {
    freopen ((problem + ".in").c_str(),"r",stdin);
    freopen ((problem + ".out").c_str(),"w",stdout);
  }
}
void localInput(const char in[] = "s") {
  if (fopen (in, "r")) {
    freopen (in, "r", stdin);
  }
  else
    cerr << "Warning: Input file not found" << endl;
}

int main()
{
  # ifdef Local
    //localInput();
  # endif
  Read_rap();
  while (true) {
    int n, q;
    cin >> n >> q;
    if (n + q == 0)
      break;

    map <int, int> cnt;
    for (int i = 1; i <= n; i++) {
      int k;
      cin >> k;
      while (k--) {
        int d;
        cin >> d;
        cnt[d]++;
      }
    } 
    int mx = 0;
    for (auto x : cnt) {
      if (cnt[mx] < x.y)
        mx = x.x;
    }
    if (cnt[mx] < q)
      mx = 0;
    cout << mx << endl;
  }


  return 0;
}






// Coded by Z..


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

int main(){
  int N;
  cin >> N;
  int x[N+1] = {0}, y[N+1] = {0};
  for(int i = 1; i <= N; i++){
    cin >> x[i];
    y[i] = x[i];
  }
  sort(y, y+N+1);
  int l = y[N/2];
  int r = y[N/2+1];
  for(int i = 1; i <= N; i++){
    if(x[i] <= l) cout << r << endl;
    else cout << l << endl;
  }
  return 0;
}


Measured memory_bytes: 3712
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{int n,d[100000],i,j;
while(~scanf("%d",&n))
  {
  for(i=0;i<n;i++)
    scanf("%d",&d[i]);
    sort(d,d+n);
    printf("%d\n",d[n/2]-d[n/2-1]);}
  
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <utility>

using namespace std;

int main()
{
    int H, W, K;
    cin>>H>>W>>K;
    vector<string> A(H);
    for (string &a: A)
        cin>>a;

    vector<vector<int>> D(H, vector<int>(W, 99999999));
    queue<pair<int,int>> Q;
    for (int y=0; y<H; y++)
    for (int x=0; x<W; x++)
        if (A[y][x] == 'S')
            D[y][x] = 0,
            Q.push(make_pair(x, y));
    int dx[] = {-1, 1, 0, 0};
    int dy[] = {0, 0, -1, 1};
    while (!Q.empty())
    {
        int sx = Q.front().first;
        int sy = Q.front().second;
        Q.pop();
        for (int d=0; d<4; d++)
        {
            int tx = sx + dx[d];
            int ty = sy + dy[d];
            if (0<=tx && tx<W && 0<=ty && ty<H && A[ty][tx]=='.' && D[ty][tx]>D[sy][sx]+1)
                D[ty][tx] = D[sy][sx]+1,
                Q.push(make_pair(tx, ty));
        }
    }

    int ans = 99999999;
    for (int y=0; y<H; y++)
    for (int x=0; x<W; x++)
        if (D[y][x] <= K)
            ans = min(ans, (min(min(y,H-y-1),min(x,W-x-1))+K-1)/K + 1);
    cout<<ans<<endl;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
const int N = 205;
int main() {
    long long x;
    cin >> x;
    for (long long i = -N; i < N; i++)
        for (long long j = -N; j < N; j++)
            if (i * i * i * i * i - j * j * j * j * j == x) {
                cout << i << ' ' << j << '\n';
                return 0;
            }
    return -1;
}

Measured memory_bytes: 3532
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
	string s;
	cin >> s;
	int cnt[26] = {};
	for(int i = 0; i < s.length(); i++){
		cnt[s[i] - 'a']++;
	}
	for(int i = 0; i < 26; i++){
		if(cnt[i] > 1){
			cout << "no" << endl;
			return 0;
		}
	}
	cout << "yes" << endl;
}

Measured memory_bytes: 256
/*************************************************************************
  >         File: B.cc
  >       Author: lyyllyyl
  >         Mail: riho.yoshioka@yandex.com
  > Created Time: Sat 01 Oct 2016 08:04:50 PM CST
*************************************************************************/
#include <bits/stdc++.h>
constexpr int N = 2e5 + 5;
int a[N], L[N], R[N];

int main() {
  std::ios::sync_with_stdio(0);
  int n;
  std::cin >> n;
  std::iota(L + 1, L + n + 1, 0);
  for (int i = 1; i <= n; ++i) R[i] = i + 1;
  for (int i = 0; i < n; ++i) std::cin >> a[i + 1];
  for (int i = 1; i <= n; ++i) {
    int j = L[i];
    while (j && a[j] > a[i]) j = L[j];
    L[i] = j;
  }
  for (int i = n; i >= 1; --i) {
    int j = R[i];
    while (j <= n && a[j] > a[i]) j = R[j];
    R[i] = j;
  }
  using LL = long long;
  LL answer = 0;
  for (int i = 1; i <= n; ++i) {
    answer += 1LL * a[i] * (R[i] - i) * (i - L[i]);
  }
  std::cout << answer << std::endl;

  return 0;
}


Measured memory_bytes: 2688
#include <iostream>
#include <algorithm>
#include <numeric>
#include "math.h"
#include <string>
#include <vector>
#include <iomanip>

#define pai 3.14159265358979323846264338327950288
using namespace std;

int main() {
	long long int n;
	long long int hoge;
	cin >> n;
	hoge = n-1;
	for (long long int i = 2; i <= sqrt(n); i++)
	{
		if (n % i != 0) 
		{
			continue;
		}
		//cout << i <<","<< n / i<<endl;
		if (hoge > (i - 1) + ((n / i) - 1))
		{
			hoge = (i - 1) + ((n / i) - 1);
		}
	}

	cout << hoge << endl;
	return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << endl;
#else
#define DBG(X)
#endif
 
using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const ll mod = 1e9 + 7;
const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }

void solve()
{
	string s;
	cin >> s;

	int cnt[256];
	memset(cnt, 0, sizeof(cnt));

	for(auto ch: s)
		++cnt[ch];

	int nz = 0;

	for(int i = 0; i < 256; ++i)
		nz += !!cnt[i];

	if(nz == 2)
	{
		bool ok = true;

		for(int i = 0; i < 256; ++i)
			ok &= (cnt[i] == 2 || cnt[i] == 0);

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

int main()
{
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 256
def check_area(x,y)
  return 0 if x < 0 || x > $H-1
  return 0 if y < 0 || y > $W-1
  return 1
end

$H,$W = gets.split("\s").map {|s|s.to_i}
field = Array.new($H) { Array.new($W) }

$H.times do |i|
  tmp = gets.chomp
  $W.times do |j|
    s = tmp[j]
    if s=="." then
      s = 0
    end
    field[i][j] = s
  end
end

$H.times do |i|
  $W.times do |j|
    if field[i][j]=="#" then
      (-1..1).each do |x|
        (-1..1).each do |y|
          next if x==0 && y==0
          a = i+x
          b = j+y
          ca = check_area(a,b)
          #puts "check #{a},#{b},#{ca}"
          if ca!=0 && field[a][b]!="#" then
            field[a][b] += ca
          end
        end
      end
    end
  end
end

$H.times do |i|
  $W.times do |j|
    print field[i][j]
  end
  puts ""
end


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

using namespace std;
using ll = long long;

int main() {
    ll H, W;
    cin >> H >> W;
    if (H == 1 || W == 1)
    {
        cout << 1 << endl;
        return 0;
    }
    
    cout << (H * W + 1)/2 << endl;

    return 0;
}

Measured memory_bytes: 3568
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807/2;
const int MOD = 1000000007;
const int N_MAX = 1010;

vector<vector<ll>> dp(N_MAX+1, vector<ll>(N_MAX+1, -1*LLINF));
vector<ll> cake(N_MAX+1,0);

void init_dp() {
  rep(i, N_MAX+1) fill(dp[i].begin(), dp[i].end(), -1*LLINF);
  return;
}

ll dfs(int n, int m) {
  if (dp[n][m]!=-1*LLINF) return dp[n][m];
  if (m==0) return dp[n][m] = 0;
  ll result = 0;
  if (n==m) result = dfs(n-1, m-1)+cake[n];
  else result = max(dfs(n-1, m-1)+cake[n], dfs(n-1, m));
  return dp[n][m] = result;
}

int main() {
  int N, M; cin >> N >> M;
  ll x[N+1], y[N+1], z[N+1];
  for(int i=1; i<=N; i++) cin >> x[i] >> y[i] >> z[i];

  ll result = 0;
  for(int sx=1; sx>=-1; sx-=2) for(int sy=1; sy>=-1; sy-=2) for(int sz=1; sz>=-1; sz-=2) {
    init_dp();
    for(int i=1; i<=N; i++) cake[i] = sx*x[i] + sy*y[i] + sz*z[i];
    dfs(N, M);
    result = max(result, dp[N][M]);
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 8448
#include<stdio.h>
int main()
{
	int masatoy, koutay, hideo, ruio, max = 0, nagase = 0, a[101],tetuo=0,j2,k,j;
	scanf("%d %d %d %d", &masatoy, &koutay, &hideo, &ruio);
	for (int i = 0; i < masatoy; i++) {
		scanf("%d", &a[i]);
	}
	for (int i = 0; i < masatoy; i++) {
		for (int j = i+1; j < masatoy; j++) {
			if (a[i] < a[j]) {
				nagase = a[i];
				a[i] = a[j];
				a[j] = nagase;
			}
		}
	}
	nagase = ruio;
	for (int i = 0; i < masatoy; i++) {
		for ( j = 0; j < i; j++) {
			nagase += a[j];
			j2 = j;
		}
		tetuo = hideo*j + koutay;
		nagase = nagase / tetuo;
		if (nagase > max) {
			max = nagase;
		}
		nagase = ruio;
	}
	printf("%d\n", max);
	return 0;
}

Measured memory_bytes: 2732
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    int n;
    cin>>n;
    map<ll,ll> m;
    rep(i,n){
        ll a;
        cin>>a;
        m[a]++;
    }

    vector<pair<ll,ll>> v;
    for(auto e : m){
        //cout<<e.first<<" "<<e.second<<endl;
        v.push_back({e.first,e.second});
    }
    reverse(all(v));

    bool ok=false;
    ll ans=1;
    rep(i,v.size()){
        if(ok){
            if(v[i].second>=2){
                ans*=v[i].first;
                cout<<ans<<endl;
                return 0;
            }
        }
        else{
            if(v[i].second>=4){
                ans=v[i].first*v[i].first;
                cout<<ans<<endl;
                return 0;
            }
            if(v[i].second>=2){
                ans*=v[i].first;
                ok=true;
            }
        }
    }

    cout<<0<<endl;
}


Measured memory_bytes: 11404
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define F first 
#define S second 
#define MAX 10000003  

ll prime[MAX]; 
map<ll, ll> max_map; 

ll power(ll a, ll n) 
{ 
	if (n == 0) 
		return 1; 
	ll p = power(a, n / 2) % mod; 
	p = (p * p) % mod; 
	if (n & 1) 
		p = (p * a) % mod; 
	return p; 
} 
void sieve() 
{ 
	prime[0] = prime[1] = 1; 
	for (ll i = 2; i <= MAX; i++) { 
		if (prime[i] == 0) { 
			for (ll j = i * 2; j < MAX; j += i) { 
				if (prime[j] == 0) { 
					prime[j] = i; 
				} 
			} 
			prime[i] = i; 
		} 
	} 
} 

ll fun(const ll* ar, ll n) 
{ 

	for (ll i = 0; i < n; i++) { 
		ll num = ar[i]; 
		map<ll, ll> temp;  
		while (num > 1) { 
			ll factor = prime[num]; 
			temp[factor]++; 
			num /= factor; 
		} 
	map<ll,ll> ::iterator it;
		for (it=temp.begin();it!=temp.end();it++) {  
			max_map[it->first] = max(max_map[it->first], it->second); 
		} 
	} 

	ll ans = 1; 
	map<ll,ll> ::iterator it;
	for (it=max_map.begin();it!=max_map.end();it++) { 
		ans = (ans * power(it->F, it->S)) % mod; 
	} 
	return ans; 
} 

int main() {
    sieve();
	ll n,i,a[200005],g,ans=0,inv;
    cin>>n;
    for(i=0;i<n;i++) {
    	cin>>a[i];
	}
	g=fun(a,n);
	for(i=0;i<n;i++) {
		inv=power(a[i],mod-2);
		ans=(ans+(g*inv)%mod)%mod;
	}
	cout<<ans;
}

Measured memory_bytes: 79104
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define REP(i, n) for(int i = 0; i < n; ++i)
using namespace std;
using LLONG = long long;
const LLONG MOD = 998244353;

int counts[200001];

// O(|n|)
const int Popcount(const string& n)
{
	int cnt = 0;
	for (const char ch : n)
	{
		if (ch == '1') ++cnt;
	}
	return cnt;
}

int main()
{
	// 予め　X (mod Popcount(X) ± 1) と 2^i (mod Popcount(X) ± 1) を計算しておく
	// 各々 O(N) で計算可能で，初回の f(n) 計算はこの事前計算によって完了
	// ２回目以降の f(n) 計算は n = f(X) ~ log(X) ~ N 程度に桁が落ちているので，
	// int型で n を保持しシミュレーションしていくことで O(1) 程度で高速に計算可能
	int N; string X; cin >> N >> X;
	int popX = Popcount(X);
	if (popX == 0) { REP(i, N) cout << 1 << endl; return 0; }
	
	vector<int> mods = { popX + 1, popX - 1 };

	// a[i][k] = { 2^i (mod Popcount(X) + 1), 2^i (mod Popcount(X) - 1) }
	vector<vector<int>> a(N, vector<int>(2, 0));

	// b[k] = { X (mod Popcount(X) + 1), X(mod Popcount(X) - 1) }
	vector<int> b(2, 0);

	for (int k = 0; k < 2; ++k)
	{
		if (mods[k] == 0) continue;

		a[0][k] = 1 % mods[k];
		b[k] = static_cast<int>(X[N - 1] - '0') % mods[k];

		for(int i = 1; i < N; ++i)
		{
			// 2^i mod Popcount(X)±1 については，
			// 2^(i-1) を２倍していくことで桁溢れせず計算可能
			a[i][k] = (2 * a[i - 1][k]) % mods[k];

			// X mod Popcount(X)±1 については，
			// 1が立っている桁（＝2^iを含む）について，
			// 2^i mod Popcount(X)±1 (=a[i][k]) を足していけばよい
			if (X[N - 1 - i] == '1')
			{
				b[k] += a[i][k];
				b[k] %= mods[k];
			}
		}
	}

	vector<int> ans(N);
	REP(i, N)
	{
		// mod Popcount(X) + 1 か mod Popcount(X) - 1 になるか判定
		// i桁目が０ならば，１に置換するので mod Popcount(X) + 1 となる
		int k = X[i] == '0' ? 0 : 1;
		
		// 置換した結果，全て０になるなら答えは０回
		if (mods[k] == 0)
		{
			ans[i] = 0;
			continue;
		}

		// 置換後の n = f(X) を計算
		// k = 0 （０->１に置換）のとき，X に 2^(N-1-i) を加える
		int n = k == 0 ? b[k] + a[N - 1 - i][k] : b[k] - a[N - 1 - i][k];
		if (n < 0) n += mods[k];
		n %= mods[k];

		// n が０になるまで繰り返す
		// n ~ log(X) となるので，int型で計算可能
		ans[i] = 1;
		while (n > 0)
		{
			int popcount = 0, digit = 0;
			while (n >= (1 << digit))
			{
				if (n & (1 << digit)) ++popcount;
				++digit;
			}
			n %= popcount;
			++ans[i];
		}
	}

	REP(i, N)
	{
		cout << ans[i] << endl;
	}
}


Measured memory_bytes: 15204
#include <iostream>

using namespace std;

int main() {
    int n,c=0;
    cin>>n;
    int a[n];
    for(int i=0;i<n;++i)
    cin>>a[i];
    for(int i=0;i<n;++i)
    if((i+1)%2 && a[i]%2)
    ++c;
    cout<<c;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#pragma GCC optimize ("O3,unroll-loops")
#define f first
#define s second
#define ri register int
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;
#define MOD 1000000007
#define mod(a) (a) < MOD ? (a) : (a) - MOD 
int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int h, w, **paths;
	char **grid;
	cin >> h >> w;
	grid = new char*[h];
	paths = new int*[h + 1];
	for(ri k = 0; k < h; ++k) {
		grid[k] = new char[w + 1];
		cin >> grid[k];
	}
	for(ri k = 0; k <= h; ++k) {
		paths[k] = new int[w + 1];
		for(ri i = 0; i <= w; ++i)
			paths[k][i] = 0;
	}
	paths[h - 1][w] = 1;
	for(ri k = h - 1; k >= 0; --k) {
		for(ri i = w - 1; i >= 0; --i) {
			if(grid[k][i] == '#') continue;
			paths[k][i] = mod(paths[k + 1][i] + paths[k][i + 1]);
		}
	}
	cout << paths[0][0] << '\n';
    return 0;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
    using namespace std;
    #define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
     
    int main() {FIN
    	
      	int h, w, n;
        cin >> h;
        cin >> w;
        cin >> n;
    	h = max(h, w);
        cout << (n / h) + (n % h > 0 ? 1 : 0) << "\n";
    	return 0;
    }

Measured memory_bytes: 256
n,m,X,Y=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
xx=max(x)
yy=min(y)
t1=max(X,xx)
t2=min(Y,yy)
if t1<t2:
    print("No War")
else:
    print("War")

Measured memory_bytes: 9124
#include <iostream>
#define MAX 100
using namespace std;
int main() {
    int h = 0;
    int w = 0;
    char pic[MAX][MAX];
    cin >> h >> w;

    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> pic[i][j];
        }
    }

    //一番↑
    for (int k = 0; k < w+2; ++k) {
        putchar('#');
    }
    printf("\n");
    for (int l = 0; l < h; ++l) {
        for (int i = 0; i < w+2; ++i) {

            if (i == 0 || i == w+1){
                putchar('#');
            } else{
                cout << pic[l][i -1];
            }
        }
        printf("\n");
    }

    for (int k = 0; k < w+2; ++k) {
        putchar('#');
    }

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
using Pair = System.Tuple<int, int>;
using Edge = System.Tuple<int, int, long>;
//using Debug;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        Solve();
        //WriteLine(Solve());
    }
    static void Solve()
    {
        var num = Input.num;
        var adj = Enumerable.Repeat(0, num).Select(_ => new List<int>()).ToArray();
        for(var i = 0; i < num - 1; i++)
        {
            var inp = Input.ar;
            adj[inp[0] - 1].Add(inp[1] - 1);
            adj[inp[1] - 1].Add(inp[0] - 1);
        }
        var st = new int[num];
        st[0] = 1;
        st[num - 1] = 2;
        var qu = new Queue<int>();
        qu.Enqueue(0);
        qu.Enqueue(num - 1);
        while (qu.Count != 0)
        {
            var p = qu.Dequeue();
            foreach (var ad in adj[p])
                if (st[ad] == 0)
                {
                    st[ad] = st[p];
                    qu.Enqueue(ad);
                }
        }
        WriteLine(st.Count(b => b == 1) > st.Count(b => b == 2) ? "Fennec" : "Snuke");
    }
}

public class Input
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public static char[][] gred(int h) 
        => Enumerable.Repeat(0, h).Select(v => read.ToCharArray()).ToArray();
    public static int[][] ar2D(int num)
        => Enumerable.Repeat(0, num).Select(v => ar).ToArray();
    public static long[][] arL2D(int num)
        => Enumerable.Repeat(0, num).Select(v => arL).ToArray();
    public const long Inf = (long)1e18;
    public const double eps = 1e-6;
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}


Measured memory_bytes: 27480
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAX_N=100005;
LL a[MAX_N],n,k;
int main()
{
	cin>>n>>k;
	for(int i=0;i<n;i++)cin>>a[i];
	LL x=0;
	for(int i=62;i>=0;i--)
	{
		LL cnt=0;
		for(int j=0;j<n;j++)cnt+=(bool)(a[j]&(1LL<<i));
		if(2*cnt<n && (x|(1LL<<i))<=k)x|=1LL<<i;
	}
	LL res=0;
	for(int i=0;i<n;i++)res+=x^a[i];
	cout<<res<<endl;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(void)
{
    double a, b, c;
    double d, e, f;
    double x, y;

    while (scanf("%lf %lf %lf %lf %lf %lf", &a, &b, &c, &d, &e, &f) != EOF) {
        x = (c * e - b * f) / (a * e - b * d);
        y = (c * d - a * f) / (b * d - a * e);
        if (x == -0) {
            x = 0;
        }
        if ( y == -0) {
            y = 0;
        }
        printf("%.3f %.3f\n", x, y);
    }

    return 0;
}

Measured memory_bytes: 652
abs = $stdin.read.lines.map(&:chomp).tap{|s| s.shift}.map{|l| l.split(" ").map(&:to_i)}
sorted = abs.sort_by {|a,b| b}
t = 0
sorted.each do |a,b|
  t += a
  if t > b
    puts "No"
    exit
  end
end

puts "Yes"


Measured memory_bytes: 56312
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<cctype>
#define SG getchar()
using namespace std;
signed main()
{
	puts((((!(SG-'Y'))&&(!(SG-'A'))&&(!(SG-'K'))&&(!(SG-'I')))?("Yes"):("No")));
	return 0;
}

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

typedef long long ll;
#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007

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

    cout<<min(b,c)<<" ";
    if(a-max(b,c)>min(b,c)){
        cout<<0<<endl;
    }
    else {
        cout<<min(b,c)-(a-max(b,c))<<endl;
    }
}


Measured memory_bytes: 256
x,y=sorted(map(int,input().split()));z=x+y
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

print((z%3<1)*cmb(z//3,(2*x-y)//3,10**9+7))

Measured memory_bytes: 127624
n,l = map(int,input().split())

taist = [0] * n
abs_taist = [0] * n
for ii in range(n):
    taist[ii] = (ii + 1) + l - 1
    abs_taist[ii] = abs(taist[ii])

index = abs_taist.index(min(abs_taist))
taist.remove(taist[index])
print(sum(taist))


Measured memory_bytes: 3060
import java.util.*

class Graph constructor(val graph: Array<MutableList<Int>>) {
    private val dp = IntArray(100000) { -1 }

    fun rec(v: Int): Int {
        if (dp[v] != -1) return dp[v]

        var res = 0
        graph[v].forEach {
            res = Math.max(res, rec(it) + 1)
        }
        dp[v] = res
        return res
    }

}


fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(' ').map { it.toInt() }

    val graph: Array<MutableList<Int>> = Array(n) { ArrayList<Int>() }
    repeat(m) {
        val (x, y) = readLine()!!.split(' ').map { it.toInt() }
        graph[x - 1].add(y - 1)
    }

    val g = Graph(graph)
    var res = 0
    (0 until n).forEach {
        res = Math.max(res, g.rec(it))
    }
    println(res)
}


Measured memory_bytes: 69700
N=int(input())
S=input()
if N%2==1:
  print('No')
else:
  count=0
  for i in range(0,N//2):
    if S[i]==S[i+N//2]:
      count+=1
  if count==N//2:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 3060
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
constexpr ll MOD = 1000003;

// a^b O(log b)
template <typename T>
T mypow(T a, T b)
{
    if (b == 0)
        return 1;
    T tmp = mypow(a, b / 2);
    if (b % 2)
        return (((tmp * tmp) % MOD) * a) % MOD;
    else
        return (tmp * tmp) % MOD;
}

struct RangeProductQuery
{
    using type = ll;
    static type id() { return 1; }
    static type op(const type &l, const type &r) { return l * r % MOD; }
};

template <typename M>
class SegmentTree
{
    using T = typename M::type;
    int n;
    std::vector<T> node;

  public:
    // v を基に初期化
    SegmentTree(const std::vector<T> &v)
    {
        // n は v.size() 以上の最小の2冪
        n = 1;
        while (n < int(v.size()))
            n *= 2;
        node.resize(2 * n, M::id());

        // i の子 -> 2*i+1, 2*i+2 , 親 -> (i-1)/2
        for (int i = 0; i < int(v.size()); i++)
            node[i + n] = v[i];
        for (int i = n - 1; i >= 0; i--)
            node[i] = M::op(node[2 * i], node[2 * i + 1]);
    }
    // Monoid::id 初期化
    SegmentTree(int _n)
    {
        // n は v.size() 以上の最小の2冪
        n = 1;
        while (n < _n)
            n *= 2;
        node.resize(2 * n, M::id());
    }
    // x 番目を val に更新
    void update(int x, T val)
    {
        x += n;
        node[x] = val;
        while (x >>= 1)
        {
            node[x] = M::op(node[2 * x], node[2 * x + 1]);
        }
    }
    // v[x] を M::op(v[x], val) に更新
    void operation(int x, T val)
    {
        x += n;
        node[x] = M::op(node[x], val);
        while (x >>= 1)
        {
            node[x] = M::op(node[2 * x], node[2 * x + 1]);
        }
    }
    // [a, b) の op
    T query(int l, int r)
    {
        l += n;
        r += n;
        T retl = M::id(), retr = M::id();
        while (l < r)
        {
            if (l & 1)
                retl = M::op(retl, node[l++]);
            if (r & 1)
                retr = M::op(node[--r], retr);
            l >>= 1;
            r >>= 1;
        }
        return M::op(retl, retr);
    }
};

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

    int q;
    cin >> q;
    vector<ll> v(2222222);
    for (int i = 0; i < 2222222; i++)
        v[i] = i % MOD;
    SegmentTree<RangeProductQuery> dst(v);
    while (q--)
    {
        // x, x+d, ..., ... x+(n-1)d の積mod
        ll x, d, n;
        cin >> x >> d >> n;
        if (d == 0)
        {
            cout << mypow(x, n) << endl;
            continue;
        }
        if (n >= MOD)
        {
            cout << 0 << endl;
            continue;
        }
        ll st = x * mypow(d, MOD - 2) % MOD, gt = st + n - 1; // gt < 2 * MOD
        ll ret = mypow(d, n) * dst.query(st, gt + 1) % MOD;
        cout << ret << endl;
    }
}


Measured memory_bytes: 83840
// Hail god Yato
 
#include <bits/stdc++.h> 
using namespace std;
 
#define add(x) accumulate(x)
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end() 
#define rep(i, a, b) for (int i=a; i<(b); i++)
#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
const ll mod = 1000000007;
const ll INF = 1e18;
const ll MAX = 100001;
//
//
                void solve(){
                        ll x,n;
                        cin>>x>>n;
                        if(x*500>=n)
                                cout<<"Yes";
                        else
                                cout<<"No";
                }
                int main(){
                        hs;
                        ll t;
                        t=1;
                        // cin>>t;
                        for (int i=1; i<=t; i++){
                                // cout<<"Case "<<i<<": ";
                                solve();
                         }
        return 0; 
}         
 

Measured memory_bytes: 764
import collections
n = int(input())
s = [input() for _ in range(n)]
ss = collections.Counter(s)
# print(ss)

n_ma = max(ss.values())
ans = []
for k in ss.keys():
    if ss[k] == n_ma:
        ans.append(k)
ans = sorted(ans)
for a in ans:
    print(a)


Measured memory_bytes: 101968
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

int main()
{
	for(int n,q;cin>>n>>q;){
		vi cs(n);
		rep(i,n) cin>>cs[i];
		sort(all(cs));
		rep(_,q){
			int m; cin>>m;
			int res=0;
			for(int i=m;i<3e5;i+=m){
				int j=lower_bound(all(cs),i)-cs.begin();
				if(j-1>=0) res=max(res,cs[j-1]%m);
			}
			cout<<res<<endl;
		}
		
	}
	
	return 0;
}

Measured memory_bytes: 2316
#include<bits/stdc++.h>
using namespace std;
int main(){
    string str;
    cin>>str;
    string front,back;
    int q;
    cin>>q;
    vector<int>t(q);
    vector<int>f(q);
    vector<char>c(q);
    bool rev=false;
    for(int i=0;i<q;i++){
        cin>>t[i];
        if(t[i]==2){
            cin>>f[i]>>c[i];
            if(rev==false){
                if(f[i]==1)front.push_back(c[i]);
                else back.push_back(c[i]);
            }
            if(rev==true){
                if(f[i]==1)back.push_back(c[i]);
                else front.push_back(c[i]);
            }
        }
        if(t[i]==1){
            if(rev)rev=false;
            else rev=true;
        }
    }
    int fr=front.size(),st=str.size(),ba=back.size();
    if(rev){
        for(int i=ba-1;i>=0;i--)cout<<back[i];
        for(int i=st-1;i>=0;i--)cout<<str[i];
        cout<<front<<endl;
    }
    else{
        for(int i=fr-1;i>=0;i--)cout<<front[i];
        cout<<str<<back<<endl;
    }
    return 0;
}

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

namespace std {
template <>
struct hash<pair<int, int>> {
  size_t operator()(const pair<int, int>& p) const {
    return hash<int>()(p.first) + hash<int>()(p.second);
  }
};
}

using namespace std;
class UnionFind {
 public:
  explicit UnionFind(int n) : vec(n + 1), rank(n + 1) {
    for (int i = 0; i <= n; ++i) {
      vec[i] = i;
      rank[i] = 0;
    }
  }

  int find(int x) const {
    if (x == vec[x]) return x;
    return vec[x] = find(vec[x]);
  }

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

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

  void dump() const {
    for (size_t i = 1; i < vec.size(); ++i) {
      if (1 < i) cout << ", ";
      cout << vec[i];
    }
    cout << "\n";
  }

  mutable vector<int> vec;
  mutable vector<int> rank;
};

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

  int n, k, l;
  cin >> n >> k >> l;
  UnionFind roads(n), rails(n);
  for (int i = 0; i < k; ++i) {
    int p, q;
    cin >> p >> q;
    p--;
    q--;
    roads.unite(p, q);
  }

  for (int i = 0; i < l; ++i) {
    int r, s;
    cin >> r >> s;
    r--;
    s--;
    rails.unite(r, s);
  }

  unordered_map<pair<int, int>, int> connects;
  for (int i = 0; i < n; ++i) {
    auto p = make_pair(roads.find(i), rails.find(i));
    connects[p]++;
  }
  for (int i = 0; i < n; ++i) {
    if (0 < i) cout << " ";
    cout << connects[make_pair(roads.find(i), rails.find(i))];
  }
  cout << "\n";
}


Measured memory_bytes: 14280
#/*
    AUTHOR:shivam51
    IIESTS
*/
  #include<bits/stdc++.h>
  using namespace std;
  //
  #define add accumulate
  #define ll long long int
  #define ff first
  #define ss second
  #define pb push_back
  #define mp make_pair
  #define vll vector<ll>
  #define lb lower_bound
  #define ub upper_bound
  #define pll pair<ll,ll>
  #define vpll vector<pll>
  #define all(v) v.begin(), v.end()
  #define rep(i,k,n) for(int i=k;i<n;i++)
  #define hs ios_base::sync_with_stdio(false);cin.tie(NULL);
  const ll mod=1e9+7;
  const ll MAX=401;
  //
  //
  	ll solve(){
  		ll n;
  		cin>>n;
  		vll a(n+1),b(n);
  		rep(i,0,n+1)
  			cin>>a[i];
  		rep(i,0,n)
  			cin>>b[i];
  		ll ans=0;
  		rep(i,0,n){
  			ll k=min(a[i],b[i]);
  			a[i]-=k;
  			b[i]-=k;
  			ans+=k;
  			// cout<<k;
  			ans+=min(a[i+1],b[i]);
  			a[i+1]-=min(a[i+1],b[i]);
  		}
  		cout<<ans;
  	}
	int main(){ 
		hs;
		ll t;
		// cin>>t;
		t=1;
		while(t--)
			solve();
    return 0; 
} 

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

int main(){
	string A, B;
	cin >> A >> B;
	if (A.size()>B.size()) {
		cout << "GREATER" << endl;
		return 0;
	}
	if (A.size()<B.size()) {
		cout << "LESS" << endl;
		return 0;
	}
	rep(i,A.size()){
		if ((A[i]-'0') > (B[i]-'0')) {
			cout << "GREATER" << endl;
			return 0;
		}
		if ((A[i]-'0') < (B[i]-'0')) {
			cout << "LESS" << endl;
			return 0;
		}
	}
	cout << "EQUAL" << endl;
	return 0;
}


Measured memory_bytes: 3604
import numpy as np
def eratosthenes(m):
    if m<2:
        return []
    dp=[True]*(m+1)
    sosu=[2]
    like=[0]*(m+1)#累積和
    like[3]=1
    for x in range(3,m+1,2):
        if dp[x]:
            sosu.append(x)
            if dp[(x+1)//2]==True and (x+1)//2%2==1:
                like[x]+=1
        for j in range(2*x, m+1, x):
            dp[j]=False
    return like

like=eratosthenes(10**5+1)
c = np.array(like).cumsum()
q=int(input())
for i in range(q):
    l,r=map(int,input().split())
    ans=c[r]-c[l-1]
    print(ans)

Measured memory_bytes: 29028
#include <iostream>

#include <algorithm>


constexpr int MAX=3001;


int n;
int s,t;
int A[MAX],B[MAX];

int dp[MAX][MAX],dp1[MAX+1][MAX];

int main(){
	std::cin>>n>>t>>s;
	for(int i=1;i<=n;++i)
		std::cin>>A[i]>>B[i];
	for(int i=1;i<=n;++i){
		for(int j=1;j<=s;++j){
			dp[i][j]=dp[i-1][j];
			if(j>=B[i])
				dp[i][j]=std::max(dp[i][j],dp[i-1][j-B[i]]+A[i]);
		}
	}
	for(int i=n;i>0;--i){
		for(int j=1;j<=t-s;++j){
			dp1[i][j]=dp1[i+1][j];
			if(j>=B[i])
				dp1[i][j]=std::max(dp1[i][j],dp1[i+1][j-B[i]]+A[i]);
		}
	}
	int ans=0;
	for(int i=0;i<=n;++i)
		ans=std::max(ans,dp[i][s]+dp1[i+1][t-s]);
	std::cout<<ans<<std::endl;
	return 0;
}

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

#define LL long long
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;

int main() {
    LL Q, H, S, D, N;
    cin >> Q >> H >> S >> D;
    cin >> N;
    N *= 4;

    LL val[] = {Q, H, S, D};
    LL vol[] = {1, 2, 4, 8};
    LL cost = 0;

    REP(x, 4) {
        int mi = -1;
        LL m = LINF;
        REP(i, 4) {
            if(val[i]*pow(2, 3 - i) < m*pow(2, 3 - mi)) {
                m = val[i];
                mi = i;
            }
        }
        cost += (N/vol[mi])*val[mi];
        N -= (N/vol[mi])*vol[mi];
        val[mi] = LINF;
    }
    cout << cost << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <string.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;


int main()
{
//回答が整数の場合
string ans;
//整数値の入力
int y,m,d;
char st,stt;
cin >> y>> st>> m>> stt>> d;
//行列の入力
if(m>4){ans="TBD";}
else{ans="Heisei";}
//回答
cout << ans << endl;
return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <algorithm>
const int mod=1e9+7;
using LL=long long;
using std::cout;using std::endl;using std::cin;
using std::vector;using std::string;using std::set;using std::multiset;
using std::pair;using std::map;
using std::min;using std::max;
using std::make_pair;
std::ostream& operator<<(std::ostream& os,std::map<int,int>& obj){for(std::map<int,int>::iterator itr=obj.begin();itr!=obj.end();itr++){os<<itr->first<<"^"<<itr->second<<" ";}return os;}
std::ostream& operator<<(std::ostream& os,std::vector<std::map<int,int>>& obj){for(auto itr=obj.begin();itr!=obj.end();itr++){os<<*itr<<std::endl;}return os;}
std::ostream& operator<<(std::ostream& os,std::vector<int>& obj){for(auto itr=obj.begin();itr!=obj.end();itr++){os<<*itr<<" ";}return os;}

namespace ndifix{

}

int main(){
  string s;cin>>s;
  int cnt=0;
  for(int i=0;i<s.size();i++)if(s[i]=='x')cnt++;
  if(cnt<=7)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <unordered_set>

using namespace std;

int main(){
	int n;
	cin >> n;
	unordered_set<int> s;
	for(int i=0; i<n; ++i){
		int d;
		cin >> d;
		s.insert(d);
	}
	cout << s.size() << "\n";
	return 0;
}


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

typedef long long LL;
const int M=1005;
const int INF=0x3f3f3f3f;

struct Node
{
	int a,b,c;
	void read()
	{
		scanf("%d%d%d",&a,&b,&c);
	}
}r[M],c[M];

int x[M],y[M];
int nx,ny;
int findx(int v)
{
	return lower_bound(x,x+nx,v)-x;
}
int findy(int v)
{
	return lower_bound(y,y+ny,v)-y;
}

int vis[M][M];
int block[M][M][4];
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
//         L R U D

LL ans;

int qx[M*M];
int qy[M*M];

void bfs(int xx,int yy)
{
	int t=0;
	qx[t]=xx; qy[t]=yy; t++;
	vis[xx][yy]=1;
	for(int ii=0;ii<t;ii++)
	{
		xx=qx[ii]; yy=qy[ii];
		ans+=1LL*(x[xx+1]-x[xx])*(y[yy+1]-y[yy]);
		for(int i=0;i<4;i++)
		{
			if(block[xx][yy][i]) continue;
			int x=xx+dx[i],y=yy+dy[i];
			if(x<=0||nx-1<=x||y<=0||ny-1<=y)
			{
				ans=-1;
				return;
			}
			if(vis[x][y]) continue;
			vis[x][y]=1;
			qx[t]=x; qy[t]=y; t++;
		}
	}
}

int main()
{
	//freopen("F.in","r",stdin);
	int n,m; scanf("%d%d",&n,&m);
	nx=ny=0;
	for(int i=0;i<n;i++)
	{
		r[i].read();
		//x[nx++]=r[i].a;
		//x[nx++]=r[i].b;
		y[ny++]=r[i].c;
	}
	for(int i=0;i<m;i++)
	{
		c[i].read();
		x[nx++]=c[i].a;
		//y[ny++]=c[i].b;
		//y[ny++]=c[i].c;
	}
	x[nx++]=-INF; x[nx++]=INF;
	y[ny++]=-INF; y[ny++]=INF;
	sort(x,x+nx); nx=unique(x,x+nx)-x;
	sort(y,y+ny); ny=unique(y,y+ny)-y;
	// cout<<nx<<" "<<ny<<endl;
	// for(int i=0;i<nx;i++)
	// 	cout<<x[i]<<" ";
	// cout<<endl;
	// for(int i=0;i<ny;i++)
	// 	cout<<y[i]<<" ";
	// cout<<endl;
	for(int i=0;i<n;i++)
	{
		int p=findy(r[i].c);
		//cout<<p<<" "<<findx(r[i].a)<<" "<<findx(r[i].b)<<endl;
		int up=findx(r[i].b);
		if(r[i].b!=x[up]) up--;
		for(int j=findx(r[i].a);j<up;j++)
			block[j][p-1][1]=block[j][p][0]=1;
	}
	for(int i=0;i<m;i++)
	{
		int p=findx(c[i].a);
		int up=findy(c[i].c);
		if(c[i].c!=y[up]) up--;
		for(int j=findy(c[i].b);j<up;j++)
			block[p-1][j][3]=block[p][j][2]=1;
	}
	bfs(findx(0)-1,findy(0)-1);
	if(ans==-1) printf("INF\n");
	else printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 31192
R,G,B,N= map(int,input().split())

cnt = 0
for k in reversed(range(N // R + 1)):
  if N - k * R == 0:
    cnt += 1
    continue
  N1 = N - k * R
  for i in reversed(range(N1 // G + 1)):
    if N1 - i * G == 0:
      cnt += 1
      continue
    N2 = N1 - i * G
    if N2 % B == 0:
      cnt += 1
    else:
      continue
print(cnt)

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

int main() {
    
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  int left = A+B;
  int right = C+D;
  
  
  if(left > right){
      cout << "Left" << endl;
  }
  else if(left == right){
      cout << "Balanced" << endl;
  }
  else{
      cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#import math
#import itertools
#import numpy as np
#from collections import deque
# sys.setrecursionlimit(10 ** 6)
#mod = 10 ** 9 + 7
#INF = 10 ** 9
#PI = 3.14159265358979323846

INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))

def do():
    l,r=INTM()
    mods=[]
    for i in range(l,min(l+3000,r+1)):
        mods.append(i%2019)
    
    ans=2018
    ml=len(mods)
    for i in range(ml-1):
        for j in range(i+1,ml):
            ans=min(ans,(mods[i]*mods[j])%2019)

    print(ans)


if __name__=='__main__':
    do()

Measured memory_bytes: 9116
#include <iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	char ids[n];
	int max=0;
	int x=0;
	for(int i=0;i<n;i++){
		cin>>ids[n];
		if(ids[n]=='I')x+=1;
		else x-=1;
		if(x>max)max=x;
	}
	cout<<max;
}

Measured memory_bytes: 256
def main():
	# a = int(input())
	# n,m = map(int,input().split())
	#1行R列
	# a = list(map(int,input().split()))
	#R行1列
	# l = [str(input()) for i in range(n)]
	#R行C列
	a = [list(map(int,input().split())) for x in range(3)]
	n = int(input())
	b = [int(input()) for i in range(n)]
	# print(' '.join())

	bingo = [[0,0,0],[0,0,0],[0,0,0]]

	for x in range(3):
		for y in range(n):
			if a[x].count(b[y]) > 0:
				bingo[x][a[x].index(b[y])] = 1
	
	bingo_check = [0,0,0]
	ans  = 0
	#斜め揃ってる時
	if bingo[0][0] == bingo[1][1] == bingo[2][2] == 1 or bingo[0][2] == bingo[1][1] == bingo[2][0] == 1:
		ans = 1
	for i in range(3):
		#よこ揃ってる時
		if bingo[i][0] == bingo[i][1] == bingo[i][2] == 1:
			ans = 1
	#たて揃ってる時
	for x in range(3):
		if bingo[0][x] == bingo[1][x] == bingo[2][x] == 1:
			ans = 1
	if ans == 1:
		print("Yes")
	else:
		print("No")


if __name__ == '__main__':
	main()

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
bool zs(int n)
{
	for(int i=2;i*i<=n;++i)
		if(n%i==0)
			return false;
	return true;
}
bool hw(int n)
{
	int m=0,k=n;
	while(k!=0)
	{
		m=m*10+k%10;
		k/=10;
	}
	if(m==n)
		return true;
	return false;
}
int main()
{
	int a,b;
	cin>>a>>b;
	cout<<ceil((a+b)/2.0);
	return 0;
}

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

int main(void){
  int n;
  while(cin>>n){
    long long res = 0;
    for(int i = 0 ; i < 600 ; i += n){
      res += n * i * i;
    }
    cout<<res<<endl;
  }
  return 0;
}

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

bool ans(int x,int y){
    return x>=2*y-1;
}
int main(void){
    // Your code here!
    int x,a[5]={0};
    for(int i=0; i< 6; i++){
        cin >> x;
        a[x]++;
    }
    if((a[1]*a[2]*a[3]*a[4])%2==0) printf("YES\n");
    else printf("NO\n");
    //cout << a[1]*a[2]*a[3]*a[4];
}


Measured memory_bytes: 256
#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<fstream>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()

using namespace std;

const int MAX = 1010000;
const int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;

//typedef pair<int, int> P;

int dp[202020];
int nex[202020][27];
map<char, int>mp;
signed main() {
	REP(i, 26) {
		mp['a' + i] = i;
	}
	string S; cin >> S;
	m0(dp);
	int N = S.size();
	REP(i, 26) {
		nex[N][i] = N + 1;
	}

	for (int i = N-1; i>=0;i--) {
		REP(j, 26) {
			nex[i][j] = nex[i + 1][j];
		}
		nex[i][mp[S[i]]] = i + 1;
	}
	//print(N); REP(i, N)print(nex[0][i]);
	dp[N] = 1;
	for (int i = N - 1; i >= 0; i--) {
		int mn = INF;
		REP(j, 26) {
			mn = min(mn, dp[nex[i][j]]);
		}
		dp[i] = mn + 1;
	}

	int M = dp[0];
	string ans;
	int pos = 0;
	while (M > 0) {
		REP(j, 26) {
			if (dp[nex[pos][j]] == M - 1) {
				ans += 'a' + j;
				pos = nex[pos][j];
				M--;
				break;
			}
		}
	}
	print(ans);
}


Measured memory_bytes: 44804
<?php
$stdin = trim(fgets(STDIN));
$stack = array();
// 配列のキーと値を反転
$operator = array_flip(explode(',', '+,-,*,/'));

foreach (explode(' ', $stdin) as $str) {
    if (!isset($operator[$str])) {
        $stack[] = (int)$str;
        continue;
    }
    // 配列の末尾から要素を取り除く
    $b = array_pop($stack);
    $a = array_pop($stack);
    
    switch ($str) {
        case '+':
            $result = $a + $b;
            break;
        case '-':
            $result = $a - $b;
            break;
        case '*':
            $result = $a * $b;
            break;
        case '/':
            $result = $a / $b;
            break;
    }
    $stack[] = $result;
}
 
 // 先頭を取り除く
echo array_shift($stack), PHP_EOL;


Measured memory_bytes: 9324
#include<iostream>
#include<queue>
#include<vector>
#include<utility>
#include<functional>
#include<tuple>

//#define DEBUGMODE
#define  DEBUG
#ifdef DEBUGMODE
#define DEBUG cout << "hage" << endl
#endif

using namespace std;
typedef tuple<int, int, pair<int, int> > T;

int dp[100][100];
bool used[100][100];
const int INF = 1145141919;

int main(){
	int n, m; cin >> n >> m;
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < n; ++j){	
			dp[i][j] = INF;
		}
		dp[i][i] = 0;
	}
	vector<	pair<int, int> > road[n];
	for(int i = 0; i < m; ++i){
		int a, b, c; cin >> a >> b >> c;
		--a; --b;
		road[a].push_back(pair<int, int>(b, c));
		road[b].push_back(pair<int, int>(a, c));
		used[a][b] = used[b][a] = 1;
	}

	
	DEBUG;
	for(int i = 0; i < n; ++i){
		priority_queue<T, vector<T>, greater<T> >q;	//cost, to, road
		q.push(T(0, i, pair<int, int>(i, i)));
		
		while(!q.empty()){
			auto t = q.top(); q.pop();
			if(dp[i][get<1>(t)] < get<0>(t)) continue;
			dp[i][get<1>(t)] = get<0>(t);
			used[get<2>(t).first][get<2>(t).second] = used[get<2>(t).second][get<2>(t).first] = 0;
			for(pair<int, int> u : road[get<1>(t)]){	
				if(dp[i][get<1>(t)] + u.second < dp[i][u.first]){
					q.push(T(dp[i][get<1>(t)] + u.second, u.first, pair<int, int>(get<1>(t), u.first)));
				}
			}
		}
	}

	int ans = 0;
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < n; ++j){
			ans += used[i][j];
		}
	}

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

Measured memory_bytes: 384