akhauriyash/Code-Regression huggingface dataset:
//From Naruto to Hokage
//#include <RJ>
#include<bits/stdc++.h>
using namespace std;
#define int         long long
#define ll          long long
#define pb          push_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=200005;
int a[N];
pii seg[N<<2];
void build(int node,int start,int end){
    if(start==end){
        seg[node].F=a[start];
        seg[node].S=a[start];
        return;
    }
    int mid=(start+end)>>1;
    build(node<<1,start,mid);
    build(node<<1|1,mid+1,end);
    seg[node].F=max(seg[node<<1].F,seg[node<<1|1].F);
    seg[node].S=min(seg[node<<1].S,seg[node<<1|1].S);
}
pii query(int node,int start,int end,int l,int r){
    if(l<=start && r>=end) return seg[node];
    if(r<start || l>end) return {-1,hell};
    int mid=(start+end)>>1;
    pii ans1=query(node<<1,start,mid,l,r);
    pii ans2=query(node<<1|1,mid+1,end,l,r);
    return {max(ans1.F,ans2.F),min(ans1.S,ans2.S)};
}
int pre[N];
void solve(){
    ll n,k;
    cin>>n>>k;
    // vi v(n+1);
    rep(i,1,n) cin>>a[i];
    build(1,1,n);
    ll b[n+1];
    memset(b,0,sizeof(b));
    rep(i,2,n){
        if(a[i]>(a[i-1])){
            b[i]=1;
        }
        pre[i]=pre[i-1]+b[i];
    }
    ll ans=1;
    ll kk=0;
    if(pre[k]-pre[1]==(k-1)) ans--,kk=1;
    // cout<<ans<<endl;
    // rep(i,1,n) cout<<pre[i]<<" ";
    rep(i,k+1,n){
        ll minn=query(1,1,n,i-k,i).S;
        ll maxx=query(1,1,n,i-k+1,i).F;
        if(a[i-k]!=minn || a[i]!=maxx){
            if(pre[i]-pre[i-k+1]!=(k-1)) ans++;
            else kk=1;
        }
    }
    cout<<ans+kk;
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}

Measured memory_bytes: 15360
n,k = map(int, input().split())
a = list(map(int, input().split()))

for i in range(k):
    nxt = [0]*n
    for j in range(n):
        l = j-a[j]
        r = j+a[j]+1
        if l < 0:
            l = 0
        nxt[l] += 1
        if r < n:
            nxt[r] -= 1
    for j in range(n-1):
        nxt[j+1] += nxt[j]
    if a == nxt:
        break
    a = nxt
print(*a)

Measured memory_bytes: 148464
#!/usr/bin/env python3

def main():
    N=int(input())
    A = list(map(int,input().split()))
    ans=[None]*N
    i=1
    for a in A:
        ans[a-1]=str(i)
        i+=1
    print(' '.join(ans))

if __name__ == "__main__":
    main()


Measured memory_bytes: 14972
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};


int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    string s;
    cin>>s;
    rep(i,3) cout<<s[i];
    cout<<endl;
}/*
./problem.exe
*/

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

int main(void){
    int n,q;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    cin>>q;
    int x,b,c;
    while(q--){
        cin>>x>>b>>c;
        if(x==0) cout<<*min_element(a+b,a+c)<<endl;
        else cout<<*max_element(a+b,a+c)<<endl;
    }
}


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

#define all(A) begin(A), end(A)
#define rall(A) rbegin(A), rend(A)
#define sz(A) int(A.size())
#define pb push_back
#define mp make_pair

using namespace std;

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

int main () {
	ios::sync_with_stdio(false); cin.tie(0);
	ll n;
	cin>>n;
	ll total = 0;
	map <string,ll> m; 
	set <string> s;
	for(ll i=1; i<=n;i++){
		string palabra;
		cin>>palabra;
		sort(palabra.begin(),palabra.end());
		m[palabra]++;
		s.insert(palabra);
	}
	for(auto it=s.begin(); it!=s.end(); ++it){
		total += (m[*it])*(m[*it]-1)/2;
	}
	cout<<total;
	
	
	
	
	return (0);
}

Measured memory_bytes: 20608
//#define _GLIBCXX_DEBUG    //空コンテナ操作禁止　Clang環境では#define _LIBCPP_DEBUG 0
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;
using ll = long long;
char moji[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};

int main(){
  int N;
  string S;
  cin >> N >> S;
  
  for( int i=0; i<S.size(); i++ ){
    cout << moji[( S.at(i) +26 -'A' + N )%26];
  }
  return 0;
}



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

int main()
{
    cin.tie(0);

    int n, k;
    cin >> n >> k;

    vector<tuple<int, int, char>> ds(n);
    for (auto& d : ds) {
        int x, y;
        char c;
        cin >> x >> y >> c;
        d = tuple<int, int, char>(x, y, c);
    }

    vector<vector<int>> bs(k * 2 + 1, vector<int>(k * 2 + 1, 0));
    vector<vector<int>> ws(k * 2 + 1, vector<int>(k * 2 + 1, 0));

    for (auto& d : ds) {
        int x, y;
        char c;
        tie(x, y, c) = d;

        if (c == 'B') {
            bs[y % (k * 2) + 1][x % (k * 2) + 1]++;
        } else {
            ws[y % (k * 2) + 1][x % (k * 2) + 1]++;
        }
    }

    auto sum = [&](vector<vector<int>>& m) {
        for (int y = 1; y <= 2 * k; y++) {
            for (int x = 1; x <= 2 * k; x++) {
                // cout << m[y][x] << " ";
                m[y][x] += m[y][x - 1] + m[y - 1][x] - m[y - 1][x - 1];
            }
            // cout << endl;
        }
        // cout << endl;
    };
    sum(bs);
    sum(ws);

    auto count_sub = [&](vector<vector<int>>& m, int sx, int sy, int tx, int ty) -> int {
        if (sx >= tx)
            return 0;
        if (sy >= ty)
            return 0;
        return m[ty][tx] - m[ty][sx] - m[sy][tx] + m[sy][sx];
    };

    auto count = [&](vector<vector<int>>& m, int sx, int sy, int tx, int ty) -> int {
        if (sx >= 2 * k) {
            sx -= 2 * k;
            tx -= 2 * k;
        }
        if (sy >= 2 * k) {
            sy -= 2 * k;
            ty -= 2 * k;
        }

        int ret = 0;
        ret += count_sub(m, sx, sy, min(tx, 2 * k), min(ty, 2 * k));
        ret += count_sub(m, 0, sy, tx - 2 * k, min(ty, 2 * k));
        ret += count_sub(m, sx, 0, min(tx, 2 * k), ty - 2 * k);
        ret += count_sub(m, 0, 0, tx - 2 * k, ty - 2 * k);
        return ret;
    };

    int ans = 0;
    for (int oy = 0; oy < 2 * k; oy++) {
        for (int ox = 0; ox < 2 * k; ox++) {
            int cur = 0;
            cur += count(bs, ox, oy, ox + k, oy + k);
            cur += count(ws, ox + k, oy, ox + k + k, oy + k);
            cur += count(ws, ox, oy + k, ox + k, oy + k + k);
            cur += count(bs, ox + k, oy + k, ox + k + k, oy + k + k);

            // cerr << ox << ", " << oy << ": " << cur << endl;
            ans = max(ans, cur);
        }
    }
    cout << ans << endl;

    return 0;
}


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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define what_is(x) cerr << #x << " is " << x << endl;

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int n, m;
	scanf("%d%d", &n, &m);
	ll prev = 0;
	map<int,int> cnt;
	cnt[0] = 1;
	for (int i = 0; i < n; i++) {
		int x;
		scanf("%d", &x);
		x = (x + prev) % m;
		cnt[x]++;
		prev = x;
	}

	ll answer = 0;
	for (auto x : cnt) {
		//printf("%d %d\n", x.first, x.second);
		answer += (ll)x.second * (x.second - 1) / 2;
	}
	printf("%lld\n", answer);
}


Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,i;
  cin>>a>>b;
  if(a>=b)
  {
    for(i=0;i<a;i++)
      cout<<b;
  }
  else
  {
    for(i=0;i<b;i++)
      cout<<a;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef pair<string,ll> si;
typedef pair<ii,ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
#define sort(a) sort(a.begin(),a.end());
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define mp make_pair
#define F first
#define S second
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define nl "\n"
const int MOD = 1e9+7;
const ld PI = 3.1415926535898;
const ll LLMAX = LLONG_MAX;
#define N (int)1e6+1

int main()
{
	ios
	int n,a,b,c,p1,p2,p3;
	cin>>n;
	int prev1,prev2,prev3;
	cin>>prev1>>prev2>>prev3;
	for(int i=0;i<n-1;i++)
	{
		cin>>a>>b>>c;
		p1=prev1,p2=prev2,p3=prev3;
		prev1=a+max(p2,p3);
		prev2=b+max(p1,p3);
		prev3=c+max(p1,p2);
	}
	cout<<max(prev1,max(prev2,prev3))<<nl;
}

Measured memory_bytes: 256
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll mod=(ll)1e9+7;
//}}}

bool f(string s){
  rep(i, s.size()){
    bool f = true;
    rep(j, 4){
      if(s[i] == "ACGT"[j]) f = false;
    }
    if(f) return false;
  }
  return true;
}

int main(){
  string s;
  cin >> s;
  int ans = 0;
  rep(i, s.size()){
    rep(j, i, s.size() + 1){
      string str = s.substr(i, j - i);
      if(f(str)){
        ans = max(ans, j - i);
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

ll solve(ll a, ll b, ll n)
{
  ll num1 = (a*n) / b;
  ll num2 = n / b;
  ll num = num1 - a*num2;
  return num;
}

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

  ll a, b, n;
  cin >> a >> b >> n;

  ll ans = 0;

  bool n_gt_b = (n >= b);
  if(n_gt_b) ans = solve(a, b, b - 1);
  else ans = solve(a, b, n);

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

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
typedef long double ld ;
typedef long long ll ;
ll dp[111][10101];
ll v[111];
ll w[111];
int main(){
	ll N,W; 
	cin>>N>>W;
	for(ll i=1;i<=N;i++)cin>>v[i]>>w[i];
	dp[0][0] = 0;
	for (ll i=1;i<=N;i++){
		for(ll j=1;j<=W;j++){
			dp[i][j] = max(dp[i-1][j],dp[i][j]);
			if(j>=w[i])dp[i][j] = max(dp[i-1][j-w[i]]+v[i],dp[i][j]);
		}
	}
	ll ans =0;
	for(ll i=0;i<=W;i++){
		ans = max(ans,dp[N][i]);
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 10988
#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define inf 2000000000
#define infLL 2000000000000000000
#define MAX 200005
#define sf(a) scanf("%d", &a)
#define sfl(a) scanf("%lld", &a)
#define pf(a) printf("%d\n", a)
#define pfl(a) printf("%lld\n", a)
#define Case(t) printf("Case %d: ", t)
#define pii pair<int, int>
#define MOD 1000000000
#define mod 998244353
#define PI acos(-1.0)
#define eps 1e-9
#define mem(a, b) memset(a, b, sizeof(a))
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

inline int Set(int N, int pos){return N=N | (1<<pos);}
inline int Reset(int N, int pos){return N=N & ~(1<<pos);}
inline bool Check(ll N, ll pos){return (bool)(N & (1LL<<pos));}

inline void normal(ll &a) { a %= mod; (a < 0) && (a += mod); }
inline ll modMul(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a * b) % mod; }
inline ll modAdd(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a + b) % mod; }
inline ll modSub(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while (p) { if (p & 1LL) r = modMul(r, b); b = modMul(b, b); p >>= 1LL; } return r; }
inline ll modInverse(ll a) { return modPow(a, mod - 2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll fast_exp(ll x, ll n, ll m)
{
    ll res = 1;
    while(n>0)
    {
        if(n%2==1)
            res = (res * x) % m;
        x = (x * x) % m;
        n/=2;
    }
    return res%m;
}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

clock_t t_Start;
void Start()
{
    t_Start = clock();
}
void End()
{
    double Time = (double)(clock()-t_Start)/CLOCKS_PER_SEC;
    error(Time);
}

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>orderedSet;
typedef tree<int,null_type,greater<int>,rb_tree_tag,tree_order_statistics_node_update>orderedSet1;

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    //Start();

    string s;
    cin>>s;
    if(s[2]==s[3] && s[4]==s[5])
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

    //End();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define vl vector
using namespace std;
int main()
{
    set<char> se;
    string s;
    cin>>s;
    for(ll i=0;i<s.size();i++) se.insert(s[i]);
    if(se.size()==2) cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cstdio>

using namespace std;

template<class T>
struct LeftistHeap {

private:

  struct node{
    node *lch,*rch;
    int s;
    T val;
    node(T val):val(val){ lch=rch=NULL; }
  } *root;

public:

  LeftistHeap(){root=NULL;}

  node *meld(node *a,node *b){
    if(!a || !b)return a?a:b;
    if(a->val < b->val)swap(a,b);
    a->rch=meld(a->rch,b);
    if(!a->lch || a->lch->s < a->rch->s)swap(a->lch,a->rch);
    a->s=(!a->rch?0:a->rch->s)+1;
    return a;
  }

  void push(T x){ root=meld(root,new node(x)); }
  
  void pop(){
    node *tmp=root;
    root=meld(root->rch,root->lch);
    delete tmp;
  }

  T top(){ return root->val; }
  bool empty(){ return !root; }
  void clear(){ while(!empty())pop(); }
};

int main(void){

  LeftistHeap<int> que;
  //string com;
  char ch[10];
  int k;

  //while(cin >> com,com!="end"){
  while(true){
    scanf(" %s",ch);
    if(ch[2]=='d')break;
    if(ch[0]=='i'){
      scanf("%d",&k);
      que.push(k);
    } else {
      printf("%d\n",que.top());
      que.pop();
    }
  }

  return 0;
}

Measured memory_bytes: 32436
function Main(raw: string) {
    const lines = raw.split("\n");
    const [firstLine] = lines;
    const N = firstLine.split(" ").map(str=>parseInt(str, 10));
    N.sort();
    const ans = N[0]==1 &&
        N[1]==4 &&
        N[2]==7 &&
        N[3]==9;
    console.log(ans?"YES":"NO");
}

//DO NOT EDIT
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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


#define MAX 100002

int n;
bool use[MAX];
vector<long long int> pr;
#include<unordered_map>
unordered_map<long long int, long long int> mp;

unordered_map<long long int, int> mp2;
unordered_map<long long int, int> mpp;

int main(){
	for (int i = 2; i < 100000; i++){
		if (use[i] == false){
			pr.push_back(i);
			for (int j = i * 2; j < MAX; j+=i){
				use[j] = true;
			}
		}
	}
	scanf("%d", &n);
	int ans = 0;
	for (int i = 0; i < n; i++){
		long long int a;
		scanf("%lld", &a);
		for (int j = 0; pr[j] * pr[j] * pr[j] <= a; j++){
			while (a % (pr[j] * pr[j] * pr[j]) == 0){
				a /= (pr[j] * pr[j] * pr[j]);
			}
		}
		if (a == 1){
			mpp[1]++;
			mp2[1]++;
			continue;
		}
		long long int val = a;
		if (mp.count(a)){
			mpp[mp[a]]++;
			mp2[val]++;
			continue;
		}
		int siz = pr.size();
		long long int v = 1;
		for (int j = 0; j<siz&&pr[j] * pr[j] <= a; j++){
			int cnt = 0;
			while (a%pr[j] == 0LL){
				a /= pr[j];
				cnt++;
			}
			if (cnt){
				v *= pr[j];
				if (cnt == 1){
					v *= pr[j];
				}
			}
			if (v > 10000000000LL){
				break;
			}
		}
		if (v<=10000000000LL&&a){
			v *= a;
			if (v <= 10000000000LL){
				v *= a;
			}
		}
		if (v > 10000000000LL){
			v = -1;
		}
		mp[v] = val;
		mp[val] = v;
		mpp[v]++;
		mp2[val]++;
	}
	long long int way = 0;
	for (auto it = mpp.begin(); it != mpp.end(); it++){
		if ((*it).first == 1LL){
			ans++;
			continue;
		}
		if ((*it).first == -1LL){
			ans += (*it).second;
			continue;
		}
		if (mp2.count((*it).first)){
			way += max((*it).second, mp2[(*it).first]);
		}
		else{
			ans += (*it).second;
		}
	}
	way /= 2LL;
	printf("%lld\n", ans + way);
	return 0;
}

Measured memory_bytes: 14736
# -*- coding: utf-8 -*-
"""
Created on Thu Aug  9 23:51:35 2018

@author: Yuki
"""

A, B, AB, Acnt, Bcnt =map(int, input().split())

res = []
# AをAcnt枚, BをBcnt枚買う場合
res.append(A*Acnt+B*Bcnt)

# AcntとBcntの少ない方に到達するまでABを買い、残りは普通の買う場合
if Acnt >= Bcnt:
    res.append(Bcnt*2*AB+(Acnt-Bcnt)*A)
else:
    res.append(Acnt*2*AB+(Bcnt-Acnt)*B)

# 多い方までABを買う
res.append(max(Acnt, Bcnt)*2*AB)
print(min(res))

Measured memory_bytes: 3060
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    d = int(ipt())
    c = [int(i) for i in ipt().split()]
    s = [[int(i) for i in ipt().split()] for _ in range(d)]
    ld = [-1]*26
    edval = [0]*26

    for i in range(d):
        edval = s[i]*1
        for j in range(26):
            dl = i-ld[j]
            edval[j] += c[j]*dl*(dl+1)//2*0.5
        v = edval.index(max(edval))
        ld[v] = i
        print(v+1)

    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 70940
object Main {
  // 標準入力
  import scala.io.StdIn._
  def readints: Array[Long] = readLine split " " map (_.toLong)
  //
  def main(args: Array[String]) = {
    val Array(a, b) = readints
    val la = (a * 12.5).ceil.toLong
    val ua = ((a + 1) * 12.5).ceil.toLong
    val lb = (b * 10).ceil.toLong
    val ub = ((b + 1) * 10).ceil.toLong
    val lc = Math.max(la, lb)
    val uc = Math.min(ua, ub)
    if (lc < uc) {
      println(s"$lc")
    } else {
      println(s"-1")
    }
  }
}


Measured memory_bytes: 27320
n = int(input())
s = list(input())

ans = 0
for i in range(1,n):
    s1 = set(s[:i])
    s2 = set(s[i:])
    count = 0
    for sc in s1:
        if sc in s2:
            count += 1
    ans = max(ans, count)
print(ans)

Measured memory_bytes: 3060
n, m = map(int,input().split())
a = [list(map(int,input().split())) for _ in range(n)]

like = [0] * (m+1)

for i in range(n):
    for j in range(1,a[i][0]+1):
        like[a[i][j]] += 1

cnt = 0
for i in range(len(like)):
    if like[i] == n:
        cnt += 1

print(cnt)


Measured memory_bytes: 3060
#include<stdio.h>
#include<math.h>
#include <iostream>
using namespace std;
#define  LL long long

const int maxn = 1e5+55;

LL a[maxn],b[maxn];
LL x[maxn],v[maxn];
LL sum[maxn];
int main()
{
	LL n,c;
	cin>>n>>c;
	for(int i=1;i<=n;i++){
		cin>>x[i]>>v[i];

	}
	for(LL i=1;i<=n;i++){
		a[i]=a[i-1]+v[i]-(x[i]-x[i-1]);
	}
	x[n+1]=c;
	for(LL i=n;i>=1;i--){
		b[i]=b[i+1]+v[i]-(x[i+1]-x[i]);
	}
	a[0]=b[n+1]=-1231231222231323;
	for(LL i=1;i<=n;i++){
		a[i]=max(a[i-1],a[i]);
	}
	for(LL i=n;i>=1;i--){
		b[i]=max(b[i],b[i+1]);
	}
	LL ans=0;
	for(LL i=1;i<=n;i++){
		ans=max(ans,-x[i]+a[i]+b[i+1]);
		ans=max(ans,a[i]);
		ans=max(ans,b[i]);
		ans=max(ans,-(c-x[i])+b[i]+a[i-1]);
	}
	cout<<ans<<endl;




}


Measured memory_bytes: 3328
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

vector<int> use;

bool solve(long long rest, int sum)
{
    if(rest == 0)
        return true;

    for(int i=0; i<13; ++i){
        if((sum - (i+1)) % (i+1) == 0 && (rest & (7LL << (3*i)))){
            use.push_back(i+1);
            if(solve(rest - (1LL << (3*i)), sum - (i+1)))
                return true;
            use.pop_back();
        }
    }
    return false;
}

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        long long rest = 0;
        int sum = 0;
        for(int i=0; i<n; ++i){
            int a;
            cin >> a;
            rest += (1LL << (3*(a-1)));
            sum += a;
        }

        use.clear();
        if(solve(rest, sum)){
            for(int i=n-1; i>0; --i)
                cout << use[i] << ' ';
            cout << use[0] << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 1220
use std::vec::Vec;
use std::cmp::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let n: usize = read();
    let mut h: Vec<usize> = read_vec();

    let mut ans = 0;
    while !check_all_zero(&h) {
      let mut l = n;
      let mut r = 0;

      for i in 0..n {
        if h[i] > 0 {
          l = i;
          break;
        }
      }

      for j in l..n {
        if h[j] == 0 {
          r = j;
          break;
        } else if j == n-1 {
          r = n;
          break;
        }
      }

      for k in l..r {
        h[k] -= 1;
      }
      ans += 1;
    }

    println!("{}", ans);
}


fn check_all_zero(h: &Vec<usize>) -> bool {
  for i in 0..h.len() {
    if h[i] > 0 {
      return false;
    }
  }

  return true;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main()
{
    using vi = vector<int>;
    using vvi = vector<vi>;
    using vvvi = vector<vvi>;
    using ll = long long;

    int N, K;
    cin >> N >> K;
    int count = 0;
    rep(i, N)
    {
        int h;
        cin >> h;
        if(h >= K)
            count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int n,i,a=0;
	int min=1000000;
	int max=-1000000;
	long int b=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a);
		if(min>a){
			min=a;
		}
		if(max<a){
			max=a;
		}
		b+=a;
	}
	printf("%d %d %ld\n",min,max,b);
	return 0;

}

Measured memory_bytes: 2756
#include<iostream>
#include<iomanip>
#include<cstdio>

#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>

#include<algorithm>
#include<cmath>
#include<numeric>

using namespace std;
typedef long long ll;
template <class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template <class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
const ll INF = 1e18+1;

/*

XORの累積和は容易に求めることができ、
Al+...+Arを求めるなら
S(r) + S(l-1) を求めればよい (S(0)ダミー付加)

累積和

和とXORの違いは?
繰り上げが発生時に出る

各桁のカウントの累積和をとったら?

条件を満たすようなlrの組は...
各桁カウントSとして B = S(r)-S(l-1)を計算したとき、
一致するのは全ての桁で1以下の時
桁をxとして、
all x
S[x][r] - S[x][l-1] <= 1

各桁カウントSは単調増加なので、尺取り法が使えるのでは?
*/

ll S[200001][20];

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];

    for (int i = 0; i < N; i++) {
        ll a = A[i];
        int d = 0;
        while (a > 0) {
            S[i+1][d] = a % 2 + S[i][d];
            a /= 2; d++;
        }
        for (; d < 20; d++) S[i+1][d] = S[i][d];
    }/*
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 20; j++) {
            cout << S[i][j] << " ";
        } cout << endl;
    }*/
    if (N == 1) {
        cout << 1 << endl;
        return 0;
    }
    int r = 1, l = 0;
    ll cnt = 0;
    while (true) {
        r = max(r,l+1);
        while (true) {
            bool flag = true;
            for (int i = 0; i < 20; i++) {
                if (r+1 <= N && S[r+1][i] - S[l][i] > 1) {
                    flag = false;
                    break;
                }
            }
            if (flag && r+1 <= N) r++;
            else break;
        }
        cnt += r-l;
        //cout << l << " " << r << endl;
        l++;
        if (l == N-1) {
            cnt++; break;
        }
    }
    cout << cnt << endl;
    



}



Measured memory_bytes: 33024
#include<cstdio>
typedef long long ll;
const int mod=1000000007,I2=mod+1>>1;
ll pw(ll a,int n){ll b=1;for(;n;n>>=1)n%2?b=b*a%mod:1,a=a*a%mod;return b;}
int p[20],c[20],cnt;
ll dfs(int i,int x,int K){
	if(i==cnt)return pw(K,x+1>>1)*x%mod;
	ll s=0,t;
	for(int k=0,w=1;k<=c[i];k++,w*=p[i]){
		t=w&1?1:I2;
		if(k<c[i])(t+=(mod-p[i])*1ll*(w*p[i]&1?1:I2))%=mod;
		(s+=dfs(i+1,x*w,K)*t)%=mod;
	}
	return s;
}
int calc(int N,int K){
	int x=N;cnt=0;
	for(int i=2;i*i<=x;i++)if(x%i==0){
		p[cnt]=i,c[cnt]=0;
		while(x%i==0)c[cnt]++,x/=i;
		cnt++;
	}
	if(x>1)p[cnt]=x,c[cnt++]=1;
	return dfs(0,1,K);
}
int main(){
	int N,K;
	scanf("%d%d",&N,&K);
	printf("%d\n",calc(N,K)); 
}

Measured memory_bytes: 128
#include <stdio.h>
int main()
{
    char ch;

    scanf("%c",&ch);
   if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
        printf("vowel\n");
    else
        printf("consonant\n");
    return 0;
}


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

using namespace std; 
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>; 

#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

//#define DEBUG

vector<ll>sum;
ll s(ll a,ll b){
  return (sum[b]-sum[a-1])%MOD;
}

int main_(){
  ll N;
  cin>>N;
  vector<ll>c(N+1);
  map<ll,ll>old;
  ll old_=0;
  sum.resize(N+1,0);
  vector<vector<ll> >v(N+1);
  for(ll i=1;i<=N;i++){
    cin>>c[i];
    if(old[c[i]]!=0&&old_!=c[i]){
      v[old[c[i]]].push_back(i);
      sum[i]++;
    }
    old[c[i]]=i;
    old_=c[i];
  }
  //for(auto it:memo)cout<<it.first<<" "<<it.second<<endl;
  //for(auto it:sum)cout<<it<<endl;
  for(int i=1;i<N;i++){
    sum[i]%=MOD;
    sum[i+1]+=sum[i];
    sum[i+1]%=MOD;
  }
  //for(auto it:sum)cout<<it<<endl;
  vector<ll>dp(N+1,0);
  dp[1]=1;
  ll ans=0;
  for(int i=1;i<N;i++){
    if(v[i].size()){
      for(auto it:v[i]){
        dp[it]=(max(dp[it],1ll)%MOD*(dp[i])%MOD);
        //dp[it]+=(dp[i]*(s(1,it)-s(i+1,it)+1)%MOD)%MOD;
        //ans%=MOD;
        //ans+=(sum[it]-s(i+1,it)+1)%MOD;
        //ans%=MOD;
        //cout<<ans<<endl;
        //cout<<s(1,it)<<" "<<s(i+1,it)<<" "<<(s(1,it)-s(i+1,it))+1<<endl;
        //dp[it]%=MOD;
      }
    }
    dp[i]%=MOD;
    dp[i+1]+=dp[i];
    dp[i+1]%=MOD;
  }
  //cout<<(ans+1)%MOD<<endl;
  //for(auto it:dp)cout<<it<<endl;
  cout<<dp[N]%MOD<<endl;
  return 0;
}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
#ifdef DEBUG
  vector<string>test;
  /*
   * input for debug
   */
  test.push_back("15 1 0 2 0 1 2 1 0 2 1 2 0 1 0 2");
  for(int i=0;i<test.size();++i){
    stringbuf buf;
    streambuf*out=cout.rdbuf(&buf);
    cout<<test[i]<<flush;
    cout.rdbuf(out);
    streambuf*in=cin.rdbuf(&buf);
    main_();
    cin.rdbuf(in);
    cout<<"---------------------"<<endl;
  }
#else
  main_();
#endif

  return 0;
}


Measured memory_bytes: 22144
#include<iostream>
#include<cstdio>
#define _USE_MATH_DEFINES
#include<math.h>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<map>
#include<unordered_map>
#include<set>
#include <algorithm>
#include <utility>

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

typedef unsigned long long ull;
typedef long long ll;

#define Prime1 1000000007
#define Prime2 9999973

int i, j, k, l, m, n;
int H, W, N, M, Q;
int a, b, c;

int main()
{
	string str;
	cin >> str;
	if (str[0] == str[2])cout << "Yes\n";
	else cout << "No\n";
	return 0;
}


Measured memory_bytes: 256
// Original macro is in https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = || -> String {
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
    
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [$t:tt]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// for adhoc read (ex. https://atcoder.jp/contests/abc112/tasks/abc112_a)
#[allow(dead_code)]
fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}
fn main() {
    input!{ n: usize, a: [i32;n] }
    let mut b = vec![0;n];

    for i in (1..n+1).rev() {
        let mut j = 2*i;
        let mut sum = 0;
        while j <= n {
            sum += b[j-1];
            j += i;
        }
        if a[i-1] != sum%2 {
            b[i-1] = 1;
        }
    }

    let mut ans = Vec::new();
    for i in 0..n {
        if b[i] == 1 {
            ans.push(i+1);
        }
    }
    println!("{}", ans.len());
    for (i,v) in ans.iter().enumerate() {
        if i > 0 {
            print!(" ");
        }
        print!("{}", v);
    }
    println!();
}

Measured memory_bytes: 9084
fun main(arr:Array<String>) {
    val (n,d) = readLine()!!.split(" ").map { it.toInt() }
    val pointList = (1..n).map { readLine()!!.split(" ").map { it.toInt() } }
    val variation = (0 until n).map { p1->(0 until n).map { p2-> (0 until d).map { (pointList[p1][it] - pointList[p2][it])* (pointList[p1][it] - pointList[p2][it])}.sum() } }
    val count = variation.sumBy { list->list.count { num -> num != 0 && (Math.sqrt(num.toDouble())).toInt().let { it*it } == num } }
    println(count/2)
}




Measured memory_bytes: 36944
#include<bits/stdc++.h>
#define pi 3.1415926535897932384626
using namespace std;
      
struct P{
  int x,y;
  bool operator < (const P &a )const{
    //if(y!=a.y)
    return y>a.y;
  };
};

int a,b,c,d,i,k,n,m,e,dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1};
int o[1];
int l[411];
int j[1];

long long x,y,z,mod=1000000007;
//string r;
char r[100333];

P u[100011];
queue<int> q;

//stack<int> s;
set<int> s;
map<long long,int> p;
vector<int> v,v1;

bool as(P a,P b)
{
  return a.y<b.y;
}

int main()
{
  scanf("%d",&a);
  for(int t=1;t<=a;t++)
  {
    scanf("%d %d",&n,&m);
    u[t]={n-m,n+m};
  }
  c=-mod;
  sort(u+1,u+1+a,as);
  for(int t=1;t<=a;t++)
  {
    if(u[t].x>=c) k++,c=u[t].y;
  }
  printf("%d",k);
}



Measured memory_bytes: 1024
# coding: utf-8
n, x = map(int,input().split())
A = list(map(int,input().split()))
S = sum(A)
for i in range(n-1):
    s = A[i+1] + A[i]
    if s > x:
        if s-x > A[i+1]:#後ろから全部引ける時
            t = s-x-A[i+1]
            A[i+1] = 0
            A[i] -= t
        else:#後ろから全部引くと負になるとき(前からも引く)
            A[i+1] -= s - x
print(S - sum(A))

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

int main(void) {
    char c11,c12,c13;cin>>c11>>c12>>c13;
    char c21,c22,c23;cin>>c21>>c22>>c23;
    if (c11 == c23 && c22 == c12 && c21 == c13) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdbool.h>
#include <string.h>

void nshift( char *s, int n ){
	int i;

	for( i=0; i<strlen(s); i++ ){
		if( s[i] == ' ' || s[i] == '.' || s[i] == ',' )
			continue;
		s[i] = s[i]+n;
		if( s[i] == 123 )s[i] = 'a';
		if( s[i] == 96 ) s[i] = 'z';
	}
}

int main(){
	char s[81];
	char list[3][6]={"the", "this", "that"};
	int i, j;
	char *p;
	
	while( scanf("%[^\n]", s) != EOF ){
		getchar();
		for( i=0; i<3; i++ ){
			for( j=0; j<26; j++){
				p = strstr( s, list[i] );
				if( p != NULL )
					goto found;
				nshift( s, -1 );
			}
		}
	found:
		printf("%s\n", s);
	}

	return 0;
}

Measured memory_bytes: 536
from itertools import permutations
n = int(input())
p_list = list(map(int,input().split()))
q_list = list(map(int,input().split()))
dum_list = [i for i in range(1,n+1)]
count = 0
ans = 0
for i in permutations(dum_list,n):
    count += 1
    if p_list == list(i):
        ans += count
    if q_list == list(i):
        ans -= count


print(abs(ans))

Measured memory_bytes: 40560
N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)] #1-index

def chmax(a,b):
    if a >= b:
        return a
    else:
        return b
# dp[i+1][w]: i番目までの品物を選びその重さがwを超えないときの最大価値
dp = [[0]*(W+10) for _ in range(N+10)]

for i in range(N):
    for w in range(W+1):
        dp[i+1][w] = dp[i][w]
        
        if w - wv[i][0] >= 0:
            dp[i+1][w] = chmax(dp[i][w - wv[i][0]] + wv[i][1], dp[i][w])

print(dp[N][W])

Measured memory_bytes: 120856
import           Control.Monad
import qualified Data.ByteString.Char8 as BS
import           Data.Foldable
import           Data.Maybe
import qualified Data.Sequence         as Seq

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
  n <- getInt
  as <- getIntList
  bs <- getIntList

  let countAB [] [] ps nneg dneg total = (ps, nneg, dneg, total)
      countAB (a:as') (b:bs') ps nneg dneg total | a < b     = countAB as' bs' ps (nneg+1) (dneg+b-a) (total+a-b)
                                                 | otherwise = countAB as' bs' ((a-b):ps) nneg dneg (total+a-b)

      (ps, nneg, dneg, total) = countAB as bs [] 0 0 0

      ps' = toList $ Seq.unstableSortBy (flip compare) $ Seq.fromList ps

      takePs ps dneg m | dneg <= 0 = m
                       | otherwise = let (p:ps') = ps
                                         dneg' = dneg - p
                                     in takePs ps' dneg' (m+1)

      ans = if total < 0 then -1 else nneg + takePs ps' dneg 0

  print ans

Measured memory_bytes: 15740
//IOI 2021
//labriz kon code ra, ham paye ie AC manam, AC age yari kone ta sob man code miznm :)
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define ff first
#define ss second

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

const int MAXN = 2 * 1000 + 17;

int n, m, q, dpE[MAXN][MAXN], dp[MAXN][MAXN], p[MAXN][MAXN][2];
char a[MAXN][MAXN];

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	memset(a, '0', sizeof(a));
	cin >> n >> m >> q;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			cin >> a[i][j];
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++) {
			dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + (a[i][j] == '1');
			dpE[i][j] = dpE[i - 1][j] + dpE[i][j - 1] - dpE[i - 1][j - 1] + (a[i][j] == '1' && a[i - 1][j] == '1') + (a[i][j] == '1' && a[i][j - 1] == '1');
			p[i][j][0] = p[i][j - 1][0] + (a[i][j] == '1' && a[i][j - 1] == '1');
			p[i][j][1] = p[i - 1][j][1] + (a[i][j] == '1' && a[i - 1][j] == '1');
		}
	while (q--) {
		int x[2], y[2];
		cin >> x[0] >> y[0] >> x[1] >> y[1];
		int res = dpE[x[1]][y[1]] - dpE[x[0]][y[1]] - dpE[x[1]][y[0]] + dpE[x[0]][y[0]] + p[x[0]][y[1]][0] - p[x[0]][y[0]][0] + p[x[1]][y[0]][1] - p[x[0]][y[0]][1] ;
		res =  (dp[x[1]][y[1]] - dp[x[0] - 1][y[1]] - dp[x[1]][y[0] - 1] + dp[x[0] - 1][y[0] - 1])- res;
		cout << res << endl;
	}
	return 0;
}


Measured memory_bytes: 69248
#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define LL long long int
using namespace std;

const int N = 1e5 + 5;
const int oo = 1e9 + 5;
const int MOD = 1e9 + 7;

void solve() {
    string s, t;
    cin >> s >> t;
    int n = s.length(), res = 0;
    for (int i=0;i<n;++i) {
        res += (s[i] != t[i]);
    }
    cout << res << '\n';
} 

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

Measured memory_bytes: 3792
// Last Change: 09/12/2019 09:06:23.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  int H, W;
  cin >> H >> W;
  string A[1000];
  for (int i = 0; i < H; ++i) {
    cin >> A[i];
  }

  queue<pair<int, int>> q1, q2;
  ll cnt = H * W;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (A[i][j] == '#') {
        q1.push(make_pair(i, j));
        --cnt;
      }
    }
  }

  ll ans = 0;
  const int dx[4] = {1, -1, 0, 0};
  const int dy[4] = {0, 0, 1, -1};
  while (cnt > 0) {
    while (!q1.empty()) {
      auto tar = q1.front();
      q1.pop();
      for (int i = 0; i < 4; ++i) {
        int x = tar.first + dx[i], y = tar.second + dy[i];
        if (0 <= x and x < H and 0 <= y and y < W) {
          if (A[x][y] == '.') {
            A[x][y] = '#';
            q2.push(make_pair(x, y));
            --cnt;
          }
        }
      }
    }
    swap(q1, q2);
    ++ans;
  }
  cout << ans << endl;
}


Measured memory_bytes: 9728
a=[int(input()) for i in range(5)]
b=[a[i]%10 for i in range(5)]
c= sorted(b)
for i in range(5):
	if c[i]!=0:
		for j in range(5):
			if c[i]==b[j]:
				d=j
		break
for i in range(5):
	if a[i]%10 !=0 and i!=d:
		while True:
			a[i]=a[i]+1
			if a[i] % 10==0:
				break
print(sum(a))

Measured memory_bytes: 3064
N, x = map(int,input().split())
if x == 1 or x == 2*N-1:
    print("No")
    exit(0)
if N == 2:
    print("Yes")
    print(*[1,2,3], sep="\n")
    exit(0)

A = [0 for k in range(2*N-1)]
A[N-2], A[N-1], A[N] = x-1, x, x+1
t = 1
for k in range(N-2):
    while x-1 <= t <= x+1:
        t += 1
    A[k] = t
    t += 1
for k in range(N+1,2*N-1):
    while x-1 <= t <= x+1:
        t += 1
    A[k] = t
    t += 1
print("Yes")
print(*A, sep="\n")

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

int main(){
  int n;
  cin >> n;
  vector<vector<ll>> cnt(10, vector<ll>(10,0));

  for (int i = 1; i <= n; i++) {
    string s = to_string(i);
    cnt[s.front() - '0'][s.back() - '0']++;
  }

  ll res = 0;

  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) res += cnt[i][j] * cnt[j][i];
  }

  cout << res << endl;
  return 0;
} 

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

#define pb(a) push_back(a)
#define ll long long int
#define vi vector<int>
#define loop(i, n) for(ll i=1;i<=n;i++)
#define loop0(i, n) for(ll i=0;i<n;i++)
#define in(i) scanf("%lld", &i);
#define out(i) printf("%d", i)

ll n, k, a[401];
ll dp[401][401];

ll solve(ll l, ll r)
{
  if(l>r)
    return LONG_MAX;
  if(dp[l][r]!=-1)
    return dp[l][r];
  if(l==r)
    return dp[l][r]=0;
  ll ans=LONG_MAX, finalI=l;
  for(ll i=0;i<r-l;i++)
  {
    ll temp=solve(l, l+i)+solve(l+i+1, r)+a[r]-a[l-1];
    if(temp<ans)
    {
      finalI=i+l;
    }
    ans=min(ans, temp);
  }
  return dp[l][r]=ans;
}
int main()
{
  memset(dp, -1, sizeof(dp));
  in(n);
  loop(i, n)
  {
    in(a[i]);
    a[i]+=a[i-1];
  }
  ll ans=solve(1, n);
  cout<<ans<<"\n";
}


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

int main() {
	// your code goes here
	int a,b;int c[3]={0}; 
  cin>>a>>b;
  c[0]=a+b;
  c[1]=a-b;
  c[2]=a*b;
  sort(c,c+3);
  cout<<c[2];
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(long long (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()

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


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

int main() {
   string N;
   cin >> N;
   if (N.at(N.size()-1)=='3') cout << "bon" << endl;
   else if (N.at(N.size()-1)=='0' || N.at(N.size()-1)=='1' || N.at(N.size()-1)=='6' || N.at(N.size()-1)=='8') cout << "pon" << endl;
   else cout << "hon" << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <vector>

typedef long long ll;

int main(){
  ll N;
  std::cin >> N;
  std::vector<ll> A(N);
  for(auto && r : A) std::cin >> r;
  std::sort(A.rbegin(), A.rend());
  ll resa = 0;
  for(int i = 1 ; i < (int)A.size() ; i++){
    resa += A[ i / 2];
  }

  std::cout << resa << std::endl;
  return 0;
}


Measured memory_bytes: 4848
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mem(a,v) memset(a,v,sizeof(a));

using namespace std;
int main(){

    int a[5];
    cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4];
    int i=0;
    while(a[i]!=0){
        i++;
    }
    cout<<i+1<<endl;
}


Measured memory_bytes: 3588
n = gets.to_i
arr = n.times.map{ gets.to_i }
@cnt = 0


def insert_sort(arr, n, g)
  return if g > n-1
  for i in g..(n-1) do
    v = arr[i]
    j = i - g
    while j >= 0 && arr[j] > v do
      arr[j+g] = arr[j]
      j = j - g
      @cnt += 1
    end
    arr[j+g] = v
  end
end

def build_g_arr(n)
  h = 1
  arr = []
  while h <= n do
    arr.push(h)
    h = h*3 + 1
  end
  arr.reverse
end


g_arr = build_g_arr(n)
m = g_arr.size
m.times do |i|
  insert_sort(arr, n, g_arr[i])
end

puts g_arr.size
puts g_arr.join(' ')
puts @cnt
puts arr


Measured memory_bytes: 14808
answer = "Yes"
N = int(input())
points = [[int(i) for i in input().split()] for i in range(N)]

for t, x, y in points:
    mdist = abs(x) + abs(y)
    if (mdist - t)%2 != 0 or t < mdist:
        answer = "No"
        break

print(answer)

Measured memory_bytes: 21108
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {Main instance = new Main();sc = instance.new Scanner();instance.solve();}
    private class Scanner {String[] s = new String[0];String regex = " ";int i = 0;BufferedReader br = new BufferedReader(new InputStreamReader(System.in));public String next() {try {if (i < s.length) { return s[i++];}String st = br.readLine();while ("".equals(st)) { st = br.readLine(); }s = st.split(regex, 0);i = 0;return s[i++];} catch (IOException e) { return null; }}public int nextInt(){return Integer.parseInt(next());}}        
    private static Scanner sc;

    private void solve() {
        System.out.println((sc.nextInt()-sc.nextInt())%sc.nextInt());
    }
}

Measured memory_bytes: 22740
import itertools
import math
def main():
    N = int(input())
    pos = list()
    for i in range(N):
        x, y = map(int, input().split())
        pos.append([x, y])

    l = [i for i in range(0, N)]
    dist = 0
    for c in itertools.permutations(l, N):
        for i in range(len(c) - 1):
            dist += math.sqrt( (pos[c[i]][0] - pos[c[i+1]][0])**2 +  (pos[c[i]][1] - pos[c[i+1]][1])**2 )

    print(dist/float(math.factorial(N)))
if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

// Acknowledgement: Special thanks to kyomukyomupurin, who developed this
// template.
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#ifdef LOCAL
#define debug(...) \
  std::cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}
using namespace std;
using int64 = long long;

int main() {
  int64 N, H;
  cin >> N >> H;
  vector<pair<int64, int>> v;
  int64 a, b;
  for (int i = 0; i < N; i++) {
    cin >> a >> b;
    v.push_back(make_pair(a, 0));
    v.push_back(make_pair(b, 1));
  }
  sort(v.begin(), v.end(), [](const auto& x, const auto& y) {
    if (x.first == y.first)
      return x.second > y.second;
    else
      return x.first > y.first;
  });
  debug(v);
  int64 ans = 0;
  int idx = 0;
  while (H > 0) {
    debug(H);
    if (v[idx].second == 1) {
      H -= v[idx].first;
      ans++;
      idx++;
    } else {
      ans += (H + v[idx].first - 1) / v[idx].first;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 7464