akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <stack>
#include <iostream>
#include <set>
typedef long long ll;
using namespace std;
int a[100005],n,k;
int f(ll x)
{
	int j=1;
	for(int i=1;i<=k;i++)
	{
		ll sum=0;
		while(sum+a[j]<=x)
		{
			sum=sum+a[j];
			if(j==n)
			return n;
			j++;
		}
	}
	return j-1;
}
ll ans;
ll solve()
{
	ll mid,left=0,right=1e10;
	int v;
	while(right-left>1)
	{
		mid=(left+right)/2;
		v=f(mid);
		if(v>=n)
		right=mid;
		else left=mid;
	}
	return right;
}
int main()
{
   cin>>n>>k;
   for(int i=1;i<=n;i++)
   {
   	cin>>a[i];
   }
   ans=solve();
  cout<<ans<<"\n";
	return 0;
}



Measured memory_bytes: 3488
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main(void){
    int x; cin >> x;
  ll ans = 0;
  for(ll b = 1; b <= 100; b++){
    ll num = b;
  	for(int p = 2; p <= 10; p++){
    	num *= b;
      	if(num <= x){
        	ans = max(num, ans);
        }
    }
  }
  cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
J=[]
while True:
    sum=int(input())
    if sum==0:
        for k in range(len(J)):
            print(J[k])
        break
    else:
        a=int(input())
        b=int(input())
        c=int(input())
        d=int(input())
        e=int(input())
        f=int(input())
        g=int(input())
        h=int(input())
        i=int(input())
        J.append(sum-a-b-c-d-e-f-g-h-i)



Measured memory_bytes: 5596
#include <bits/stdc++.h>
#define ll long long
#define ui unsigned int
#define ull unsigned long long
#define bug(x) cerr << '\n' << (#x) << " = " << (x) << endl;
#define REP0(i, n) for(int i = 0, _n = (n); i < _n; ++i)
#define REP1(i, n) for(int i = 1, _n = (n); i <= _n; ++i)
#define REPB0(i, n) for(int i = (n) - 1; i >= 0; --i)
#define REPB1(i, n) for(int i = (n); i > 0; --i)
#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define FORB(i, a, b) for(int i = (a), _b = (b); i >= _b; --i)
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define X first
#define Y second

using namespace std;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef pair<double, double> dd;
typedef pair<float, float> ff;

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n;
	cin >> n;
	vector<string> arr(n);
	map<string, int> my;
	REP0(i, n) {
		cin >> arr[i];
		sort(arr[i].begin(), arr[i].end());
		if (my.count(arr[i])) ++my[arr[i]];
		else my[arr[i]] = 1;
	}
	ll sum = 0;
	for (auto &it : my) sum += (ll)(it.Y) * (it.Y - 1) / 2;
	cout << sum;
	return 0;
}

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  string s ;
  cin >> s ;
  deque<char> ans1 , ans2 ;
  
  rep(i,s.size()){
   if( i % 2 == 0){
    ans1.push_back('0');
    ans2.push_back('1');
   }
    else {
      ans1.push_back('1');
      ans2.push_back('0');
    }
  }
  
  int count1 = 0;
  int count2 = 0;
  
  rep(i,s.size()){
    if(s.at(i) != ans1.at(i))
      count1 ++ ;
     if(s.at(i) !=ans2.at(i))
       count2 ++;
  }
  
  cout << min(count1,count2);


}


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

typedef long long ll;
const int N = 2000006;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int n,m;
	cin>>n>>m;
	if(n == m)cout<<"Yes";
	else cout<<"No";
	
	return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define big long long
int main()
{
	//#ifndef ONLINE_JUDGE
	//	freopen("take.in","r",stdin);
	//	freopen("give.out","w",stdout);
	//#endif

	string a;
	cin>>a;
	if(a=="AAA" || a=="BBB") cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
	return 0;

}

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

int a[200010];

int main() {
    int n;
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
    long long ans = 0;
    for(int i = 2; i <= n; i++) {
        if(a[i] < a[i - 1]) {
            ans += (a[i - 1] - a[i]);
            a[i] = a[i - 1];
        }
    }
    printf("%lld\n", ans);

    return 0;
}


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

#define int long long int

int32_t main()
{
 int n;
 cin>>n;
 vector<int> v;
 for(int i=0;i<n;i++)
 {
   int x;
   cin>>x;
   v.push_back(x);
 }
 cout<<*max_element(v.begin(),v.end())-*min_element(v.begin(),v.end())<<endl;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#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 long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

template <class T> void vecout(T V) {
    auto t = V.begin();
    while(t != V.end()) {
        cout << *t++;
        if(t != V.end()) cout << " ";
    }
    cout << endl;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int q, k;
    cin >> q;
    rep(i, q) {
        cin >> k;
        cout << lower_bound(all(a), k) - a.begin() << " "
             << upper_bound(all(a), k) - a.begin() << "\n";
    }
}


Measured memory_bytes: 3364
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline
a = int(input())
b = list(map(int,input().split()))
from collections import defaultdict
d = defaultdict(int)
for i in b:
    d[i]+=1
    d[i-1]+=1
    d[i+1]+=1

ret_v = 0
for v in d.values():
    if v > ret_v:
        ret_v = v
print(ret_v)

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

using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define sz(s) (int)s.size()

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    for (int t = 0; t <= 1000; ++t)
    if ((a * t) % b == c) {
        cout << "YES";
        return 0;
    }
    cout << "NO";
}

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

#define 	pi 				3.1415926536
#define 	mod 			1000000007
#define 	ll  			long long int
#define 	rep(i, a, b) 	for(int i = a ; i < b ; i++)
#define 	repn(i, n) 		for(int i = n - 1 ; i >= 0 ; i--)
#define 	loop(i, a, b)	for(int i = a ; i < b ; i++)
#define 	mod1 			1000003
#define 	hello 			"hello"
#define 	nl 				"\n"
#define 	ws 				" "
#define 	F 				first
#define 	S 				second
#define 	PB 				push_back
#define 	mp				make_pair
#define 	B 				begin()
#define 	E 				end()
#define 	all(v) 			v.begin(), v.end()
#define 	reset(a, val) 	memset(a, val, sizeof(a))
#define 	vi 				vector<int>
#define 	vs 				vector<string>
#define 	print(a) 		for(auto i : a)cout<<i<<" ";cout<<"\n"
#define 	boost 			ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

using namespace std;

//g++ -std=c++14
//fixed<<setprecision(9);
//max_element(mp.begin(), mp.end(), compare)
//greater<int>()


bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); }

bool compare(const pair<string, int>&a, const pair<string, int>&b){ return a.second<b.second; }

void solve()
{
  int n, m, c=0, sum = 0;cin>>n>>m;
  vi a(n);
  rep(i, 0, n){
    cin>>a[i]; sum+= a[i];
  }
  rep(i, 0, n)
  {
    if(a[i]*4*m >= sum )
      c++;
  }
  if(c>=m)
    cout<<"Yes\n";
    else
    {
      cout<<"No\n";
    }
    

}

int main()
{
    boost;
  int t = 1;
  // cin>>t;
  while(t--)
      solve();    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
#include <fstream>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

ll mod(ll a, ll b){
  ll ret=a%b;
  if(ret<0) ret+=b;
  return ret;
}

ll modpow(ll a,ll b,ll c){
  ll res=1;
  while(b>0){
    if(b&1) res=mod(res*a,c);
    a=mod(a*a,c);
    b>>=1;
  }
  return res;
}

int main() {
  ll MOD=1000000007;
  int n;
  cin>>n;
  ll a[n],s[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
    if(i==0) s[i]=a[i];
    else s[i]=mod(s[i-1]+a[i],MOD);
  }
  ll ans=0;
  for(int i=1;i<n;i++){
    ans+=a[i]*s[i-1];
    ans=mod(ans,MOD);
  }
  cout<<ans<<endl;
  return 0;
}


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

template<typename T> using pqueue_inv = std::priority_queue<T, std::vector<T>, std::greater<T> >;
int main() {
	int n = ri();
	int m = ri();
	int s = ri(); // initials
	struct Info {
		int to;
		int cost;
		int time;
	};
	std::vector<Info> hen[n];
	for (int i = 0; i < m; i++) {
		int a = ri() - 1;
		int b = ri() - 1;
		int c = ri();
		int d = ri();
		hen[a].push_back({b, c, d});
		hen[b].push_back({a, c, d});
	}
	int exscore[n], extime[n];
	for (int i = 0; i < n; i++) {
		exscore[i] = ri();
		extime[i] = ri();
	}
	
	// [n][2500]
	int64_t dist[n][2501];
	for (auto &i : dist) for (auto &j : i) j = 1000000000000000000;
	pqueue_inv<std::pair<int64_t, std::pair<int, int> > > que;
	que.push({dist[0][std::min(2500, s)] = 0, {0, std::min(2500, s)}});
	while (que.size()) {
		auto i = que.top();
		que.pop();
		int id = i.second.first;
		int left = i.second.second;
		if (dist[id][left] != i.first) continue;
		auto go = [&] (int new_id, int new_left, int cost) {
			if (dist[new_id][new_left] > i.first + cost)
				que.push({dist[new_id][new_left] = i.first + cost, {new_id, new_left}});
		};
		// top up
		go(id, std::min(2500, left + exscore[id]), extime[id]);
		for (auto j : hen[id]) {
			if (j.cost > left) continue;
			go(j.to, left - j.cost, j.time);
		}
	}
	for (int i = 1; i < n; i++) {
		int64_t res = 1000000000000000000;
		for (int j = 0; j <= 2500; j++) res = std::min(res, dist[i][j]);
		printf("%" PRId64 "\n", res);
	}
	
	return 0;
}


Measured memory_bytes: 6216
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr> () -> T {
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let N: usize = read();
    if N % 2 == 0 {
        println!("{}", N);
    }
    else {
        println!("{}", N*2);
    }
}



Measured memory_bytes: 4352
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define gcd __gcd
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, n) revi(i, 0, n)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数 __builtin_popcount bitの個数

int main() {
  char s, S;
  int y, m, d;
  ci(y, s, m, S, d);
  if(m > 4){
    co("TBD");
  }
  else{
    co("Heisei");
  }
}

Measured memory_bytes: 256
from itertools import accumulate
from math import ceil
 
N = int(input())
A = list(map(int, input().split()))
 
if N == 1:
    print(A[0])
    exit()
 
 
class BinaryIndexedTree:
    def __init__(self, n):
        self.size = n
        self.bit = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.bit[i]
            i -= (i & -i)
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.bit[i] += x
            i += (i & -i)
 
    def reset(self):
        self.bit = [0] * (self.size + 1)
 
 
BIT = BinaryIndexedTree(N)  # Binaryの先頭の分
lo, hi = -1, 10 ** 9 + 1
while hi - lo > 1:
    # Xは中央値候補
    X = (hi + lo) // 2
 
    # X以上なら1、X未満なら-1に変換
    Binary = [(1 if a >= X else -1) for a in A]
 
    # 累積和をとる
    Binary = list(accumulate(Binary))
 
    # BITを初期化
    BIT.reset()
 
    # 転倒数っぽいものを数える
    inversion = 0
    Binary_sorted = {b: i for i, b in enumerate(sorted(Binary), start=1)}
    for j, b in enumerate(Binary):
        inversion += BIT.sum(Binary_sorted[b]) + (b >= 0)
        BIT.add(Binary_sorted[b], 1)
 
    if inversion >= ceil((N * (N + 1) / 2) / 2):
        lo = X
    else:
        hi = X
 
print(lo)

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

constexpr int maxn = 1e5 + 100;

vector<int> vec[maxn] = {};
int n;   
ll stones[maxn] = {}, dyn[maxn] = {};
bool bad = false;

void dfs(const int cur){
    if(vec[cur].empty()){
        dyn[cur] = stones[cur];
        return; }
    for(const auto next : vec[cur]){
        vec[next].erase(find(begin(vec[next]), end(vec[next]), cur));
        dfs(next); }
    vector<ll> v(vec[cur].size());
    transform(begin(vec[cur]), end(vec[cur]),
        begin(v), [](const int x){ return dyn[x]; });

    nth_element(begin(v), end(v)-1, end(v));
    const ll all_except_big = accumulate(begin(v), end(v)-1, 0ll),
        full_sum = all_except_big + v.back();
    const ll linked = full_sum - stones[cur];
    if(linked < 0) bad = true;
    else if(full_sum - 2*linked < 0) bad = true;
    else if(all_except_big >= v.back() && linked > full_sum) bad = true;
    else if(all_except_big  < v.back() && linked > all_except_big) bad = true;
    else dyn[cur] = full_sum-2*linked; }

int main(){
    cin >> n;
    copy_n(istream_iterator<ll>(cin), n, stones);
    for(int i = 0, x, y; i < n-1; ++i){
        cin >> x >> y;
        --x, --y;
        vec[x].push_back(y);
        vec[y].push_back(x); }
    if(n == 2){
        cout << (stones[0] == stones[1] ? "YES" : "NO") << endl;
        return 0; }
    int rad = 0;
    while(vec[rad].size() == 1) ++rad;
    dfs(rad);
    cout << (!bad && dyn[rad] == 0 ? "YES" : "NO") << endl;
    return 0; }


Measured memory_bytes: 15232
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdio.h>

using namespace std;

//typedefリスト
typedef vector<long long int> vint;
typedef vector<vector<long long int>> vvint;
typedef vector<string> vstr;
typedef long long int llint;

llint gcd(llint x, llint y){
	while (y != 0){
		if (x > y){
			llint r = x%y;
			x = y;
			y = r;
		}
		else {
			llint r = y%x;
			y = r;
		}
	}
	return x;
}

int main(void) {
	llint H, W;
	int jur = 0, ans = 0;
	cin >> H >> W;
	vector<vector<char>> s(H, vector<char>(W));
	for (int i = 0; i < H; i++){
		for (int j = 0; j < W; j++){
			cin >> s[i][j];
		}
	}
	for (int i = 0; i < H; i++){
		for (int j = 0; j < W; j++){
			jur = 0;
			if (s[i][j] == '#'){
				if (i - 1 >= 0){
					if (s[i - 1][j] == '#')jur = 1;
				}
				if (i + 1 < H){
					if (s[i + 1][j] == '#')jur = 1;
				}
				if (j - 1 >= 0){
					if (s[i][j - 1] == '#')jur = 1;
				}
				if (j + 1 < W){
					if (s[i][j + 1] == '#')jur = 1;
				}
				if (jur == 0){
					ans = 1;
					break;
				}
			}
		}
		if (ans == 1)break;
	}
	if (ans == 0)cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
/**
 *   Author: Praveen Ojha
 *   Created: 27 March 2019
 *   Time: 02:18:06
**/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define PI 3.141592653589793238510
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define __ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 
typedef long double ld;
typedef pair<int,int> pii;
const int maxn=3005;
int n,a[maxn],dp[maxn][maxn];
int solve(int start,int end){
	if(start==end)
	return a[start];
	if(dp[start][end]!=-1)
		return dp[start][end];
	return dp[start][end]=max(a[start]-solve(start+1,end),a[end]-solve(start,end-1));
}
int32_t main(){__
	memset(dp,-1,sizeof dp);
	cin>>n;
	for(int i=0;i<n;i++)
	cin>>a[i];
	cout<<solve(0,n-1)<<"\n";
return 0;
}

Measured memory_bytes: 70912
#include<stdio.h>
 
#define MAX 100000
typedef long long llong;
 
int n, k;
llong T[MAX];
 
int check(llong P){
  int i = 0,j;
  for(j = 0; j < k; j++){
    llong s = 0;
    while(s + T[i]<=P){
      s += T[i];
      i++;
      if(i==n) return n;
    }
  }
  return i;
}
 
int solve(){
  llong left = 0;
  llong right = 100000 * 10000;
  llong mid;
  while(right - left > 1){
    mid = (left + right) / 2;
    int v = check(mid);
    if(v >=n) right = mid;
    else left = mid;
  }
  return right;
}
 
int main(){
  int i;
  scanf("%d%d",&n,&k);
  for(i = 0; i<n;i++) scanf("%d",&T[i]);
  llong ans = solve();
  printf("%d\n",ans);
}



Measured memory_bytes: 2552
#include <iostream>
#include <map>
#include <algorithm>    
#include <vector>       
#include <set>
#include <utility>  
#include <cstring>
#include <stdio.h>
#include <limits.h>
#include <queue>
#include <algorithm> 
#define MAX_DOUBLE  40000000000.0 
#include <math.h> 
#include <unistd.h>

using namespace std;


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

long long max(long long a, long long b){
	if( a < b ) return b;
	return a; 
}

long long values[100010];
long long weights[100010];
long long K [110][100010];

long long blatmp(int W, int n) 
{ 
  
    for(int i = 0; i<=n; i++){
		for (int j = 0; j<100010; j++){			
			if(i == 0 || j == 0){
				K[i][j] = 0;
			}else if(j < values[i-1]){
				K[i][j] = K[i-1][j];	
			}else if(j == values[i-1]){

				if(K[i-1][j] == 0)  
					K[i][j] = weights[i-1];
				else 
					K[i][j] = min(K[i-1][j], weights[i-1]);
			}else{
				long long w1 = K[i-1][j];
				long long w2 = K[i-1][j - values[i-1]];
				if(w1 == 0) w1 = W+1; 
				if(w2 == 0) w2 = W+1;
				w2 += weights[i-1];
				K[i][j] = min(w1, w2);

			}
			
			if(K[i][j] > W) K[i][j] = 0;
		}

   }
   long long res = 0;
   for(int i = 0; i<100010; i++){
		if(K[n][i] !=0) res = i;
   }
   return res;  
     
} 


int main(){
	long long n, w;
	cin>>n>>w;
	
	for(int i = 0; i < n; i++){
		cin>>weights[i]>>values[i];

	}
	
	cout<<blatmp(w, n);

}


Measured memory_bytes: 82176
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
import Data.Array
--import Data.Array.Unboxed
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
-- import System.IO.Unsafe
 
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnBin :: (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d
fnBin op f g x = op (f x) $ g x
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
modifyArray :: (Ix i, MArray a e m) => a i e -> i -> (e -> e) -> m ()
modifyArray arr ix f = readArray arr ix >>= writeArray arr ix . f
-- end of templete

isTriangle xs = let [a,b,c] = sort xs in a+b>c
f x y z [] = sjoin [x+y+z, x, y, z]
f x y z (t:ts) = let [a,b,c] = sort t in case (compare (a^2+b^2) (c^2)) of
    EQ -> f (x+1) y z ts
    GT -> f x (y+1) z ts
    LT -> f x y (z+1) ts


main = takeWhile (isTriangle) . map (map readInt . words) . lines <$> getContents >>= putStrLn . f 0 0 0

Measured memory_bytes: 4236
/*********************************************************************
* AUTHOR : ANSHU KUMAR                                               *
* ABOUT :  IT DOESN'T MATTER HOW SLOW I GO, AS LONG AS I NEVER STOP  *
* INSTITUTION : IEM KOLKATA                                          *
**********************************************************************/

//try to think at least 30min(with full concentration).

#include <bits/stdc++.h>

using namespace std;

#define int             long long
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)     __builtin_ctzll(x)
#define MOD             1000000007
#define INF             1e18
#define PI              3.1415926535897932384626433832795
#define sp(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define endl            '\n'
#define da(arr,type,n)  type *arr=new type[n];


/********** Euclidean Algorithm for GCD **********/
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }



/********** Fast Power Exponentiation ***********/
int power(int a, int b) {
	int res = 1;
	while (b > 0) {
		if (b & 1)
			res = (res % MOD * a % MOD) % MOD;
		a = (a % MOD * a % MOD) % MOD;
		b >>= 1;
	}
	return res;
}



/********** FAST I/O ************/
void fastIO()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}



/********** PROGRAM START ***********/

int32_t main()
{
	fastIO();
	int n, l;
	cin >> n >> l;
	vector<string>str(n);
	for (int i = 0; i < n; i++)
	{
		cin >> str[i];
	}
	sort(str.begin(), str.end());
	string str1 = "";
	for (int i = 0; i < n; i++)
	{
		str1 += str[i];
	}
	cout << str1 << endl;
	return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    # n, k = map(int, input().split())
    v = list(map(int, input().split()))
    # s = input()

    even = [0] * (10 ** 5 + 100)
    odd = [0] * (10 ** 5 + 100)

    for i in range(n):
        if i % 2 == 0:
            even[v[i]] += 1
        else:
            odd[v[i]] += 1

    max_even = even.index(max(even))
    max_odd = odd.index(max(odd))

    if max_even == max_odd:
        even[max_even] = 0
        odd[max_odd] = 0
        if max(even) < max(odd):
            max_odd = odd.index(max(odd))
        else:
            max_even = even.index(max(even))
    ans = 0
    for i in range(n):
        if i % 2 == 0 and max_even != v[i]:
            ans += 1
        if i % 2 != 0 and max_odd != v[i]:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 85684
# abc166 B
n, k = gets.split.map(&:to_i)
a = []

sn = Array.new(n, 0)

k.times  {
  d = gets.to_i
  a << gets.split.map(&:to_i)
}


a.each do |aa|
  aa.each do |x|
    sn[x-1] += 1
  end
end

p sn.count(&:zero?)


Measured memory_bytes: 14428
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

ll gcd(ll a,ll b){
    ll r;
    while(a%b!=0){
        r=a%b;
        a=b;
        b=r;
    }
    return b;
}

map<ll,ll> prime_factor(ll n){
    map<ll,ll> res;
    for(ll i=2;i*i<=n;i++){
        while(n%i==0){
            ++res[i];
            n/=i;
        }
    }
    if(n!=1) res[n]=1;
    return res;
}

signed main(){
    ll a,b;
    cin>>a>>b;
    ll n=gcd(a,b);
    map<ll,ll> mp=prime_factor(n);
    cout<<mp.size()+1<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int64_t i = 0; i < n; ++i)
using namespace std;

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> v(h);
  string s = "";
  rep(i, h) cin >> v[i];
  rep(i, h) v[i] = "#" + v[i] + "#";
  rep(i, w+2) s += "#";
  cout << s << endl;
  rep(i, h) cout << v[i] << endl;
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*
import kotlin.concurrent.fixedRateTimer

fun PrintWriter.solve(sc: FastScanner) {
    val a = sc.nextInt()
    val b = sc.nextInt()
    if (a * b % 2 == 0) {
        println("No")
    } else {
        println("Yes")
    }
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


Measured memory_bytes: 29356
#include <cstdio>
#include <iostream>
using namespace std;
int n,r;
int c[2][55];
int main(void){
  while(cin >> n >> r && n){
    for(int i = 0; i < n; i++) c[0][n-i-1] = i+1;
    for(int i = 0; i < r; i++){
      int a,b;
      cin >> a >> b;
      a--;
      for(int j = 0; j < b; j++)
	c[(i+1)%2][j] = c[i%2][a+j];
      for(int j = 0; j < a; j++)
	c[(i+1)%2][b+j] = c[i%2][j];
      for(int j = a+b; j < n; j++)
	c[(i+1)%2][j] = c[i%2][j];

      /*
      for(int j = 0; j < n; j++)
	cout << c[(i+1)%2][j] << " ";
      cout << endl;
      */
    }
    cout << c[r%2][0] << endl;
  }
}

Measured memory_bytes: 1160
Inlist = []

while True:
    val = list(map(int, input().split()))
    H, W = val[0], val[1]
    if H == 0 and W == 0:
        break
    else:
        Inlist.append(val)
      
for HW in Inlist:
    H, W = HW[0], HW[1]
    for h in range(H):
        linestr = ''
        for w in range(W):
            if (h % 2 == 0 and w % 2 == 0) or \
                (h % 2 == 1 and w % 2 == 1):
                linestr += '#'
            else:
                linestr += '.'
        print(linestr,end='\n')
    print()


Measured memory_bytes: 5636
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  vector<int> x(5);
  for (int i = 0; i < 5; i++) {cin >> x.at(i);}
  for (int i = 0; i < 5; i++) {if (x.at(i) == 0) {a = i + 1; break;}}
  cout << a << endl;
}

Measured memory_bytes: 3576
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long inf = numeric_limits<long long>::max();
int main()
{
  int n, k;
  cin >> n >> k;
  vector<int> seq(n);
  rep(i, n) {
    cin >> seq[i];
  }
  sort(seq.begin(), seq.end());
  long long ans = inf;
  rep(i, n-k+1) {
    ans = min(ans, (long long)abs(seq[i] - seq[i+k-1]));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i = 0;i < (n);i++)
#define rep(i,m,n) for(int i = (m);i < (n);i++)
#define P pair<int,int>
#define pb push_back
#define mk make_pair
using namespace std;
#define Vec(a) vector <int> a
const int INF = 1 << 20;
const int MOD = 1e9+7;





int main(){
  int h,w;
  cin >> h >> w;
  string s[h];
  
  REP(i,h){
    cin >> s[i];
  }
  bool t = true;
  REP(i,h){
    REP(j,w){
      if(s[i][j] == '#')
	t = false;
    }
  }
  if(t){
    cout << "Yes" << endl;
    return 0;
  }
  bool f = true;
  REP(i,h){
    REP(j,w){
      if(s[i][j] == '#'){
	if(i == 0){
	  if(j == 0){
	    if(s[i][j+1] == '.' && s[i+1][j] == '.')
	      f = false;
	  }
	  else if(j == w-1){
	    if(s[i][j-1] == '.' && s[i+1][j] == '.')
	      f = false;
	  }
	  else{
	    if(s[i][j+1] == '.' && s[i+1][j] == '.' && s[i][j-1] == '.')
	      f = false;
	  }
	}
	else if(i == h-1){
	  if(j == 0){
	    if(s[i][j+1] == '.' && s[i-1][j] == '.')
	      f = false;
	  }
	  else if(j == w-1){
	    if(s[i][j-1] == '.' && s[i-1][j] == '.')
	      f = false;
	  }
	  else{
	    if(s[i][j+1] == '.' && s[i-1][j] == '.' && s[i][j-1] == '.')
	      f = false;
	  }
	}
	else{
	  if(j == 0){
	    if(s[i][j+1] == '.' && s[i-1][j] == '.' && s[i+1][j] == '.')
	      f = false;
	  }
	  else if(j == w-1){
	    if(s[i][j-1] == '.' && s[i-1][j] == '.' && s[i+1][j] == '.')
	      f = false;
	  }
	  else{
	    if(s[i][j+1] == '.' && s[i-1][j] == '.' && s[i][j-1] == '.' && s[i+1][j] == '.')
	      f = false;
	  }
	}
      }
    }
  }
  if(f)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;

 
int main(){
  int k,n;
  cin >> k >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  int ma =0;
  rep(i,n-1){
    ma = max(ma,a[i+1]-a[i]);
  }
  ma = max(ma,a[0]+k-a[n-1]);
  int ans = k-ma;
  cout << ans << endl;
  return 0;
}


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

#ifdef DEBUG
#define LOG(var, sep) (cerr << #var << " = " << (var) << (sep))

#define LOGM(msg) (cerr << (msg))

#define LOGV(vec, sep) {                                        \
    cerr << #vec << " =";                                       \
    for (const auto& v : (vec)) cerr << " " << v;               \
    cerr << (sep); }

#define LOGA(arr, N, sep) {                                     \
        cerr << #arr << " =";                                   \
        for (int i = 0; i < N; ++i) cerr << " " << (arr)[i];    \
        cerr << (sep); }

#define LOGA2(arr, N, M, sep) {                                 \
        cerr << #arr << " =\n";                                 \
        for (int i = 0; i < N; ++i) {                           \
            for (int j = 0; j < M; ++j)                         \
                cerr << (arr)[i][j] << " ";                     \
            cerr << endl;                                       \
        } cerr << (sep); }
#else
#define LOG(var, sep)
#define LOGM(msg)
#define LOGV(vec, sep)
#define LOGA(arr, N, sep)
#define LOGA2(arr, N, M, sep)
#endif

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

const int MAX { 300010 };
const ll MOD { 1000000007 }, oo { 1LL << 62 };

int solve(int H, int W, const set<ii>& ps)
{
    map<int, int> hs, vs;

    for (auto p : ps)
    {
        auto x = p.first, y = p.second;

        ++hs[x];
        ++vs[y];
    }

    vector<ii> xs, ys;

    for (auto p : hs)
    {
        auto x = p.first, qtd = p.second;

        xs.push_back(ii(qtd, x));
    }

    for (auto p : vs)
    {
        auto y = p.first, qtd = p.second;

        ys.push_back(ii(qtd, y));
    }

    sort(xs.begin(), xs.end(), greater<ii>());
    sort(ys.begin(), ys.end(), greater<ii>());

    auto A = xs.front().first, B = ys.front().first;

    set<int> bx, by;

    for (auto x : xs)
    {
        if (x.first != A)
            break;

        bx.insert(x.second);
    }

    for (auto y : ys)
    {
        if (y.first != B)
            break;

        by.insert(y.second);
    }

    for (auto x : bx)
        for (auto y : by)
            if (ps.count(ii(x, y)) == 0)
                return A + B;

    return A + B - 1;
}

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

    int H, W, M;
    cin >> H >> W >> M;

    set<ii> ps;

    for (int i = 0; i < M; ++i)
    {
        ll x, y;
        cin >> x >> y;

        ps.insert(ii(x, y));
    }

    auto ans = solve(H, W, ps);

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 78368
import java.io.*;
import java.util.*;

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

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {
            int n = in.nextInt();
            Map<String, Integer> map = new TreeMap<>();
            int max = -1;
            for (int i = 0; i < n; i++) {
                String str = in.next();
                if (map.containsKey(str)){
                    int val = map.get(str);
                    map.put(str, val+1);
                    if (max < val+1){
                        max = val+1;
                    }
                }else{
                    map.put(str, 1);
                    if (max < 1){
                        max = 1;
                    }
                }
            }
            for(String str: map.keySet()){
                if (map.get(str) == max){
                    out.println(str);
                }
            }
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

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

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

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

        public double nextDouble() {
            return Double.parseDouble(next());
        }

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

        public char nextChar() {
            return next().charAt(0);
        }

        public String nextLine() throws IOException {
            return reader.readLine().trim();
        }
    }
}


Measured memory_bytes: 50844
package main

import (
    "fmt"
    "strconv"
)

func main() {
    var a, b int 
    fmt.Scan(&a, &b) 
    var sum int 
    for i := a; i <= b; i++ {
        s := []byte(strconv.Itoa(i))
        var ng bool
        for j := 0; j < len(s); j++ {
            if s[j] != s[len(s)-j-1] {
                ng = true
            }   
        }   
        if !ng {
            sum++
        }   
    }   
    fmt.Println(sum)
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include <algorithm>
#include <functional>
#include <vector>

using namespace std;

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

	int a[10], b[10];
	
	for(int i=0; i<10; i++){
		cin >> a[i];
	}

	for(int i=0; i<10; i++){
		cin >> b[i];
	}

	sort(a,a+10);
	sort(b,b+10);


	cout << a[9] + a[8] + a[7] << " ";	
	cout << b[9] + b[8] + b[7] << "\n";	
	
	return 0;
}

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

int main() {
    int k,s;
    cin >> k >> s;
    int t = 0;
    
    for (int i = 0; i <= k; i++) {
        for (int j = i; j <= k; j++) {
            for (int z = j; z <= k; z++) {
                if (i+j+z == s) {
                    if (i==j && j==z) t+=1;
                    else if (i==j || i==z || j==z) t +=3;
                    else t += 6;
                }
            }
        }
    }
    
    cout << t;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//https://qiita.com/drken/items/cce6fc5c579051e64fab
template<class Abel> struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;
 
    UnionFind(int n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }
 
    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }
 
    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }
 
    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }
 
    bool same(int x, int y) {
        return root(x) == root(y);
    }
 
    bool merge(int x, int y, Abel w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }
 
    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};
int main(void){
    int n,m; cin>>n>>m;
    UnionFind <int> tree(n);
    for(int i=0;i<m;i++){
        int a,b,c; cin>>a>>b>>c;
        a--; b--;
        if(tree.same(a,b)){
            int dif = tree.diff(a,b);
            if(dif!=c) {cout<<"No"<<endl; return 0;}
         }else{
             tree.merge(a,b,c);
         }
    }
    cout<<"Yes"<<endl;
}


Measured memory_bytes: 1536
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
using namespace std;
int GCD(long long a, long long b){
  return b?GCD(b,a%b):a;
}
int main(){
  int n;
  cin >> n;
  vector<pair<int,int>> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i].second >> a[i].first;
  }
  sort(a.begin(),a.end());
  long long t=0;
  bool ans=true;
  for(int i=0;i<n;i++){
    t+=a[i].second;
    if(t>a[i].first)ans=false;
  }
  puts(ans?"Yes":"No");
}

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if (A == B){
    if (A == C){
      cout << "No" << endl;
    }
    else{
      cout << "Yes" << endl;
    }
  }
  else{
    if (A != C && B != C){
      cout << "No" << endl;
    }
    else{
      cout << "Yes" << endl;
    }
  }
}


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

using namespace std;

struct info{
	string word;
	int p;
	int page[1000];
};

void intsort(int a[1000], int p)
{
	int t;
	for(int i = p; i >= 0; i--){
		for(int j = 1; j <= i; j++){
			if(a[j] < a[j-1]){
				t = a[j];
				a[j] = a[j-1];
				a[j-1] = t;
			}
		}
	}
	return ;
}

void strsort(info a[101], int p)
{
	info t;
	for(int i = p; i >= 0; i--){
		for(int j = 1; j <= i; j++){
			if(a[j-1].word > a[j].word){
				t = a[j];
				a[j] = a[j-1];
				a[j-1] = t;
			}
		}
	}
	return ;
}

int main()
{
	string str;
	int s, t = 0;
	info index[101];
	bool f;

	while(cin >> str >> s){
		if(t > 0){
			f = true;
			for(int i = 0; i < t; i++){
				if(str == index[i].word){
					index[i].page[index[i].p] = s;
					index[i].p += 1;
					f = false;
					break;
				}
			}
			if(f){
				index[t].word = str;
				index[t].page[0] = s;
				index[t].p = 1;
				t++;
			}
		} else {
			index[t].word = str;
			index[t].p = 1;
			index[t].page[0] = s;
			t++;
		}
	}
	
	for(int i = 0; i < t; i++){
		intsort(index[i].page, index[i].p-1);
	}
	strsort(index, t-1);
	
	for(int i = 0; i < t; i++){
		cout << index[i].word << endl;
		cout << index[i].page[0];
		for(int j = 1; j < index[i].p; j++){
			cout << " " << index[i].page[j];
		}
		cout << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
from itertools import chain, permutations, dropwhile
from heapq import merge
from functools import wraps

def listify(fn):
  @wraps(fn)
  def wrapper(*args, **kwargs):
    return list(fn(*args, **kwargs))
  return wrapper

def comp_wild(a,b):
  return all(x==y or "?" in (x,y) for x,y in zip(a, b))

@listify
def includers(a,b):
  for i in range(len(a)-len(b)+1):
    if comp_wild(a[i:], b):
      yield i 

@listify
def connectors(a,b):
  for i in range(max(len(a)-len(b)+1, 1), len(a)+1):
    if comp_wild(a[i:], b):
      yield i

class c_int(int):
  def __new__(cls, *args, **kwargs):
    cond = kwargs.pop("cond", lambda:True)
    i = int.__new__(cls, *args, **kwargs)
    i.cond = cond
    return i

def iter_from(it, fm):
  return dropwhile(fm.__gt__, it)

def solve(*keys):
  keys = sorted(keys, key=len, reverse=True)
  len_keys = list(map(len, keys))
  inc = { (i,j):includers(keys[i],keys[j]) for i,j in permutations(range(3), 2) }
  con = { (i,j):connectors(keys[i],keys[j]) for i,j in permutations(range(3), 2) }
  
  for i in inc[0,1]:
    for j in inc[0,2]:
      if (
        j+len_keys[2] <= i or i+len_keys[2] <= j or
        j-i in inc[1,2] or j-i in con[1,2] or i-j in con[2,1]
      ):
        return len_keys[0]
  
  def candicates(x,y,z):
    return chain(
      ( c_int(
          i+len_keys[z], 
          cond=lambda:(
            (inc[x,y] and inc[x,y][0]+len_keys[y] <= i) or 
            (inc[z,y] and len_keys[x] <= i+inc[z,y][-1]) or 
            any(
              (i-j in con[y,z] if i > j else j-i in inc[z,y])
               for j in iter_from(inc[x,y]+con[x,y], i-len_keys[y])
            )
          )
        ) for i in iter_from(con[x,z], len_keys[y]-len_keys[z]+1)
      ),
      ( c_int(
          min( i+next(iter_from(q, len_keys[x]-i+1))+len_keys[z] for i in p )
        ) for (p, q) in [sorted((con[x,y], con[y,z]), key=len)]
      ),
    )
  
  for c in merge(*( candicates(*xyz) for xyz in permutations(range(3), 3) )):
    if c.cond():
      return c
  
  return sum(len_keys)

print(solve(*(input() for i in range(3))))


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

int main() {
  int H, W;
  cin >> H >> W;
  string cells[H];
  
  for (int i = 0; i < H; i++) cin >> cells[i];
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (cells[i][j] == '#') continue;
      int num = 0;
      for (int h = -1; h <= 1; h++) {
        for (int w = -1; w <= 1; w++) {
          int t_i = i + h;
          int t_j = j + w;
          if (t_i == i && t_j == j) continue;
          if (t_i < 0 || t_i >= H) continue;
          if (t_j < 0 || t_j >= W) continue;
          if(cells[t_i][t_j] == '#') num += 1;
        }
      }
      cells[i][j] = '0' + num;
    }
  }
  
  for (int i = 0; i < H; i++) cout << cells[i] << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
using namespace std;
typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
//    cout<<fixed;
//    cout<<setprecision(10);

    ll n;
    cin>>n;
    ll ans=(n/500);
    ans=ans*1000LL;
    n%=(500LL);
    ll x=n/5;
    x*=5;
    ans+=x;
    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n,m = LI()
    a = LI()
    s = sum(a)
    r = 0
    for c in a:
        if c / s >= 1 / 4 / m:
            r += 1

    if r >= m:
        return "Yes"

    return "No"


print(main())





Measured memory_bytes: 5568
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define veci(x,n) vector<int> x((int) (n))
#define vecs(x,n) vector<string> x((int) (n))
#define vecbf(x,n) vector<bool> x((int) (n), false)

int main(){
  int a,b;
  cin >> a >> b;
  int x1,x2,x3;
  x1 = a+b;
  x2 = a-b;
  x3 = a*b;
  int ans = max(x1,x2);
  ans = max(ans,x3);
  cout << ans << endl;
}


Measured memory_bytes: 256
import sys

#入力用
def ILI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def ISI(): return map(int, sys.stdin.readline().rstrip().split())
def II(): return int(sys.stdin.readline().rstrip())
def ISS(): return sys.stdin.readline().rstrip().split()
def IS(): return sys.stdin.readline().rstrip()

N, M = ISI()
ab = [list(ISI()) for _ in range(N)]
cd = [list(ISI()) for _ in range(M)]
for i in range(N):
    min = 1000000000000
    for j in range(M):
        n = abs(ab[i][0] - cd[j][0]) +  abs(ab[i][1] - cd[j][1])
        if min > n:
            min = n
            point = j+1
    print(point)

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

#define MOD (1000 * 1000 * 1000 + 7)
#define INF (1LL << 60)
#define pb push_back
#define po pop_back
#define fi first
#define se second

typedef long long ll;
typedef long double ld;

#define maxn 1005
string table[maxn];
ll dp[maxn][maxn];

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

    int H, W;
    cin >> H >> W;

    for (int i = 1; i <= H; ++i) {
        cin >> table[i];
        table[i] = " " + table[i];
    }

    dp[1][1] = 1;
    for (int i = 1; i <= H; ++i) {
        for (int j = 1; j <= W; ++j) {
            if (table[i][j] == '#')
                continue;
            if (i == 1) {
                dp[i][j] = (dp[i][j] + dp[i][j - 1]) % MOD;
            } else if (j == 1) {
                dp[i][j] = (dp[i][j] + dp[i - 1][j]) % MOD;
            } else {
                dp[i][j] = (dp[i][j] + dp[i - 1][j] + dp[i][j - 1]) % MOD;
            }
        }
    }

    cout << dp[H][W] << endl;
    return 0;
}

Measured memory_bytes: 9088
#include <stdio.h>
#include <math.h>

#define NMAX 100
#define WMAX 100
#define HMAX 100

int main(void){
  int i;
  int w, h, n;
  int x, y, a;
  int x1, x2, y1, y2;
  int ans;

  scanf("%d %d %d", &w, &h, &n);

  x1 = y1 = 0;
  x2 = w;
  y2 = h;

  for (int i = 0; i < n; i++){
    scanf("%d %d %d", &x, &y, &a);
    switch (a){
    case 1:x1 = (int)fmax(x1, x); break;
    case 2:x2 = (int)fmin(x2, x); break;
    case 3:y1 = (int)fmax(y1, y); break;
    case 4:y2 = (int)fmin(y2, y); break;
    }
  }
  if (x1 >= x2 || y1 >= y2)ans = 0;
  else ans = (x2 - x1)*(y2 - y1);

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

  return(0);
}

Measured memory_bytes: 128