akhauriyash/Code-Regression huggingface dataset:
// Template Headers {{{
#include <bits/stdc++.h>
using namespace std;

using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long;
using pll = pair<ll, ll>; using vpll = vector<pll>;
using vll = vector<long long>; using vvll = vector<vll>;
template <class T> using min_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T> istream &operator>>(istream &, vector<T> &);
template <class T> ostream &operator<<(ostream &, const vector<T> &);
template <class T, class U> istream &operator>>(istream &, pair<T, U> &);
template <class T, class U> ostream &operator<<(ostream &, const pair<T, U> &);
template <class T> struct Inf { static constexpr T inf() { return std::numeric_limits<T>::has_infinity ? std::numeric_limits<T>::infinity() : std::numeric_limits<T>::max(); } };
template <> struct Inf<int> { static constexpr int inf() { return 0x3f3f3f3f; } };
template <> struct Inf<long long> { static constexpr long long inf() { return 0x3f3f3f3f3f3f3f3fLL; } };
constexpr int INF = Inf<int>::inf(); constexpr ll BINF = Inf<ll>::inf();
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// }}}
// Preprocessing & "Global" variables {{{
struct Solver {
	Solver() {}
	int solve();
};
// }}}


int Solver::solve() {
	int n, m; cin >> n >> m;
	int lo = 1, hi = n;
	for (int i = 0; i < m; i++) {
		int l, r; cin >> l >> r;
		lo = max(lo, l);
		hi = min(hi, r);
	}
	int can = hi - lo + 1;
	cout << max(0, can) << endl;
	return 0;
}

// Template Main {{{
int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	Solver solver;
	#ifdef JUDGE_MULTI_CASE
		int t; cin >> t; for (int i = 1; i <= t; i++)
	#endif
	solver.solve();
	// cout << "Case #" << i << ": ", solver.solve();
	return 0;
}

template <class T> istream &operator>>(istream &is, vector<T> &v) {
	for (auto it=v.begin();it!=v.end();++it) is >> *it;
	return is;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
	for (auto it=v.begin();it!=v.end();) os << *it, os << " \n"[++it==v.end()];
	return os;
}

template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) {
	return is >> p.first >> p.second;
}

template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) {
	return os << p.first << ' ' << p.second;
}
// }}}

// vim: fdm=marker


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define re(i,a,b) for(int i=(a);i<(b);i++)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define run(a) for(int k=head[a];k;k=e[k].ne)
#define v e[k].t
#define clr(a) memset(a,0,sizeof(a));
#define il inline
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back 
#define w1 first
#define w2 second
#define adm(a,b,c) {a=a+b;if(a>=c)a-=c;else if(a<0)a+=c;}
typedef double db;
typedef long long ll;typedef long double ld;typedef unsigned long long ull;
typedef pair<ll,ll> pa;
const int N=5e6+5,M=5e3+5,INF=1e9,mod=1e9+7;
const ll linf=1e18;const double eps=1e-8,pi=acos(-1);
il int gmin(int &a,int b){if(a>b)a=b;}il ll gmin(ll &a,ll b){if(a>b)a=b;}il int gmax(int &a,int b){if(a<b)a=b;}il ll gmax(ll &a,ll b){if(a<b)a=b;}
il void read(ll&x){ll f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il ll read(ll&x,ll&y){read(x);read(y);}
il void read(int&x){int f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il int read(int&x,int&y){read(x);read(y);}
il void read(int&a,int&b,int&c){read(a);read(b);read(c);}il void read(ll&a,ll&b,ll&c){read(a);read(b);read(c);}
il int read(){int x;read(x);return x;}
il ll qpow(ll a,ll b,ll p){ll ret=1;for(;b;b>>=1,a=a*a%p)if(b&1)ret=ret*a%p;return ret;}il ll qpow(ll a,ll b){ll ret=1;for(;b;b>>=1,a=a*a%mod)if(b&1)ret=ret*a%mod;return ret;}
il ll qmul(ll a,ll b,ll p){ll ret=0;for(;b;b>>=1,a=(a<<1)%p)if(b&1)adm(ret,a,p);return ret;}il ll qmul(ll a,ll b){ll ret=0;for(;b;b>>=1,a=(a<<1)%mod)if(b&1)adm(ret,a,mod);return ret;}
il void judge(){
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);}
double d1[N],x[N],dd1[M],xx[M];
int n=4;
void add(int i,int j){dd1[i]+=d1[j];xx[i]+=x[j];}
void golef(int y){
	re(i,0,y)add(i,i);
	if(y-1>0){add(y-1,y);add(y-1,y+1);}
	re(i,y,n+n-2)add(i,i+2);
}
void gorig(int y){
	re(i,0,y)add(i,i);
	re(i,y,n+n-2)add(i,i+2);
	add(y,y);add(y,y+1);
}
double gao(int n,double d,double x){
	if(!n)return 0;
	return gao(n-1,d+(2.0*d)/(n*2.0)+5.0*x/(n*2.0),x*(n+2)/n)+d+(0.0+n+n-1)*x/2;
}
int main(){double d,x;
	read(n);scanf("%lf%lf",&d,&x);
	printf("%.10lf",gao(n,d,x));
}
/*
int main(){n=read();
	 re(i,0,n+n)d1[i]=1,x[i]=i*1;
	 re(i,0,n){
	 	golef(i*2);
	 	gorig(i*2);
	 }
	 cout<<n<<endl;
	 re(i,0,n+n-2)printf("%lf %lf\n",dd1[i],xx[i]);
	 ;
}*/

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

string s;
string ans[4];

bool dfs(int sum, int i) {

    // cout << "ans: " << ans << "   sum: " << sum << "   i: " << i << endl;
    if (i == s.length())
        return sum == 7;
    if (dfs(sum + (s[i] - '0'), i + 1)) {
        ans[i] += "+";
        ans[i] += s[i];
        return true;
    }
    if (dfs(sum - (s[i] - '0'), i + 1)) {
        ans[i] += "-";
        ans[i] += s[i];
        return true;
    }
    return false;
}
int main() {
    cin >> s;
    ans[0] += s[0];
    if (dfs((s[0] - '0'), 1)) {
        for (int i = 0; i < 4; i++) {
            cout << ans[i];
        }
        cout << "=7" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0; i<(n); i++)
#define chmin(a,b) a = min(a,b)
#define chmax(a,b) a = max(a,b)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vv = vector<vi>;
using P  = pair<int,int>;

const ll INF = 1001001001;
const int MOD = 1000000007;

int main(){
    int n;
    cin>>n;
    
    vi a(n);
    
    rep(i,n)cin>>a[i];
    
    int ans = 0;
    
    for(int i=0; i<n; i+=2){
        if(a[i]%2)ans++;
    }
    
    cout << ans <<endl;
    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int n,m[7],s[7];
char c,cc;

int main(){
	while(cin>>n){
		fill(m,m+7,0);
		fill(s,s+7,0);
		int nn=n;
		while(nn--){
			cin>>c>>cc;
			if(c!=cc){m[c-'0']++;m[cc-'0']++;}
			else s[c-'0']++;
		}
		if(n==1){cout<<"Yes"<<endl;continue;}
		int od=0,f=1;
		for(int i=0;i<7;i++)if(m[i]%2)od++;
		if(od>2){cout<<"No"<<endl;continue;}
		for(int i=0;i<7;i++)if(s[i]&&!m[i]){cout<<"No"<<endl;f=0;break;}
		if(f)cout<<"Yes"<<endl;
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
int a[100010],b[100010];
int tmp[200010];
long long f[200010];
int main()
{
	int n;scanf("%d",&n);
	long long ans1=0,ans2=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d %d",&a[i],&b[i]);
		tmp[i*2-1]=a[i];tmp[i*2]=b[i];
		ans1+=a[i];ans2+=b[i];
	}
	sort(tmp+1,tmp+n*2+1);
	for(int i=1;i<=n*2;i++)
		f[i]=f[i-1]+tmp[i];
	long long ans=min(ans1,ans2);
	for(int i=1;i<=n;i++)
	{
		int pos1=lower_bound(tmp+1,tmp+n*2+1,a[i])-tmp;
		int pos2=lower_bound(tmp+1,tmp+n*2+1,b[i])-tmp;
		if(pos1>pos2)swap(pos1,pos2);
		if(pos2<=n)ans=min(ans,f[n]);
		else if(pos1<n)ans=min(ans,f[n-1]+tmp[pos2]);
		else ans=min(ans,f[n-2]+tmp[pos1]+tmp[pos2]);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <algorithm>
#define N 100010
using namespace std;
struct node{
	int id,num;
}a[N];
bool cmp(const node&a1,const node&a2){
	return a1.num<a2.num;
}
int main(){
	int n;scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i].num);
		a[i].id=i;
	}
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++)
		printf("%d ",a[i].id);
	return 0;
}

Measured memory_bytes: 1536
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstring>
#include <regex>
#include <sstream>

typedef long long ll;
constexpr double PI = 3.141592653589793;
constexpr int INF = 1e9 + 10;
constexpr ll INFL = 1e18 + 10;

template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}

struct edge
{
public:
    int to;
    int cost;
};

// O(|E|(log|V|))
void dijkstra(std::vector<int> &dist, const std::vector<std::vector<edge>> &graph, int s)
{
    typedef std::pair<int, int> P;
    std::priority_queue<P, std::vector<P>, std::greater<P>> pq;
    for (auto &e : dist)
    {
        e = INF;
    }

    dist[s] = 0;
    // P(distance from start, vertex index)
    pq.push(P(0, s));
    while (!pq.empty())
    {
        P cur = pq.top();
        pq.pop();
        int v = cur.second;
        int cost = cur.first;
        if (dist[v] < cost)
        {
            continue;
        }
        for (const auto &next : graph[v])
        {
            if (dist[next.to] > next.cost + dist[v])
            {
                dist[next.to] = next.cost + dist[v];
                pq.push(P(dist[next.to], next.to));
            }
        }
    }
}

void restorePath(
    std::vector<int> &path,
    const std::vector<int> &dist,
    const std::vector<std::vector<edge>> &graph,
    int e)
{
    int cur = e;
    path.push_back(e);
    while (dist[cur] != 0)
    {
        for (const auto &n : graph[cur])
        {
            if (dist[n.to] + n.cost == dist[cur])
            {
                path.push_back(n.to);
                cur = n.to;
                break;
            }
        }
    }
    std::reverse(path.begin(), path.end());
}

using namespace std;
//    cout << setprecision(20) << ans << "\n";

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

    string a, b;
    cin >> a >> b;

    if (a.size() > b.size()){
        cout << "GREATER"
             << "\n";
        return 0;
    }
    if (a.size() < b.size())
    {
        cout << "LESS"
             << "\n";
        return 0;
    }
    for (size_t i = 0; i < a.size(); i++)
    {
        if(a[i] - '0' > b[i] - '0'){
            cout << "GREATER"
                 << "\n";
            return 0;
        }
        if (a[i] - '0' < b[i] - '0')
        {
            cout << "LESS"
                 << "\n";
            return 0;
        }
    }
    cout << "EQUAL"
         << "\n";

    return 0;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
int main() {
    // your code goes here
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int n;
    cin>>n;
    set<pair<int,pair<int,int> > > a,b;
    for(int i=0;i<n;i++)
    {
    	int x,y;
    	cin>>x>>y;
    	a.insert(make_pair(x+y,make_pair(x,y)));
    	b.insert(make_pair(x-y,make_pair(x,y)));
    }
    vector<pair<int,int> > co;
    co.push_back((*a.begin()).second);
    co.push_back((*a.rbegin()).second);
    co.push_back((*b.begin()).second);
    co.push_back((*b.rbegin()).second);
    int ans=0;
    for(int i=0;i<4;i++)
    	for(int j=0;j<4;j++)
    	{
    		ans=max(ans,abs(co[i].first-co[j].first)+abs(co[i].second-co[j].second));
    	}
    cout<<ans;
    return 0;
}

Measured memory_bytes: 28576
#define _CRT_SECURE_NO_WARNINGS
//#define DEBUG
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

int main(void) {
#ifdef DEBUG
	printf("");
#endif
	int N;
	int tmp;
	int flag = 0;

	scanf("%d", &N);
	tmp = N % 10;
	if (tmp == 9) {
		flag = 1;
	}
	tmp = N / 10;
	if (tmp == 9) {
		flag = 1;
	}
	if (flag) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
}

Measured memory_bytes: 128
import math

n = int(input())
x = list(map(int,input().split()))

mod = 10**9 + 7

f = math.factorial(n-1)
f %= mod

def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

l = []
for i in range(n-1):
    d = x[i+1] - x[i]
    l.append(d)

# print(l)

count = 0
k = f
plus = 0
for i in range(1,n):
    # print(k)
    k = f + plus
    count += l[i-1] * k
    plus += f * modinv(i+1,mod)

print(int(count)%mod)


Measured memory_bytes: 15020
// https://atcoder.jp/contests/abc124/tasks/abc124_c

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String S = sc.next();
        char[] s = S.toCharArray();

        int even_0_count = 0;
        int even_1_count = 0;
        int odd_0_count = 0;
        int odd_1_count = 0;
        for (int i = 0; i < s.length; i++) {
            if (i % 2 == 0) {
                if (s[i] == '0') {
                    even_0_count++;
                } else {
                    even_1_count++;
                }
            }
            if (i % 2 == 1) {
                if (s[i] == '0') {
                    odd_0_count++;
                } else {
                    odd_1_count++;
                }

            }
        }

        int ans1 = even_1_count + odd_0_count;
        int ans2 = even_0_count + odd_1_count;

        int ans = ans1 < ans2 ? ans1:ans2;
        System.out.println(ans);
    }
}


Measured memory_bytes: 26532
#include <cstdio>
#include <algorithm>

using namespace std;

int N;
int L[105];

int main(){
    scanf("%d",&N);
    for(int i=0;i<N;i++) scanf("%d",L+i);

    int ans=0;
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            for(int k=j+1;k<N;k++){
                int temp[3]={L[i],L[j],L[k]};
                sort(temp,temp+3);
                if (temp[0]==temp[1]||temp[1]==temp[2]) continue;
                if (temp[0]+temp[1]<=temp[2]) continue;
                ans++;
            }
        }
    }

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


    return 0;
}

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

int main(){
    int N,T,A;
    cin>>N;
    cin>>T>>A;
    int H[N];
    for(int i=0;i<N;i++)cin>>H[i];
    double best=10000000;
    int ans=-1;
    for(int i=0;i<N;i++){
        if(best>fabs(A-(T-0.006*H[i]))){
            ans=i+1;
            best=min(best,fabs(A-(T-0.006*H[i])));
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.Collections;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int A = sc.nextInt();
    int B = sc.nextInt();
    int sum = 0;
    int total = 0;
    int tmp = 0;
    for (int i = 1; i <= N; i++) {
      sum = 0;
      tmp = i;
      while (tmp != 0) {
        sum += tmp % 10;
        tmp /= 10;
      }
      if (sum >= A && sum <= B) {
        total += i;
      }
    }
    System.out.println(total);
  }
}


Measured memory_bytes: 23892
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>

using namespace std;
using i64=long long int;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (auto &e: A) cin >> e;

    int ans = 0;
    i64 def = 0;
    vector<int> surs;
    surs.reserve(N);
    for (auto &&a: A) {
        int b;
        cin >> b;
        if (a < b) {
            def += b - a;
            ++ans;
        } else if (b < a) {
            surs.push_back(a-b);
        }
    }

    sort(surs.begin(), surs.end(), std::greater<int>());

    for (auto &e: surs) {
        if (def <= 0) break;
        def -= e;
        ++ans;
    }

    if (def <= 0) {
        cout << ans << endl;
    } else {
        cout << -1 << endl;
    }

    return 0;
}


Measured memory_bytes: 896
import bisect
import itertools
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

*perm, = itertools.permutations(list(range(1, n+1)), n)
a = bisect.bisect_right(perm, p)
b = bisect.bisect_right(perm, q)
print(abs(a-b))


Measured memory_bytes: 8052
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define loop(i, a, n) for(int i = (a); i < (n); i++)
#define all(x) x.begin(), x.end()
#ifdef _DEBUG
#define dd(x) cout << #x << " : " << x << endl
#else
#define dd(x)
#endif
using namespace std;
using ll = int64_t;

int main(){
    int n, k; cin >> n >> k;
    vector<int> p;
    rep(i, n) {
        int tmp; cin >> tmp;
        p.push_back(tmp);
    }

    sort(all(p));
    int ans = 0;
    rep(i, k) ans += p[i];
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3612
N, M, X = map(int, input().split())
A = list(map(int, input().split()))

# 左方向(1からX-1間)のコストを求める
left_cost = 0
for i in range(1, X):
    if i in A:
        left_cost += 1

# 右方向（X+1からN-1間）のコストを求める
right_cost = 0
for i in range(X+1, N):
    if i in A:
        right_cost += 1

if left_cost <= right_cost:
    print(left_cost)
else:
    print(right_cost)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
using namespace std;

// 文字列を半角スペース区切りで単語に分割する
// s = "This is a pen."
// vector<string> v = split_words(s); // v = {"This", "is", "a", "pen."}
vector<string> split_words(string s){
    bool flag = false;
    vector<string> vs;
    string str;
    s.push_back(' ');
    for(int i=0 ; i < s.size() ; i++ ){
        char c = s[i];
        if( flag == false ){
            if( c != ' ' ){
                flag = true;
                str.clear();
                str.push_back( c );
            }
        }else{
            if( c != ' ' ){
                str.push_back( c );
            }
            if( c == ' ' ){
                flag = false;
                vs.push_back( str );
                str.clear();
            }
        }
    }
    return vs;
}


int main(){
	int n;
	while( cin >> n , n ){
		cin.ignore();
		map<string,int> m;
		map<char,vector<string> > d;
		
		for(int i=0 ; i < n ; i++ ){
			string s;
			getline(cin,s);
			vector<string> vs = split_words(s);
			for(int j=0 ; j < vs.size() ; j++ ){
				s = vs[j];
				if( m.count(s) == 0 ){
					m[s] = 1;
				}else{
					m[s]++;
				}
				char c = s[0];
				if( count( d[c].begin() , d[c].end() , s ) == 0 ){
					d[c].push_back( s );
				}
			}
		}
		char c;
		cin >> c;
		vector<string> vs = d[c];
		if( vs.size() == 0 ){
			cout << "NA" << endl;
		}else{
			vector< pair<int,string> > v;
			for(int i=0 ; i < vs.size() ; i++ ){
				string s = vs[i];
				int num = -m[s];
				v.push_back( pair<int,string>(num,s) );
			}
			sort( v.begin() , v.end() );
			for(int i=0 ; i < 5 && i < v.size() ; i++ ){
				cout << v[i].second;
				if( i == v.size()-1 || i == 4 ){
					cout << endl;
				}else{
					cout << " ";
				}
			}
		}
	}
}

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

using namespace std;

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

const int MAXN = 60;

ll solve[2][2];
ll niz[MAXN];
int n,p;

void rek1(int congurent,int pos){
    if(pos==n/2){
        //cout<<congurent;
        solve[0][congurent]++;
        return;
    }
    rek1((congurent+niz[pos])&1,pos+1);
    rek1((congurent)&1,pos+1);
}

void rek2(int congurent,int pos){
    if(pos==n){
        solve[1][congurent]++;
        return;
    }
    rek2((congurent+niz[pos])%2,pos+1);
    rek2((congurent)%2,pos+1);
}

int main(){
    cin>>n>>p;
    REP(i,n)
        cin>>niz[i];
    rek1(0,0);
    rek2(0,n/2);
//    REP(i,2){
//        REP(j,2){
//            cout<<solve[i][j]<<" ";
//        }
//        cout<<endl;
//    }
    if(p==1)
        cout<<solve[0][0]*solve[1][1] + solve[0][1]*solve[1][0] ;
    else
        cout<<solve[0][0]*solve[1][0] + solve[0][1]*solve[1][1] ;
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
#import bisect #bisect.bisect_left(B, a)
from collections import defaultdict #d = defaultdict(int) d[key] += value
from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

N = ii()
A = li()
Q = ii()
B = li2(Q)

#a =　dict(Counter(A).most_common())
a = defaultdict(int)
for num in A:
    a[num] += 1
#print(a)
ans = sum(A)
for i in range(Q):
    if a[B[i][0]]:
        #print(a[B[i][1]])
        ans += (B[i][1]-B[i][0]) * a[B[i][0]]
        a[B[i][1]] += a[B[i][0]]
        a[B[i][0]] = 0
        print(ans)
    else:
        print(ans)

Measured memory_bytes: 40100
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  ll a, b;
  char op;
  cin >> a >> op >> b;
  if(op == '+') cout << a + b;
  else cout << a - b;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
#define SZ(x) ((int)(x).size)
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> Vl;
typedef vector<double> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<VS> VSS;  
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
// cout << << endl;
// cin >> ;
int main(){
    ll c=0,d=0,k=0,n,m,h,w,p,q,min,ans=0;
    string s,s1,s2;
    cin >> n;
    VI a(n);
    VI b(n);
    rep(i,n){
        cin >> a[i];
        b[i] = a[i];
    }
    sort(ALL(b));
    ll max = b[n-1];
    ll second = b[n-2];
    rep(i,n){
        if(a[i]<max)
            cout << max << endl;
        else if (a[i]==max) 
            cout << second << endl;
    }

    return 0;
}


Measured memory_bytes: 4736
n, a = map(int,input().split())
x = list(map(int,input().split()))

dp = [[[0] * n for i in range(n * a + 1)] for i in range(n)]
for i in range(n):
    for j in range(n * a + 1):
        for k in range(n):
            if i == 0 and x[0] < n * a + 1:
                dp[0][x[0]][0] = 1
                break
            else:
                if j == 0:
                    if k == 0 and x[i] < n * a + 1:
                        dp[i][x[i]][0] += 1
                    continue

                if dp[i - 1][j][k] == 0:continue
                dp[i][j][k] += dp[i - 1][j][k]
                if not(0 <= j + x[i] < n * a + 1):continue
                dp[i][j + x[i]][k + 1] += dp[i - 1][j][k]
cnt = 0
for i in range(n * a + 1):
    if i != 0 and i % a == 0:
        temp = i // a
        cnt += dp[-1][i][temp - 1]
print(cnt)


Measured memory_bytes: 101852
#include <iostream>
#include<vector>
#include<map>
using LL = long long;
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	int Q;
	cin >> Q;
	vector<int> B(Q), C(Q);
	for (int q = 0; q < Q; q++) {
		cin >> B[q] >> C[q];
	}
	map<int, int>M;
	LL sum = 0;
	for (int i = 0; i < N; i++) {
		M[A[i]]++;
		sum += A[i];
	}
	for (int q = 0; q < Q; q++) {
		int temp = M[B[q]];
		sum = sum + temp * (C[q] - B[q]);
		M[B[q]] = 0;
		M[C[q]] += temp;
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 8748
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.Deque;
   
public class Main {
     
    public static void main(String[] args) throws IOException {
        new Main().exec();
    }
     
    public void exec() throws IOException {
        SimpleInputUtil in = new SimpleInputUtil();
        PrintWriter out = new PrintWriter(System.out);
        out.print(new SectionDiagram().analyze(in.br.readLine()));
        out.flush();
    }
}

class SectionDiagram {
	public static final String EOF = System.lineSeparator();

	Deque<Integer> downhillDeque = new ArrayDeque<>();
	Deque<WaterHazardElement> waterHazardDeque = new ArrayDeque<>();
	int A = 0;
	int k = 0;
	StringBuilder sbL = new StringBuilder();
	
	public SectionDiagram analyze(String s) {
		int len = s.length();
		for(int i=0; i<len; i++) {
			switch(s.charAt(i)) {
			case '\\':
				downhillDeque.push(i);
				break;
			case '/':
				if(!downhillDeque.isEmpty()) {
					int start = downhillDeque.pop();
					WaterHazardElement wh = new WaterHazardElement(start,i);
					while(true) {
						if(!waterHazardDeque.isEmpty()){
							WaterHazardElement whPre = waterHazardDeque.getFirst();
							if(wh.include(whPre)) {
								wh.merge(whPre);
								waterHazardDeque.removeFirst();
							} else {
								waterHazardDeque.addFirst(wh);
								break;
							}
						}else{
							waterHazardDeque.addFirst(wh);
							break;
						}
					}
				}
				break;
			}
		}
		
		for(k=0; !waterHazardDeque.isEmpty(); k++){
			int c = waterHazardDeque.removeLast().getCapacity();
			A += c;
			sbL.append(" ").append(c);
		}
		return this;
	}
	
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append(A).append(EOF);
		sb.append(k).append(sbL).append(EOF);
		return sb.toString();
	}
	
}

class WaterHazardElement {
	int st = -1;
	int ed = -1;
	int childCapacity = 0;
	
	public WaterHazardElement(int st, int ed) {
		this.st = st;
		this.ed = ed;
	}
	
	public void merge(WaterHazardElement s) {
		childCapacity += s.getCapacity();
	}
	
	public int getCapacity() {
		return childCapacity + ed - st;
	}
	
	public boolean include(WaterHazardElement s) {
		return this.st < s.st && s.ed < this.ed;
	}
	
}
 
class SimpleInputUtil {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
    public String[] readStrArray(String delim) throws NumberFormatException, IOException{
        return br.readLine().split(delim);
    }
     
    public int readInt() throws NumberFormatException, IOException{
        return Integer.parseInt(br.readLine());
    }
     
    public int[] readIntArray(int[] a) throws NumberFormatException, IOException{
        int i=0;
        while(i<a.length) {
            for(String s: br.readLine().split(" ")){
                if(i<a.length) {
                    a[i++] = Integer.parseInt(s);
                }
            }
        }
        return a;
    }
 
     
}

Measured memory_bytes: 25680
#include <bits/stdc++.h>
#define REP(i,a,b) for(int(i)=(a);(i)<(b);++(i))
#define RREP(i,a,b) for(int(i)=(a)-1;(i)>=(b);--(i))
#define ALL(x) (x).begin(),(x).end()
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; }
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF = 1e9;
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

int H,W;
string A[1010];

int d[1010][1010];  // 最も近い#との距離

int main()
{
  cin >> H >> W;
  REP(i,0,H) cin >> A[i];
  // 最短距離を INF で初期化
  REP(x,0,H) REP(y,0,W) d[x][y] = INF;

  // ** BFS **
  // #の周りを#に変えていく
  queue<P> que;
  // #の座標をqueに追加していく
  REP(x,0,H) REP(y,0,W) {
    if (A[x][y] == '#') {
      d[x][y] = 0;
      que.push(P(x,y));
    }
  }

  while(que.size()) {  // while nonempty
    int x,y;
    tie(x,y) = que.front(); que.pop();

    REP(i,0,4) {
      int nx = x + dx[i];
      int ny = y + dy[i];
      // 訪れていないところのみ
      if (0 <= nx && nx < H && 0 <= ny && ny < W && d[nx][ny] == INF) {
        d[nx][ny] = d[x][y] + 1;
        que.push(P(nx,ny));
      }
    }
  }

  int maxi = -1;  //距離の最大値
  REP(x,0,H) REP(y,0,W) chmax(maxi, d[x][y]);
  cout << maxi << endl;

  return 0;
}


Measured memory_bytes: 13456
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#define rep(i, n) for (int i = 0; i < n; ++i)
using ll = long long;
using namespace std;
#define P pair<int, int>
int main () {
    int n;
    cin >> n;
    long long ans = 1;
    long long MX = 1000000000000000000;
    vector<long long >a(n);
    bool ng = false;
    rep(i,  n){
        cin >> a[i];
        if(a[i]==0){
            cout << 0 << endl;
            return 0;
        }
    }
    rep(i,  n){
        if( a[i] <= MX/ans){
            ans *= a[i];
        } else {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
    return 0 ;
}

Measured memory_bytes: 4044
using System;
using System.Linq;
using System.Collections.Generic;

public class Prime{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        //Console.WriteLine("{0}: {1}", n, string.Join(" ", PrimeFactors(n)));
		Console.WriteLine("{0}: {1}", n, string.Join(" ", PrimeFactors(n).Select (x => x.ToString()).ToArray())); //AOJ??¨
    }
     
    public static IEnumerable<int> PrimeFactors(int n)
    {
        int i = 2;
        int tmp = n;
         
        while (i * i <= n)
        {
            if(tmp % i == 0){
                tmp /= i;
                yield return i;
            }else{
                i++;
            }
        }
		if(tmp != 1) yield return tmp;
    }
}

Measured memory_bytes: 20288
# /usr/bin/python
# -*- coding: utf-8 -*-
#
import sys
import math


s = str(input())
n = len(s)
sn = []
cont = 1
for i in range(1,n):
  if s[i-1] != s[i]:
    sn.append(cont)
    cont = 1
  else:
    cont += 1
sn.append(cont)

# ->
sm_l = 0
for i in sn:
  if sm_l < (n+1)//2:
    sm_l += i

# <-
sn = reversed(sn)
sm_r = 0
for i in sn:
  if sm_r < (n+1)//2:
    sm_r += i

print(min(sm_l,sm_r))

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

using namespace std;

ll mod = 1000000007;

template<class Type> inline bool chmax(Type& a, Type b) { if (a < b) { a = b; return 1; } return 0; }
template<class Type> inline bool chmin(Type& a, Type b) { if (a > b) { a = b; return 1; } return 0; }

template<class Type>
Type modpow(Type a, Type n, Type mod)
{
	Type res = 1;
	while (0 < n)
	{
		if (n & 1)
		{
			res = res * a % mod;
		}
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

template<class Type>
Type gcd(Type x, Type y)
{
	Type r;
	if (x < y)
	{
		swap(x, y);
	}

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

template<class Type>
bool isPrime(Type x)
{
	if (x == 2) return true;
	if (x < 2 || x % 2 == 0) return false;

	for (Type i = 3; i <= sqrt(x); i += 2)
	{
		if (x % i == 0) return false;
	}
	return true;
}

template<class Type>
vector<bool> eratos(Type n)
{
	vector<bool> isPrime(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	for (Type i = 2; i <= n; i++)
	{
		if (isPrime[i])
		{
			Type j = i + i;
			while (j <= n)
			{
				isPrime[j] = false;
				j = j + i;
			}
		}
	}
	return isPrime;
}

bool binarySearchJudge(vector<int> a, int index, int key)
{
	if (key <= a[index]) return true;
	else return false;
}

int binarySearch(vector<int> a, int key)
{
	int ng = -1;
	int ok = a.size();
	while (1 < abs(ng - ok))
	{
		int mid = (ng + ok) / 2;
		if (binarySearchJudge(a, mid, key)) ok = mid;
		else ng = mid;
	}
	return a[ok] == key;
}

int main()
{
	string s;
	cin >> s;
	for (int i = 0; i < 4; i++)
	{
		cout << s[i];
	}
	cout << " ";
	for (int i = 4; i < s.size(); i++)
	{
		cout << s[i];
	}
	cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
int n,c,a[410],b[410],sum[410][410],dp[410][410];
signed main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>n>>c;
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    for(int i=1;i<=400;i++){
        sum[i][0]=1;
        for(int j=1;j<=400;j++){
            sum[i][j]=sum[i][j-1]*i%mod;
        }
    }
    for(int j=0;j<=400;j++){
        for(int i=1;i<=400;i++){
            sum[i][j]+=sum[i-1][j];
            sum[i][j]%=mod;
        }
    }
    dp[0][0]=1;
    rep(i,n){
        rep(j,c+1){
            rep(k,j+1){
                dp[i+1][j]+=dp[i][j-k]*(sum[b[i]][k]-sum[a[i]-1][k]+mod)%mod;
                dp[i+1][j]%=mod;
            }
        }
    }
    cout<<dp[n][c]<<endl;
    return 0;
}

Measured memory_bytes: 6104
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll a,b,t;
	ll sum=0;
	
	cin>>a>>b>>t;
	ll x=a;
	while(a<=t)
	{
		sum+=b;
		a=a+x;
	}
	cout<<sum;
}

Measured memory_bytes: 256
function Main(input) {
  input=input.split("\n");
  if(input[input.length-1]===''){
    input.pop();
  }
  const N=input[0].split(' ')[0]-0;
  const P=input[1].split(' ').map(e=>{
    return e-0;
  });
  var min=Infinity;
  var ret=0;
  P.forEach(e=>{
    if(min>=e){
      ret++;
      min=e;
    }
  });
  console.log(ret);
}


//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
  



  


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


const int maxn = 1e6+5;
//int k[34] = {0,1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main(){
    ll h, w; cin >> h >> w;
    ll sum = 0;
    if(h==1||w==1) cout << 1 << endl;
    else{
    sum += h/2*w;
    if(h&1ll) {
        if(w&1ll) sum += w/2+1;
        else sum += w/2;
    }
    cout << sum << endl;
    }
}


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

int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    int cnt=1,i;
    char ch=s[0];
    for(i=1; i<s.size(); i++)
    {
        if(s[i]!=ch)
        {
            cnt++;
            ch=s[i];
        }
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 512
N, K = map(int,input().split())
ans = 0.0
for i in range(1,N+1,1):
    count = 0
    tmp = i
    if tmp < K:
        while True:
            tmp *= 2
            count += 1
            if tmp>=K:
                break
    ans += float(1/N)*(0.5**count)
print(ans)

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

int main() {
  int a, b, ans;
  string s;
  cin >> a >> b;
  ans = 0;
  for (int i = a; i <= b; i++) {
    s = to_string(i);
    for (int j = 0; j <= s.length() / 2; j++) {
      if (s[j] != s[s.length() - j - 1]) break;
      if (j == s.length() / 2) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
li = list(map(int,input().split()))
li.sort(reverse = True)
count = 0
for i in range(1,n+1):
    count = 0
    while True:
        if li:
            if li[-1]==i:
                count+=1
                li.pop()
            else:
                break
        else:
            break
    print(count)

Measured memory_bytes: 92288
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
const int P = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int n, m;
char s[MAXN];
void update(int &x, int y) {
	x += y;
	if (x >= P) x -= P;
}
int main() {
	read(n), read(m);
	scanf("%s", s + 1);
	bool same = true;
	for (int i = 1; i <= m; i++)
		if (s[i] != s[1]) same = false;
	if (same) {
		static int dp[MAXN], sum[MAXN];
		dp[1] = sum[1] = 1;
		for (int i = 2; i <= n; i++) {
			dp[i] = sum[i - 2];
			sum[i] = (sum[i - 1] + dp[i]) % P;
		}
		int ans = (sum[n - 1] + 1) % P;
		for (int i = 2, j = n - 1; i <= n; i++, j--)
			update(ans, sum[j]);
		printf("%d\n", ans);
		return 0;
	}
	if (n & 1) {
		puts("0");
		return 0;
	}
	int Min = n - (n - 1) % 2;
	int last = 0;
	for (int i = 1; i <= m; i++)
		if (s[i] != s[1]) {
			int len = i - last - 1;
			if (last == 0) chkmin(Min, len + 1);
			if (len % 2 == 1) chkmin(Min, len);
			last = i;
		}
	static int dp[MAXN], sum[MAXN];
	dp[1] = sum[1] = 1;
	for (int i = 2; i <= n; i++) {
		if (i % 2 == 1) {
			dp[i] = sum[i - 2];
			update(dp[i], P - sum[max(i - Min - 3, 0)]);
		}
		sum[i] = (sum[i - 1] + dp[i]) % P;
	}
	int ans = (sum[n - 1] - sum[max(n - Min - 2, 0)] + P) % P;
	for (int i = 2, j = n - 1; i <= n && j >= n - Min - 2; i++, j--)
		update(ans, (sum[j] - sum[max(n - Min - 2, 0)] + P) % P);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,x,f=0;
    vector<long long int>v;
    cin>>n;
    map<long long int,long long int>m;
    for(long long int i=0; i<n; i++)
    {
        cin>>x;
        v.push_back(x);
        m[x]++;
    }

    long long int ans=0;
    map<long long int,long long int>::iterator it;
    for(it=m.begin(); it!=m.end(); it++)
    {
        x=it->second;
        ans+=x*(x-1)/2;
    }
    for(long long int i=0; i<n; i++)
    {
        cout<<ans-(m[v[i]]-1)<<endl;
    }
    return 0;
}


Measured memory_bytes: 11120
n,m = map(int,input().split())

if n == 1 and m == 1:
    print(1)
elif n == 1:
    print(max(0,m-2))
elif m == 1:
    print(max(0,n-2))
else:
    a = max(0,m-2)
    b = max(0,n-2)
    print(a*b)










Measured memory_bytes: 3060
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0}; 
int r,c;
string s[1005]; 
bool vis[1001][1001];

bool ok(int i,int j){
    if (i<0 or i>=r or j<0 or j>=c or vis[i][j] or s[i][j]=='#') return false;
    return true;
}

map <pii,int> dis; 


inline void solve(){
    cin >> r >> c ; 
    queue <pii> q;
    for (int i=0;i<r;i++){
        cin >> s[i];
        for (int j=0;j<c;j++){
            if (s[i][j] == '#') {
              q.push({i,j}); 
            }
        }
    }
    int ans=0;
    while (q.size()){
        int x=q.front().ff;
        int y=q.front().ss;
        q.pop();
        for (int i=0;i<4;i++){
            int a=x+dx[i];
            int b=y+dy[i];
            if (ok(a,b)){
                q.push({a,b});
                vis[a][b] = true;
                dis[{a,b}] = dis[{x,y}]+1;
                ans = max(ans,dis[{a,b}]);
            }
        }
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 69008
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	ll n, k;
	cin >> n>> k;
	if(k==0){
		cout << n*n << endl;
		return 0;
	}

	ll ans=0;
	for(int i=k+1; i<=n; i++){
		ans+=(n/i)*(i-k)+max(0ll, n%i-k+1);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
xyc = [[int(i) for i in input().split()] for _ in range(N)]

def check(n) :
  for i in range(N) :
    xi, yi, ci = xyc[i]
    ri = n / ci
    for j in range(i + 1, N) :
      xj, yj, cj = xyc[j]
      xj -= xi
      yj -= yi
      rj = n / cj
      a = (xj ** 2 + yj ** 2 + ri ** 2 - rj ** 2) / 2
      root = max(0, (xj ** 2 + yj ** 2) * (ri ** 2) - a ** 2) ** 0.5
      for sgn in [1, -1] :
        cnt = 0
        X = (a * xj + sgn * yj * root) / (xj ** 2 + yj ** 2) + xi
        Y = (a * yj - sgn * xj * root) / (xj ** 2 + yj ** 2) + yi
        for x, y, c in xyc :
          if (x - X) ** 2 + (y - Y) ** 2 <= (n / c) ** 2 + eps :
            cnt += 1
        if cnt >= K :
          return True
  
  for X, Y, _ in xyc :
    cnt = 0
    for x, y, c in xyc :
      if (x - X) ** 2 + (y - Y) ** 2 <= (n / c) ** 2 + eps :
        cnt += 1
    if cnt >= K :
      return True
      
  return False

eps = 1e-8
ng, ok = 0, 10 ** 6
while ok - ng > eps :
  n = (ng + ok) / 2
  if check(n) :
    ok = n
  else :
    ng = n
 
print(ok)

Measured memory_bytes: 52188
n = input()
x = int(n[-1])
if x == 2 or x == 4 or x == 5 or x == 7 or x == 9:
	print("hon")
elif x == 0 or x == 1 or x == 6 or x == 8:
	print("pon")
else:
	print("bon")

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

int main(void){
  int n;
  while(cin >> n, n){
    vector<long long> cust;
    for(int i=0; i < n; i++){
      int tmp; cin >> tmp;
      cust.push_back(tmp);
    }
    sort(cust.begin(), cust.end());
    vector<long long> waiting(n, 0);
    for(int i=1; i < n; i++){
      waiting[i] = waiting[i-1] + cust[i-1];
    }
    long long ans = 0;
    for(int i=0; i < n; i++){
      ans += waiting[i];
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1340
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define all(n)      (n).begin(), (n).end()
#define ll long long
#define ull unsigned long long int
void solve() {

    int n; cin >> n;
    vector<int> v(n+1);
    vector<int> dp(n+1);
    for(int i=1; i <= n; i++){
        cin >> v[i];
    }
    dp[0] = dp[1] = 0;
    
    dp[2] = abs(v[1]-v[2]);
    for(int i = 3; i <= n; i++){
        int a = abs(v[i-2] - v[i]);
        int b = abs(v[i-1] - v[i]);
        dp[i] = min(dp[i-2] + a, dp[i-1] + b);
    }
    cout << dp[n] << endl;
    
}
int main(){
    // ios::sync_with_stdio(0);
    // cin.tie(0);
    //Starts here , 
                
        solve();
    return 0;
            
}

Measured memory_bytes: 3996
#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>
#include <memory.h>
#include <assert.h>
#include<limits.h>


#define eps 1e-8
#define PI 3.141592653589793
#define bsize 512

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define bs 1000000007

using namespace std;

int longestCommonSubsequence(string s1, string s2, vector<vector<int>>& dp) 
{
    for (int i = 1; i <= s1.size(); i++) 
    {
        for (int j = 1; j <= s2.size(); j++) 
        {
            if (s1[i-1] == s2[j-1]) 
                dp[i][j] = dp[i-1][j-1] + 1;

            dp[i][j] = max({dp[i][j], dp[i][j-1], dp[i-1][j]});
        }
    }
    return dp[s1.size()][s2.size()];
}

int main()
{
    ios_base::sync_with_stdio(false) ;
    cin.tie(NULL) ;
    cout.tie(NULL) ;
    
    string s1, s2; 
    cin >> s1 >> s2;

    vector<vector<int>> dp(s1.size()+1, vector<int>(s2.size()+1, 0));
    int count = longestCommonSubsequence(s1, s2, dp);   // This will give count of lcs and change the dp vector

    string s = "";
    int i = s1.size(), j = s2.size();
    while (i > 0 && j > 0) 
    {
        if (dp[i-1][j-1] + 1 == dp[i][j] && dp[i-1][j] + 1 == dp[i][j] && dp[i][j-1] + 1 == dp[i][j]) 
        {
            i--; 
            j--; 
            s = s1[i] + s; //As we are travelling backward reverse the string
        }
        else if (dp[i][j-1] > dp[i-1][j]) 
            j--;
        else
            i--;
    }
    cout << s << endl;

    return 0;
}

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

vector<ll> v[100010];
vector<pll> v1;

multiset<ll> st1,st2,st3,st4;

int cnt[100010],n,m;

inline int rd()
{
	int x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

inline void print(ll x)
{
	static char s[233];
	if (x<0) putchar('-'),x=-x;
	if (!x) { putchar('0');putchar('\n');return; }
	int tot=0;
	for (;x;x/=10) s[++tot]=x%10+'0';
	for (;tot;tot--) putchar(s[tot]);
	putchar('\n');
}

int main()
{
	n=rd();m=rd();
	for (int i=1;i<=n;i++)
	{
		int x=rd(),y=rd();
		v[x].push_back(y);
	}
	for (int i=1;i<=m;i++)
	{
		sort(v[i].begin(),v[i].end());reverse(v[i].begin(),v[i].end());
		ll hh=v[i][0]+v[i][1];
		v[i][0]=v[i][1]=hh;
		for (int j=2;j<v[i].size();j++) v[i][j]*=2;
		for (int j=0;j<v[i].size();j++) v1.push_back(pll(v[i][j],i));
	}
	sort(v1.begin(),v1.end());reverse(v1.begin(),v1.end());
	for (int i=1;i<=m;i++) if (v[i].size()>=3) st4.insert(v[i][0]+v[i][1]+v[i][2]);
	ll sum=0;
	for (int i=1;i<=n;i++)
	{
		pll hh=v1[i-1];
		ll x=hh.second,y=hh.first,ans=-2;
		if (!cnt[x])
		{
			if (st1.size()) ans=max(ans,sum+*st1.rbegin());
			if (st2.size()) ans=max(ans,sum-*st2.begin()+y*2);
			if (st3.size()&&st4.size()) ans=max(ans,sum-*st3.begin()+*st4.rbegin());
			if (v[x].size()>=3) st4.erase(st4.find(v[x][0]+v[x][1]+v[x][2]));
			st3.insert(y*2);
			if (v[x].size()>2) st1.insert(v[x][2]);
			cnt[x]=1;sum+=y*2;
			print(ans/2);print(sum/2);
		}
		else if (cnt[x]>1)
		{
			sum+=y;ans=sum;
			if (cnt[x]==2) st3.erase(st3.find(v[x][0]*2));
			if (cnt[x]>2) st2.erase(st2.find(v[x][cnt[x]-1]));
			st2.insert(v[x][cnt[x]]);st1.erase(st1.find(v[x][cnt[x]]));
			if (cnt[x]+1<v[x].size()) st1.insert(v[x][cnt[x]+1]);
			cnt[x]++;
			print(ans/2);
		}
		else cnt[x]++;
	}
	return 0;
}

Measured memory_bytes: 17540