akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

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

using namespace std;

struct point{
	int x,y;
	bool operator<(const point &a)const{ return x!=a.x?x<a.x:y<a.y; }
};
bool cmp_y(const point &a,const point &b){ return a.y!=b.y?a.y<b.y:a.x<b.x; }

int D;
set<point> S;

map<int,set<int>> XtoY,YtoX; // XtoY: x -> (y-coordinate of points which have x-coordinate x)
map<int,vector<int>> XtoY2,YtoX2; // same as above (use vector instead of set)

long long ans=0;

void dfs(point p){
	int x=p.x,y=p.y;
	set<point> next;

	// (x-D, y)
	if(XtoY.count(x-D)>0){
		auto &Y=XtoY[x-D];
		for(auto it=Y.lower_bound(y-D);it!=Y.end()&&*it<=y+D;++it){
			next.emplace(point{x-D,*it});
		}
		auto &Y2=XtoY2[x-D];
		int l=lower_bound(Y2.begin(),Y2.end(),y-D)-Y2.begin();
		int r=upper_bound(Y2.begin(),Y2.end(),y+D)-Y2.begin();
		ans+=r-l;
	}

	// (x+D, y)
	if(XtoY.count(x+D)>0){
		auto &Y=XtoY[x+D];
		for(auto it=Y.lower_bound(y-D);it!=Y.end()&&*it<=y+D;++it){
			next.emplace(point{x+D,*it});
		}
		auto &Y2=XtoY2[x+D];
		int l=lower_bound(Y2.begin(),Y2.end(),y-D)-Y2.begin();
		int r=upper_bound(Y2.begin(),Y2.end(),y+D)-Y2.begin();
		ans+=r-l;
	}

	// (x, y-D)
	if(YtoX.count(y-D)>0){
		auto &X=YtoX[y-D];
		for(auto it=X.lower_bound(x-D);it!=X.end()&&*it<=x+D;++it){
			next.emplace(point{*it,y-D});
		}
		auto &X2=YtoX2[y-D];
		int l=lower_bound(X2.begin(),X2.end(),x-D)-X2.begin();
		int r=upper_bound(X2.begin(),X2.end(),x+D)-X2.begin();
		ans+=r-l;
	}

	// (x, y+D)
	if(YtoX.count(y+D)>0){
		auto &X=YtoX[y+D];
		for(auto it=X.lower_bound(x-D);it!=X.end()&&*it<=x+D;++it){
			next.emplace(point{*it,y+D});
		}
		auto &X2=YtoX2[y+D];
		int l=lower_bound(X2.begin(),X2.end(),x-D)-X2.begin();
		int r=upper_bound(X2.begin(),X2.end(),x+D)-X2.begin();
		ans+=r-l;
	}

	if(S.count({x-D,y-D})>0) ans--;
	if(S.count({x+D,y-D})>0) ans--;
	if(S.count({x-D,y+D})>0) ans--;
	if(S.count({x+D,y+D})>0) ans--;

	// delete next vertices from XtoY and YtoX
	for(point q:next){
		XtoY[q.x].erase(q.y);
		YtoX[q.y].erase(q.x);
	}

	for(point q:next) dfs(q);
}

int main(){
	int n,a,b; scanf("%d%d%d",&n,&a,&b); a--; b--;
	vector<point> P(n);
	rep(i,n){
		int x,y; scanf("%d%d",&x,&y);
		P[i]={x+y,x-y};
		S.emplace(P[i]);
	}
	D=max(abs(P[a].x-P[b].x),abs(P[a].y-P[b].y));

	{ // calc XtoY and XtoY2
		auto Q=P;
		sort(Q.begin(),Q.end());
		int pre=0;
		rep(i,n) if(i==n-1 || Q[i].x<Q[i+1].x) {
			vector<int> tmp;
			for(int j=pre;j<=i;j++) tmp.emplace_back(Q[j].y);
			XtoY[Q[i].x]=set<int>(tmp.begin(),tmp.end());
			XtoY2[Q[i].x]=tmp;
			pre=i+1;
		}
	}

	{ // calc YtoX and YtoX2
		auto Q=P;
		sort(Q.begin(),Q.end(),cmp_y);
		int pre=0;
		rep(i,n) if(i==n-1 || Q[i].y<Q[i+1].y) {
			vector<int> tmp;
			for(int j=pre;j<=i;j++) tmp.emplace_back(Q[j].x);
			YtoX[Q[i].y]=set<int>(tmp.begin(),tmp.end());
			YtoX2[Q[i].y]=tmp;
			pre=i+1;
		}
	}

	XtoY[P[a].x].erase(P[a].y);
	YtoX[P[a].y].erase(P[a].x);

	dfs(P[a]);
	cout<<ans/2<<endl;

	return 0;
}


Measured memory_bytes: 59888
def main():
    import sys
    input = sys.stdin.readline
    
    N = int(input())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    C = list(map(int,input().split()))
    
    A = sorted(A) + [float("inf")]
    B = sorted(B) + [float("inf")]
    C = sorted(C) + [float("inf")]
    
    b, c = 0, 0
    BC = []
    while b < N:
        if B[b] < C[c] or c == N:
            BC.append(N-c)
            b += 1
        else:
            c += 1
    for i in range(N-1):
        BC[N-2-i] += BC[N-1-i]
    
    a, b = 0, 0
    AB = []
    while a < N:
        if b == N:
            AB.append(N)
            a += 1
        elif A[a] < B[b]:
            AB.append(b)
            a += 1
        else:
            b += 1
            
    ans = 0
    BC += [0]
    for i in range(N):
        ans += BC[AB[i]]
    #print(AB,BC)
    print(ans)

            
    
    
main()

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

bool s[200050];
bool d[200050];
set<pair<int, int>> e;
int n, m, a, b;

int main() {
  cin >> n >> m;
  rep(i, m) {
    cin >> a >> b;
    if (a == 1) s[b] = true;
    if (b == n) d[a] = true;
  }

  for (int i = 0; i < 200009; ++i) {
    if (s[i] && d[i]) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}

Measured memory_bytes: 640
/*input

*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

int main()
{
	IOS;
	int d;
	cin>>d;
	cout<<"Christmas";
	while(d<25){
		cout<<" Eve";
		d++;
	}
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>

using namespace std;

int main()
{
	int n, m, a;
	while(1){
		cin >> n >> m >> a;
		if(n == 0 && m == 0 && a == 0) break;
		int amida[1001][101] = {0};
		int h, p, q, max_h = 0;
		for(int i = 0; i < m; i++){
			cin >> h >> p >> q;
			amida[h][p] = 1;
			amida[h][q] = -1;
			if(h > max_h) max_h = h;
		}
		pair<int, int> dot;
		dot.first = max_h+1;
		dot.second = a;
		while(1){
			if(dot.first == 0) break;
			else if(amida[dot.first][dot.second] == 1){
				(dot.second)++;
				amida[dot.first][dot.second] = 0;
			} else if(amida[dot.first][dot.second] == -1){
				(dot.second)--;
				amida[dot.first][dot.second] = 0;
			} else {
				(dot.first)--;
			}
		}
		cout << dot.second << endl;
	}
	return 0;
}

Measured memory_bytes: 1560
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

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

#define MOD 1000000007

void solve(int test_case) {
	char c;
	cin>>c;
	if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u') cout<<"vowel";
	else cout<<"consonant";
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3652
#include<stdio.h>
int main()
{
    int sum = 0;
    char S[3];
    char T[3];


    scanf("%s",S);
    scanf("%s", T);

    for (int i = 0; i < 3; i++){
        if (S[i] == T[i]) sum++;
    }
    printf("%d\n", sum);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main ()
{
	int a,dr,ir;
	cin>>a>>dr;
	if(a>=10)
	{
		ir=dr;
	}
	if(a<10)
	{
		ir=dr+100*(10-a);
	}
	cout<<ir;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
D = list(map(int, input().split()))
M = 998244353
from collections import Counter

if D[0] != 0:
    print(0)
    exit(0)

cd = Counter(D)
if cd[0] != 1:
    print(0)
    exit(0)

tmp = sorted(cd.items(), key=lambda x: x[0])

ans = 1


for kx in range(1, max(D)+1):
    ans *= pow(cd[kx-1], cd[kx],M)
    ans %= M

print(ans)


Measured memory_bytes: 26648
x,y=map(int,input().split())

def cmb(n, r, m,g1,g2):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % m

def nCrMOD(n,r,m):
    g1 = [1, 1]
    g2 = [1, 1]
    inverse = [0, 1]
    for i in range( 2, n + 1 ):
        g1.append( ( g1[-1] * i ) % m )
        inverse.append( ( -inverse[m % i] * (m//i) ) % m )
        g2.append( (g2[-1] * inverse[-1]) % m )
    return cmb(n,r,m,g1,g2)
  
if (x+y)%3!=0:
    print(0)
else:
    n=(x+y)//3
    r=x-n
    mod=10**9+7
    print(nCrMOD(n,r,mod))

Measured memory_bytes: 118764
from collections import deque

H,W=map(int,input().split())
H-=1
W-=1
maze=[]
for i in range(H+1):
   S=input()
   S=[c for c in S]
   maze.append(S)

maze[0][0]="S"

count=0
for i in range(H+1):
   for j in range(W+1):
      if maze[i][j]=="#":
         count+=1

que=deque([[0,0]])
steps=[[-1]*(W+1) for i in range(H+1)]
steps[0][0]=0
flag=True

def bfs():
      global flag
      if len(que)>=1:
         now=que.popleft()
         now_step=steps[now[0]][now[1]]
         for dx,dy in (0,-1),(1,0),(0,1),(-1,0):
               ny=now[0]+dy
               nx=now[1]+dx
               if 0<=ny<=H and 0<=nx<=W:
                     if ny==H and nx==W:
                           print((H+1)*(W+1)-(now_step+1+1)-(count))
                           flag=False
                           break
                     elif maze[ny][nx]==".":
                           maze[ny][nx]="A"
                           que.append([ny,nx])
                           steps[ny][nx]=now_step+1
                     else:
                           pass
      else:
         print(-1)
         flag=False

while(flag):
      bfs()

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

using namespace std;

int a[100];

int main(){

    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; ++i)
        scanf("%d", &a[i]);
    sort(a, a + n);
    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){
                if(a[i] == a[j] || a[j] == a[k] || a[i] == a[k])
                    continue;
                if(a[i] + a[j] > a[k])
                    ++ans;
                else
                    break;
            }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int cnt=0,A,Z;
	bool pand=false;
	for(int i=0;i<s.size();i++)
		if(s[i]=='A')
		{
			A=i;
			break; 
		}
	for(int i=s.size()-1;i>=0;i--)
		if(s[i]=='Z')
		{
			Z=i;
			break;
		}
	cout<<Z-A+1;
	return 0;

}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

int n, x, maxim, s;

int main()
{
    cin >> s >> n;
    for (int i=1;i<=n;i++)
    {
        cin >> x;
        if (x > maxim)
            maxim = x;
    }
    int restul = s-maxim;
    if (restul < maxim)
        cout << maxim-restul-1;
    else cout << 0;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N (int)1e5

int partition(int[], int, int);

int main()
{
  int i,j;
  int n;
  int A[N+1];

  scanf("%d",&n);

  for(i = 0;i < n;i++){
    scanf("%d",&A[i]);
  }
  
  j = partition(A, 0, n-1);

  for(i = 0;i < n;i++){
    if(i) printf(" ");
    
    if(i == j){
      printf("[%d]",A[i]);
    }
    else printf("%d",A[i]);
  }
  printf("\n");
  
  return 0;
}

int partition(int A[], int p, int r)
{
  int i,j;
  int x;
  int temp;
  
  x = A[r];
  i = p-1;
  for(j = p; j < r;j++){
    if(A[j] <= x){
      i++;
      temp = A[i];
      A[i] = A[j];
      A[j] = temp;
    }
  }
  temp = A[i+1];
  A[i+1] = A[r];
  A[r] = temp;
  
  return i+1;
}



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

using namespace std;

int main(){
    int n,l;
    
    cin >> n >> l;

    vector<string> list(n);
    string str;
    for(int i=0;i<n;i++){
        cin >> list[i];
    }
    sort(list.begin(),list.end());
    for(int i=0;i<n;i++){
        cout << list[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
	int n;
	cin >> n;

	int count4 = 0;
	int count2 = 0;

	for(int i =0; i < n; i++) {
		int a;
		cin >> a;
		if (a % 4 == 0) {
			count4++;
		} else if (a % 2 == 0) {
			count2++;
		}
	}

	if (n == count2) {
		cout << "Yes" << endl;
		return 0;
	}

	int use2 = n;
	if (count2 > 0) {
		use2 -= count2 - 1;
	}


	if (count4 >= use2 / 2) {
		cout << "Yes";
	} else {
		cout << "No";
	}
	cout << endl;
	return 0;
}

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

using namespace std;

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

  int n; cin >> n;
  int h[n];
  for(int i = 0; i<n; ++i) cin >> h[i];

  vector<int> dp(n, INT_MAX);
  dp[0] = 0;
  for(int i = 0; i<n; ++i) {
    if(i != n-1) {
      dp[i+1] = min(dp[i+1], dp[i]+abs(h[i] - h[i+1]));
    }
    if(i != n-2) {
      dp[i+2] = min(dp[i+2], dp[i]+abs(h[i] - h[i+2]));
    }
  }
  cout << dp[n-1] << endl;
}


Measured memory_bytes: 1024
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int n, m, x;
int main() {
	cin >> n >> m;
	vector<pair<int, int> > w(n);
	for (int i = 0; i < n; i++) w[i] = make_pair(1, i + 1);
	for (int i = 0; i < m; i++) {
		cin >> x; --x;
		w[x].first = -i;
	}
	sort(w.begin(), w.end());
	for (int i = 0; i < n; i++) cout << w[i].second << endl;
	return 0;
}

Measured memory_bytes: 4408
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;


int c[10][10] = {}, dist[10][10] = {};
int H, W, A[200][200];

int main(){
    cin >> H >> W;
    for(int i = 0; i < 10; i++){
        for(int j = 0; j < 10; j++){
            cin >> c[i][j];
            dist[i][j] = c[i][j];
        }
    }

    for(int i = 0; i < 10; i++){
        dist[i][i] = 0;
    }
    
    for(int k = 0;  k < 10; k++){
        for(int i = 0; i < 10; i++){
            for(int j = 0; j < 10; j++){
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

    long long ans = 0;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> A[i][j];
            if(A[i][j] != -1){
                ans += dist[A[i][j]][1];
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    ll X;
    cin >> X;
    ll t500 = X / 500;
    X -= t500*500;
    ll t5 = X / 5;
    X -= t5*5;
    pr(t500*1000+t5*5); 
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
template<class T>
long merge(T* xs, int l, int m, int r){
    long cnt = 0;
    auto temp = new T[r-l];
    int c1 = l, c2 = m;
    int idx = 0;

    while(c1 < m || c2 < r){
        if(c1 == m){
            temp[idx] = xs[c2++];
        } else if(c2 == r){
            temp[idx] = xs[c1++];
        } else if(xs[c1] <= xs[c2]){
            temp[idx] = xs[c1++];
        } else {
            cnt += m-c1;
            temp[idx] = xs[c2++];
        }
        ++idx;
    }
    for(int i = l; i < r; ++i){
        xs[i] = temp[i-l];
    }
    return cnt;
}

template<class T>
long inversion(T* xs, int l, int r){
    long cnt = 0;
    if(l+1 < r){
        int m = (l+r)/2;
        cnt += inversion(xs, l, m);
        cnt += inversion(xs, m, r);
        cnt += merge(xs, l, m, r);
    }
    return cnt;
}

int main(){
    int n;
    cin >> n;
    int xs[n];
    for(int i = 0; i < n; ++i){
        scanf("%d", &xs[i]);
    }
    cout << inversion(xs, 0, n) << endl;
}

Measured memory_bytes: 19484
/*IN THE NAME OF ALLAH*/
#include<bits/stdc++.h>
using namespace std;
const int M = 30;
int num[M];
bool mark[M];
map <char,int> m;
char a[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()
{
	string s;
	cin>>s;
	for(int i=0;i<26;i++)
		m[a[i]] = i;
	for(int i=0;i<(int)s.size();i++)
	{
		mark[m[s[i]]] = true;
		num[m[s[i]]] = i;
	}
	for(int i=0;i<26;i++)
	{
		if(!mark[i])
		{
			cout<<s<<a[i]<<"\n";
			return 0;
		}
	}
	for(int i=(int)s.size() - 1;i>=0;i--)
	{
		for(int j=m[s[i]]+1;j<26;j++)
		{
			if(num[j] > i)
			{
				for(int k=0;k<i;k++)
					cout<<s[k];
				cout<<a[j]<<"\n";
				return 0;
			}
		}
	}
	cout<<"-1\n";
	return 0;
}

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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define endl        "\n"
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) 	for(int i=a;i<=b;i++)
#define IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int N=2005;

char a[N][N];
vector<int> row[N];
vector<int> col[N];
int n,m;

int32_t main()
{
	IOS;
	cin >> n >> m;
	int best = INT_MIN;
	rep(i,1,n)
	{
		rep(j,1,m)
		{
			cin >> a[i][j];
		}
	}
	rep(i,1,n)
	{
		row[i].pb(0);
		rep(j,1,m)
		{
			if(a[i][j]=='#')
				row[i].pb(j);
		}
		row[i].pb(m+1);
	}
	rep(j,1,m)
	{
		col[j].pb(0);
		rep(i,1,n)
		{
			if(a[i][j]=='#')
				col[j].pb(i);
		}
		col[j].pb(n+1);
	}
	rep(i,1,n)
	{
		rep(j,1,m)
		{
			if(a[i][j]=='.')
			{
				int q= lower_bound(row[i].begin(), row[i].end(), j) - row[i].begin();
				int p = lower_bound(col[j].begin(), col[j].end(), i) - col[j].begin();
				int ans=0;
				int req= row[i][q];
				ans += (req - j-1);
				q--;
				req= row[i][q];
				ans += (j-req-1);	
				req = col[j][p];
				ans += (req - i-1);
				p--;
				req= col[j][p];
				ans += (i-req-1);	
				ans++;
				best = max(ans,best);
			}
		}
	}
	cout << best << endl;
}


Measured memory_bytes: 68352
#include "bits/stdc++.h"
using namespace std;


const int N = 1e5 + 5;
int link[N], size[N];

int find(int a) {
    return a == link[a] ? a : link[a] = find(link[a]);
}

bool same(int a, int b) {
    return find(a) == find(b);
}


void unite(int a, int b) {
    a = find(a);
    b = find(b);
    if(size[a] < size[b]) swap(a, b);
    size[a] += size[b];
    link[b] = a;
}


int main() {
    int n;
    cin >> n;
    for(int i = 1; i <= n; ++i) link[i] = i, size[i] = 1;

    vector< pair< int, int> > x, y;
    x.reserve(n);
    y.reserve(n);

    for(int i = 1; i <= n; ++i) {
        int a, b;
        cin >> a >> b;
        x.emplace_back(a, i);
        y.emplace_back(b, i);
    }

    sort(begin(x), end(x));
    sort(begin(y), end(y));

    vector< tuple< int, int, int> > Vt;
    Vt.reserve(2 * n);
    for(int i = 0; i < n - 1; i++) {
        Vt.push_back(make_tuple(x[i + 1].first - x[i].first, x[i].second, x[i + 1].second));
        Vt.push_back(make_tuple(y[i + 1].first - y[i].first, y[i].second, y[i + 1].second));
    }

    sort(begin(Vt), end(Vt));
    long long res = 0;
    for(auto it: Vt) {
        int u, v, w;
        tie(w, u, v) = it;
        if(same(u, v)) continue;
        unite(u, v);
        res += w;
    }

    cout << res << endl;

}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(obj) (obj).begin(), (obj).end()
using P = pair<int, int>;
const int inf = 1e9;
const ll INF = 1e18;
const ll MOD = 1e9+7;
const ll MAX = 1e9+7;
template<typename T> T factorial(T n){
    if(n==1) return 1;
    else return n*factorial(n-1)%MOD;
}
template<typename T> T Pow(T x, T n, T m){
    if(n == 0) return 1;
    if(n % 2 == 0) return Pow(x * x % m, n / 2, m);
    else return x * Pow(x, n - 1, m) % m;
}
template<typename T> T combination(T n, T k, T m){
    return factorial<T>(n) * Pow<T>(factorial(k), m-2, m) % m * Pow<T>(factorial(n-k), m-2, m) % m;
}
struct edge{
    int to; // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using graph = vector<vector<edge>>;
using Graph = vector<vector<int>>;

int main(){
    str s; cin >> s;
    if((s[2] == s[3]) && (s[4] == s[5])) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P2;
const int inf=1000000000;
int pa[200001]={};
int ra[200001]={};
int pa2[200001]={};
int ra2[200001]={};

int find(int xx){
	if(pa[xx]==xx)return xx;
	return pa[xx]=find(pa[xx]);
}
int same(int xx,int yy){
	return 	find(xx)==find(yy);
}
void unite(int xx,int yy){
	xx=find(xx);
	yy=find(yy);
	if(ra[xx]<ra[yy]){
		pa[xx]=yy;
	}else{
		pa[yy]=xx;
		if(ra[xx]==ra[yy])ra[xx]++;
	}
	return;
}
int find2(int xx){
	if(pa2[xx]==xx)return xx;
	return pa2[xx]=find2(pa2[xx]);
}
int same2(int xx,int yy){
	return 	find2(xx)==find2(yy);
}
void unite2(int xx,int yy){
	xx=find2(xx);
	yy=find2(yy);
	if(ra2[xx]<ra2[yy]){
		pa2[xx]=yy;
	}else{
		pa2[yy]=xx;
		if(ra2[xx]==ra2[yy])ra2[xx]++;
	}
	return;
}


int main() {
	int n,k,l;
	vector<P> v;

	cin>>n>>k>>l;
	for(int i=1;i<n+1;++i)pa[i]=i;
	for(int i=1;i<n+1;++i)pa2[i]=i;

	for(int i=0;i<k;++i){
		int p1,q1;
		cin>>p1>>q1;
		if(!same(p1,q1))unite(p1,q1);
	}
	for(int i=0;i<l;++i){
		int r1,s1;
		cin>>r1>>s1;
		if(!same2(r1,s1))unite2(r1,s1);
	}
	for(int i=1;i<n+1;++i){
		P p1=P(find(i),find2(i));
		v.push_back(p1);
//		cout<<p1.first<<" "<<p1.second<<endl;
	}
	sort(v.begin(),v.end());

	P p1=P(find(1),find2(1));
	int t=upper_bound(v.begin(),v.end(),p1)-lower_bound(v.begin(),v.end(),p1);
	cout<<t;
	for(int i=2;i<n+1;++i){
		P p1=P(find(i),find2(i));
		int t=upper_bound(v.begin(),v.end(),p1)-lower_bound(v.begin(),v.end(),p1);
		cout<<" "<<t;
	}
	cout<<endl;
	return 0;
}


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

using namespace std;

int main()
{
    int n;
    int ans = 0;
    cin >> n;
    ans += 1000 * (n / 500);
    n %= 500;
    ans += 5 * (n / 5);
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string ss; bool ok1=false,ok2=false;
int main(){
	cin>>ss;
	for (int i=0;i<ss.length();i++){
		if (ss[i]=='C'&&ok2==false) ok1=true;
		if (ss[i]=='F'&&ok1==true) ok2=true; 
	}
	if (ok1&&ok2) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define PB push_back
#define MP make_pair
#define FST first
#define SND second
#define SZ(a) (signed)((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int MOD = 1000000007;
const char ENDL = '\n';

#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"  << " " << __FILE__ << endl;

signed main(void) {
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(10);
    cin.tie(0);

    int a, b;
    cin >> a >> b;
    if (a <= 0 && b >= 0) {
        cout << "Zero" << ENDL;
    } else if (a > 0) {
        cout << "Positive" << ENDL;
    } else if ((-a + b) % 2 == 1) {
        cout << "Positive" << ENDL;
    } else {
        cout << "Negative" << ENDL;
    }

    return 0;
}

Measured memory_bytes: 256
def counting_sort(in_arr, out_arr, arr_len, max_val):
    counter = [0] * (max_val + 1)  # 0, 1, 2, 3, ..., max_valのカウンター

    for i in range(arr_len):
        counter[in_arr[i]] += 1  # counterに出現数を記録

    for j in range(max_val):
        counter[j + 1] = counter[j + 1] + counter[j]  # 累積わ

    for i in reversed(range(0, arr_len)):  # 係数ソートは後ろから選んでいくと安定
        out_arr[counter[in_arr[i]] - 1] = in_arr[i]  # out_arrはindex, counterは個数なので1挽く
        counter[in_arr[i]] -= 1


def main():
    n = int(input())
    in_arr = list(map(int, input().split(" ")))
    out_arr = [0] * n
    counting_sort(in_arr, out_arr, n, 10000)
    print(" ".join(map(str, out_arr)))


if __name__ == "__main__":
    main()



Measured memory_bytes: 240328
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long int N; cin >> N; 
	long long int ans; 
	for(long long int i = 1; i * i <= N; i++){
		if(N % i == 0) ans = i + (N / i) - 2;  
	}
	cout << ans << endl; 
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<ctype.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    string s;
    cin >> s;
    int flag = 1;
    if(s[a]!='-') {flag=0;}
    else {
        for (int i=0; i<s.length(); i++) {
            if(i!=a && !isdigit(s[i])) {
                flag=0; break;
            }
        }
    }
    
    cout << (flag ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdlib.h>
#include <iostream>
#include <algorithm>
using namespace std;

int main(){
	int n;
	int k;

	cin >> n >> k;

	int* w = (int*)malloc(n * sizeof(int));

	int max_w = 0;
	int sum_w = 0;
	int p = 0;
	if(n < 1){
		return 0;
	}

	for(int i = 0; i < n; i++){
		cin >> w[i];
		sum_w += w[i];
		if(w[i] > max_w){
			max_w = w[i];
		}
	}
	p = max(max_w, sum_w/k);
	int current_w = 0;
	int current_k = 1;
	for(int i = 0; i <= n; ++i){
		if(current_w > p){
			++current_k;
			current_w = 0;
			--i;
			if(current_k > k){
				i = -1;
				current_k = 1;
				++p;
				continue;
			}
		}
		current_w += w[i];
	}
	cout << p <<endl;
	return 0;
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

template<typename T>
class tRMQ {
  vector<T> data;
  T unit;

public:
  static const long long INF = 100000000000;
  int n;
  function<T(const T &, const T &)> f;

  tRMQ(int _, T u, function<T(T, T)> bi) {
    unit = u;
    f = bi;
    n = 1;
    while (n < _) {
      n <<= 1;
    }
    data.resize(n * 4);
    for (int i = 0; i < n * 4; i++)
      data[i] = unit;
  }

  void update(int index, T val) {
    int i = index + n - 1;
    data[i] = val;
    while (i > 0) {
      i = (i - 1) / 2;
      data[i] = f(data[i * 2 + 1], data[i * 2 + 2]);
    }
  }

  // [a, b)
  T query(int a, int b, int k, int l, int r) {
    if (a < 0 || r <= a || b <= l)
      return unit;
    if (a <= l && r <= b)
      return data[k];
    else
      return f(query(a, b, k * 2 + 1, l, (l + r) / 2),
               query(a, b, k * 2 + 2, (r + l) / 2, r));
  }

  T query(int a, int b) { return query(a, b, 0, 0, n); }
};

tRMQ<ll> minrmq(int n) {
  return tRMQ<ll>(n, 10000000000000000LL, [](ll r, ll l) { return min(l, r); });
}

tRMQ<ll> maxrmq(int n) {
  return tRMQ<ll>(n, -10000000000000000LL,
                  [](ll r, ll l) { return max(l, r); });
}

tRMQ<ll> sumrmq(int n) {
  return tRMQ<ll>(n, 0, [](ll l, ll r) { return l + r; });
}

ll P = 1000000007;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<ll> t(n);
  vector<ll> s(2000);
  for (int i = 0; i < n; i++) s[a[i] - 1]++;
  vector<ll> ss(2001), iss(2001);
  for (int i = 0; i < 2000; i++) ss[i + 1] = ss[i] + s[i];
  for (int i = 0; i < 2000; i++) iss[1999 - i] = iss[2000 - i] + s[1999 - i];

  ll ans = 0;
  ll tmp = (k * (k - 1)) / 2;
  tmp %= P;
  auto r = sumrmq(2001);
  for (int i = 0; i < n; i++) {
    t[i] = r.query(a[i] + 1, 2001);
    ans += (t[i] * k) % P;
    ans %= P;
    ans += (iss[a[i]] * tmp) % P;
    ans %= P;
    r.update(a[i], r.query(a[i], a[i] + 1) + 1);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}

const int INF = 100100100;
const int MAX_V = 1100;
int cost[MAX_V][MAX_V];
int d[MAX_V];
bool used[MAX_V];
int V;
int previ[MAX_V];

void dijkstra(int s){
    fill(d, d+V, INF);
    fill(used, used+V, false);
    fill(previ, previ+V, -1);
    d[s] = 0;

    while(true){
        int v = -1;
        rep(u,V){
            if(!used[u] && (v==-1 || d[u]<d[v]))v=u;
        }
        if(v==-1)break;
        used[v] = true;

        for(int u=0;u<V;u++){
            if(d[u]>d[v]+cost[v][u]){
                d[u] = d[v] + cost[v][u];
                previ[u] = v;
            }
        }
    }
}

vector<int> get_path(int t){
    vector<int> path;
    for(;t!=-1;t=previ[t])path.push_back(t);
    reverse(path.begin(), path.end());
    return path;
}

int main() {
    cin >> V;
    rep(i,V){
        rep(j,V){
            if(i==j){
                cost[i][j] = 0;
            }else{
                cost[i][j] = INF;
            }
        }
    }
    int E;
    cin >> E;
    rep(i,E){
        int from,to,c;
        cin >> from >> to >> c;
        from--;
        to--;
        cost[from][to] = c;
        cost[to][from] = c;
    }

    int flag[V][V];
    rep(i,V){
        rep(j,V){
            flag[i][j] = 0;
        }
    }

    rep(i,V){
        dijkstra(i);
        rep(j,V){
            vi v = get_path(j);
            int from = i;
            rep(k,v.size()){
                flag[from][v[k]] = 1;
                from = v[k];
            }
        }
    }

    int ans = 0;
    rep(i,V){
        rep(j,V){
            if(i!=j && cost[i][j]!=INF){
                if(flag[i][j]==0)ans++;
            }
        }
    }

    cout << ans/2 << endl;

    return 0;
}
 
 


Measured memory_bytes: 768
import math
n, m = map(int, input().split())
R = 1000000007

if abs(n - m) >= 2:
    ans = 0
else:
    nf = math.factorial(n)
    mf = math.factorial(m)
    if n == m:
        ans = ((nf % R) * (mf % R) * 2) % R
    else:
        ans = (nf * mf) % R

print(ans)

Measured memory_bytes: 11000
#include <bits/stdc++.h>
#define REP(i,N) for(int 1=0;i<N;i++)
#define print(S) cout<<S<<endl;
using namespace std;

int main() {
	long long int A,B,C,D;
	cin>>A>>B>>C>>D;
	if(A*B>=C*D){
		print(A*B);
	}else{
		print(C*D);
	}
	return 0;
}

Measured memory_bytes: 892
function Main(input){
  var n = input.split("");
  for(i=0;i<=2;i++){
    if(n[i]=="1"){
      n[i] = 9;
    }else if(n[i]=="9"){
      n[i] = 1;
    }
  } 
  console.log(n.join(""));

}
    Main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 7372
#include<bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int inf = 0x3f3f3f3f;
#define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
#define Dep(i,a,b) for(register int i=(a);i>=int(b);--i)
#define rep(i,a,b) for(register int i=(a);i<int(b);++i)
#define mem(x,v) memset(x,v,sizeof(x))
#define gc getchar
#define pc putchar
#define fi first
#define se second
#define debug(x) cout << #x" = " << (x) << endl;
inline ll read(){
	register ll x=0,f=1;register char c=gc();
	for(;!isdigit(c);c=gc())if(c=='-')f=-1;
	for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48);
	return x*f;
}
void write(ll x){if(x<0)x=-x,pc('-');if(x>=10)write(x/10);putchar(x%10+'0');}
void wri(ll x){write(x),pc(' ');}
void writeln(ll x){write(x),pc('\n');}
const int maxn = 1e6+233;
ll mod=998244353;
ll qpow(ll a,ll b){
	ll ans=1;
	for(;b;b>>=1,a=1ll*a*a%mod)if(b&1)ans=ans*a%mod;
	return ans;
}
ll inv2=(mod+1)/2;
int n,m;
ll p[maxn],a[maxn],b[maxn];
void fwt(ll a[]){
	for(int i=1;i<m;i<<=1){
		for(int j=0;j<m;j+=(i<<1)){
			for(int k=0;k<i;++k){
				ll x=a[j+k],y=a[j+k+i];
				a[j+k]=(x+y)%mod;
				a[j+k+i]=(x-y+mod)%mod;
			}
		}
	}
}
void ifwt(ll a[]){
	for(int i=1;i<m;i<<=1){
		for(int j=0;j<m;j+=(i<<1)){
			for(int k=0;k<i;++k){
				ll x=a[j+k],y=a[j+k+i];
				a[j+k]=(x+y)*inv2%mod;
				a[j+k+i]=(x-y+mod)*inv2%mod;
			}
		}
	}
}
int main(){
	n = read(),m = 1 << n;
	ll sum = 0;
	rep(i,0,m){
		p[i] = read();
		sum = (sum + p[i]) % mod;
	}sum = qpow(sum,mod-2);
	a[0] = m-1;rep(i,1,m) a[i] = mod - 1;
	rep(i,0,m) b[i] = p[i] * sum % mod;b[0] = (b[0]+mod-1)%mod;
	fwt(a);fwt(b);
	rep(i,0,m) a[i]=1ll*a[i]*qpow(b[i],mod-2)%mod;
	ifwt(a);
	rep(i,0,1<<n) writeln((a[i]-a[0]+mod)%mod);
	return 0;
}

Measured memory_bytes: 15104
#include <iostream>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <unordered_map>
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
int arr[200010];
bool vis[200010];
int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    cin >> n;
    for(int i = 0; i < n; i ++){
        cin >> arr[i];
    }
    int idx = n + 1;
    bool reached = false;
    bool da = false;
    while(true){
        vis[idx] = true;
        
        if(idx - 2 >= 0){
            idx -= 2;
        }
        else{
            break;
        }
        if(vis[idx])continue;
        cout << arr[idx] << " " ;

    }
    idx = 0;
//    cout << arr[idx] << " ";
    if(n % 2 == 1)idx ++;
    while(idx < n){
        cout << arr[idx] << " ";
        idx += 2;
    }
    return 0;
}


Measured memory_bytes: 3200
#include <stdio.h>

int main(void) {
	int m,c = 0;
		while (scanf("%d",&m) , m != 0){
			c = 0;
			m = 1000 - m;
			while(m >= 500 ){
				m = m - 500 ;
				c++;
			}
			while(m >= 100 ){
				m = m - 100 ;
				c++;
			}
			while(m >= 50 ){
				m = m - 50 ;
				c++;
			}
			while(m >= 10 ){
				m = m - 10 ;
				c++;
			}
			while(m >= 5 ){
				m = m - 5 ;
				c++;
			}
			while(m){
				m--;
				c++;
			}
			printf ("%d\n",c);
		}
	return 0;
}

Measured memory_bytes: 1028
N, K = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range (N-1)]

import sys
sys.setrecursionlimit(10**9)
edge = [[] for _ in range(N)]
for u,v in AB:
    edge[u-1].append(v-1)
    edge[v-1].append(u-1)

MOD = 10**9+7
mod = 10 ** 9 + 7
MAX = K+10
fac = [0] * MAX
finv = [0] * MAX
inv = [0] * MAX
def cominit():
    fac[0] = 1
    fac[1] = 1
    finv[0] = 1
    finv[1] = 1
    inv[1] = 1
    for i in range(2,MAX):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod%i] * (mod//i) % mod
        finv[i] = finv[i-1] * inv[i] % mod
def cmb(n,r):
    if n < 0 or r < 0 or r > n:return 0
    if r > n/2: r = n-r        
    return fac[n] * (finv[r] * finv[n-r] % mod) % mod

def permu(n,r):
    if n<=0 or r<=0 or r>n: return 0
    return (fac[n]*finv[n-r])%MOD
cominit()



visited = [False]*N
visited[0] = True
def dfs(s,ans):
    M = len(edge[s])-1*(s!=0)
    if M==0:
        return ans
    if s==0:
        ans *= permu(K-1, M)
        ans %= MOD
    else:
        ans *= permu(K-2, M)
        ans %= MOD

    for nv in edge[s]:
        if visited[nv]:continue
        visited[nv] = True
        ans = dfs(nv, ans)
    
    return ans

print(dfs(0,K)%MOD)





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

typedef long long int ll;
#define rep(i,n) for(int i = 0; i < n; i++)

int main() {
  int n,k;
  cin >> n >> k;
  double ans = 0;
  for (int i = 0; i < n; i++) {
    double cnt = 1.0/n;
    ll score = i+1;
    while (score < k) {
      score *= 2;
      cnt /= 2;
    }
    ans += cnt;
  }
  printf("%.12lf\n", ans);
  return 0;
}


Measured memory_bytes: 3692
// first second push_back unordered return continue break vector visited check flag bool while iterator begin end lower_bound upper_bound temp true false ll_MAX ll_MIN insert erase clear pop push compare ll64_MAX ll64_MIN  reverse replace stringstream string::npos length substr front priority_queue
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()
const ll mod = 1e9 + 7 ;
const ll inf =
 1e9 + 5 ;
 //1e18L + 5;
const ll nax = 2e5 + 5;
void min_self(ll&a , ll b){a=min(a,b);}
void max_self(ll&a , ll b){a=max(a,b);}
void add_self(ll&a , ll b){a=(a+b)%mod;}
//#define (x)  get<0>(x) 
//#define (x)  get<1>(x)
//#define (x)  get<2>(x)
signed main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll h , n ; 
cin >> h >> n ; 
vector<ll> arr(n) ; 
for(ll i = 0 ; i<n ; i++) cin >> arr[i ] ;
sort(all(arr) , greater<ll>()) ; 

for(ll i = 0 ; i< n;  i++){
	h-=arr[i] ; 
	if(h<=0){
		cout << "Yes" ;
		return 0 ;
	}
}	

cout <<"No";

	
}

Measured memory_bytes: 1024
import java.util.Scanner;

class Main {
  public static void main(String[] args) {

    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();

    int[] a = new int[n + 1];
    for (int i = 1; i < n; i++) {
      int j = scan.nextInt();
      a[j]++;
    }

    for (int i = 1; i < n + 1; i++) {
      System.out.println(a[i]);
    }

  }

}


Measured memory_bytes: 61388
#include <iostream>
#include <vector>
#include <map>
#include <functional>

using namespace std;

int main() {
  int n,cap; cin >> n >> cap;
  vector<int>w(n), v(n);
  for (int i = 0; i < n; ++i) {
    cin >> w[i] >> v[i];
  }
  function<long long()>big_dp = [&]() -> long long {
     map<pair<int, long long>, long long>dp;
    function<long long(int, long long)>solve = [&](int i, long long j) -> long long{
      if (i == n) {
        return 0;
      }
      if (dp.find(make_pair(i,j)) != dp.end()) {
        return dp[make_pair(i,j)];
      }
      long long without = solve(i + 1, j);
      long long with = 0;
      if (j - w[i] >= 0)
        with = solve(i + 1, j - w[i]) + v[i];
      dp[make_pair(i, j)] = max(with, without);
      return max(with, without);
    };
    return solve(0, cap);
  };
  const int max_val = 1e3 * 1e2;
  int ans = 0;
  vector<long long>dp(max_val + 1, 1e9 + 1);
  dp[0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = max_val; j >= v[i]; j--) {
      dp[j] = min(dp[j], dp[j-v[i]] + w[i]);
      if (dp[j] <= cap) {
        ans = max(ans, j);
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define x first
#define y second

int n, k;
ll a[5010];

int dp[5010];

void add(int x){ for(int i=5000; i>=x; --i) dp[i] += dp[i-x]; }
void rem(int x){ for(int i=x; i<=5000; ++i) dp[i] -= dp[i-x]; }

int main()
{
	read(n, k);
	dp[0]=1;
	for(int i=1; i<=n; ++i) read(a[i]), add(a[i]);
	int ans=0;
	for(int i=1; i<=n; ++i){
        rem(a[i]);
        int l=max(0LL, k-a[i]), r=k;
        bool ex=0;
        for(int j=l; j<r; ++j) if(dp[j]) ex=1;
        if(!ex){
            ++ans;
        }
        add(a[i]);
	}
	printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 384
import math
from collections import defaultdict

def main2():
    N = int(input())
    fac = defaultdict(int)
    lim = int(math.sqrt(N))

    for i in range(2, lim + 1):
        while N % i == 0:
            is_p = False
            fac[i] += 1
            N = N // i

        if i == lim:
            if N != 1:
                fac[N] += 1

    ans = 0
    for k, v in fac.items():
        e = 1
        for i in range(10000000):       
            if e <= v:
                ans += 1
                v -= e
                e += 1
            else:
                break
    print(ans)

if __name__ == "__main__":
    main2()

Measured memory_bytes: 9500
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cmath>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int,int> P;
#define DIST(X,Y)(abs((X).first-(Y).first)+abs((X).second-(Y).second))
int dp[6][1000];
vector<P> location[7];
char M[1000][1001];
int main() {
	int x,y;
	while(scanf("%d %d",&x,&y),x) {
		for(int i=0;i<y;i++) {
			scanf("%s",M[i]);
		}
		for(int i=0;i<=6;i++) location[i].clear();
		for(int i=0;i<y;i++) {
			for(int j=0;j<x;j++) {
				if(M[i][j]=='S') location[0].push_back(P(j,i));
				else if(M[i][j]=='G') location[6].push_back(P(j,i));
				else if(isdigit(M[i][j])) location[M[i][j]-'0'].push_back(P(j,i));
			}
		}
		int A,B=1<<30;
		for(int i=1;i<=5;i++) {
			vector<int> V;
			V.push_back(0);
			for(int j=1;j<=4;j++) {
				if((i+j)<=5) V.push_back(i+j);
				else V.push_back((i+j)-5);
			}
			V.push_back(6);
			fill((int*)dp,(int*)(dp+6),1<<30);
			dp[0][0]=0;
			for(int j=1;j<=5;j++) {
				for(int k=0;k<location[V[j]].size();k++) {
					for(int l=0;l<location[V[j-1]].size();l++) {
						dp[j][k]=min(dp[j][k],dp[j-1][l]+DIST(location[V[j]][k],location[V[j-1]][l]));
					}
				}
			}
			if(B>dp[5][0]) A=i,B=dp[5][0];
		}
		if(B==(1<<30))printf("NA\n");
		else printf("%d %d\n",A,B);
	}
}

Measured memory_bytes: 2104
import itertools
N = int(input())
cnt = 0

S = ['3', '5', '7']
for i in range(3, len(str(N)) + 1):
    for p in itertools.product(['3', '5', '7'], repeat = i):
        if all(['3' in p, '5' in p, '7' in p]):
            if int(''.join(p)) <= N:
                cnt += 1
print(cnt)


Measured memory_bytes: 3060
import collections
n = int(input())
a_list = list(map(int,input().split()))
c=collections.Counter(a_list)
result=0

for i in c.values():
    result+=i * (i - 1)//2

for a in a_list:
    minus=-(c[a]) * (c[a]-1)//2
    plus=(c[a]-1) * (c[a]-2)//2
    print(result + minus + plus)  

Measured memory_bytes: 26780
#include <iostream>
#include <queue>
#include <algorithm>
#define MAX_WH 20
#define MAX_YOGORE 10

using namespace std;

int w, h;
char data[MAX_WH][MAX_WH];
int cost[MAX_YOGORE+1][MAX_YOGORE+1];
int sx, sy;
int n;

class Point {
public:
  int x, y;
  int cost;
  Point(int x=0, int y=0, int cost=0) : x(x), y(y), cost(cost) {}
};

void bfs(int x, int y) {
  Point p;
  queue<Point> Q;
  bool visited[MAX_WH][MAX_WH];
  int s = data[y][x]-'a';
  int t;
  const int dx[4] = {1,0,-1,0};
  const int dy[4] = {0,1,0,-1};

  for(int i = 0; i < h; i++) {
    for(int j = 0; j < w; j++) {
      visited[i][j] = false;
    }
  }

  visited[y][x] = true;
  Q.push(Point(x, y, 0));

  while(!Q.empty()) {
    p = Q.front();
    Q.pop();

    if(data[p.y][p.x] != '.' && data[p.y][p.x] != 'x') {
      t = data[p.y][p.x]-'a';
      cost[s][t] = cost[t][s] = p.cost; 
    }

    for(int i = 0; i < 4; i++) {
      int nx = p.x + dx[i];
      int ny = p.y + dy[i];
      if(nx < 0 || nx >= w) continue;
      if(ny < 0 || ny >= h) continue;
      if(data[ny][nx] == 'x') continue;
      if(visited[ny][nx]) continue;
      Q.push(Point(nx, ny, p.cost+1));
      visited[ny][nx] = true;
    } 
  }
}

int solve() {
  int A[MAX_YOGORE];
  int ans;
  for(int i = 0; i < n+1; i++) {
    for(int j = 0; j < n+1; j++) {
      cost[i][j] = 0;
    }
  }
  for(int i = 0; i < h; i++) {
    for(int j = 0; j < w; j++) {
      if(data[i][j] != '.' && data[i][j] != 'x') {
	bfs(j, i);
      }
    }
  }

  for(int i = 0; i < n; i++) {
    A[i] = i+1;
  }

  ans = 100000;
  do {
    int newAns = cost[0][A[0]];
    if(newAns == 0) continue;
    for(int i = 1; i < n; i++) {
      if(cost[A[i-1]][A[i]] == 0) {
	newAns = 100000;
	break;
      }
      newAns += cost[A[i-1]][A[i]];
    }
    if(newAns < ans) ans = newAns;

  } while(next_permutation(A, A+n));
  if(ans == 100000)   return -1;
  else           return ans;
}

int main() {
  while(1) {
    cin >> w >> h;
    if(w == 0 && h == 0) break;
    n = 0;
    for(int i = 0; i < h; i++) {
      for(int j = 0; j < w; j++) {
	cin >> data[i][j];
	if(data[i][j] == 'o') {
	  sx = j;
	  sy = i;
	  data[i][j] = 'a';
	} else if(data[i][j] == '*') {
	  data[i][j] = 'b' + n++;
	}
      }
    }
    cout << solve() << endl;
  }
  return 0;
}

Measured memory_bytes: 912
#include <stdio.h>

int main()
{
    int N = 0,sum = 0,d = 0,e = 0;
    scanf("%d",&N);
    int a[20],b[50],c[50];
    for(int i = 0;i < N;i++)scanf("%d",&a[i]);
    for(int l = 0;l < N;l++)scanf("%d",&b[l]);
    for(int k = 0;k < N-1;k++)scanf("%d",&c[k]);
    for(int n = 0;n < N;n++)
    {
        sum += b[n];
        d = a[n];
        if(n != 0)e = a[n-1] + 1;
        if(d == e)sum += c[a[n]-2];
    }
    printf("%d",sum);
    return 0;
}

Measured memory_bytes: 128
//created by missever

#include<bits/stdc++.h>
#define MAX 1000000007
using namespace std;
typedef long long LL;
typedef pair<int,int> P;

char s[105];
bool cput(LL x) {
    printf("? %lld\n",x);
    fflush(stdout);
    scanf("%s",s);
    return s[0] == 'Y';
}


int main() {
    int i,l = 0,r;
    bool vis = 1;
    for(i = 1000000000; i > 0; i /= 10) {
        if(cput(i)) {
            vis = vis & 1;
            if(l == 0) l = i;
        } else vis = 0;
    }
    if(vis) {
        for(i = 1; i <= 1000000000; i *= 10) {
            if(cput(i * 10LL - 1)) {
                printf("! %d\n",i);
                fflush(stdout);
                return 0;
            }
        }
    }
    r = l * 10 - 1;
    l  =l + 1;
    while(l < r) {
        int mid = (l + r) >> 1;
        if(cput(mid * 10LL + 1)) r = mid;
        else l = mid + 1;
    }
    printf("! %d\n",r);
    fflush(stdout);
    return 0;
}


Measured memory_bytes: 596
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
//#include <set>
//#include <map>
//#include <cmath>
/*************************************************************************************/
using namespace std;
typedef long long ll;
const int inf = 0x7fffffff;
const char w = '\n';
int ii( ){ int x; cin >> x; return x; }
void Faster( ){ ios_base::sync_with_stdio( false ); cin.tie( nullptr ); }
/*************************************************************************************/

int main( ){
	Faster( );
	int n, x;
	cin >> n >> x;
	for( int i = 0; i < n; i++ ){
		x -= ii();
		if( x < 0 ){
			cout << i + 1;
			return 0;
		}
	}
	cout << n + 1;
	return 0;
}

// 10-06-2020
// Грандмастер ТемплатеСимпле 14
// Хеил то Тхе Греат Рюссия



Measured memory_bytes: 256