akhauriyash/Code-Regression huggingface dataset:
//code by 27.
#include<stdio.h>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<queue>
#include<map>
#include<stack>
#include<fstream>
#include<stdlib.h>
#include<set>
#include<cassert>
#include<climits>
#include<cmath>
#include<memory.h>
using namespace std;
int f[10];
int check(int k)
{
	int t=k;
	while(t!=0)
	{
		if(f[t%10]==1)return 0;
		t/=10;
	}
	return 1;
}
int main()
{
	int n;
	cin>>n;
	int m;
	cin>>m;
	int t=0;
	while(m--)
	{
		cin>>t;
		f[t]=1;
	}
	while(!check(n))
	{
		n++;
	}
	cout<<n;
    return 0;
}

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

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

int main() {
    ll n;
    cin >> n;

    map<ll, int> mp = prime_factor(n);

    ll cnt = 0, now = 1;
    vector<int> sum(50);
    for (int i = 1; i < 50; ++i) {
        sum[i] = now;
        ++cnt;

        if (cnt - 1 == now) {
            ++now;
            cnt = 0;
        }
    }

    int ans = 0;
    for (auto p : mp) {
        ans += sum[p.second];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
#pragma GCC optimize("Ofast")
//没错，我就是抄zyy代码了
//啊，代码都不能抄，那还有什么可以抄啊 
#include<bits/stdc++.h>
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 fi first
#define se second
#define lowbit(x) ((x)&-(x))
#define debug(x) cout << #x " = " << x << endl;
namespace IO{
	const int L = 1 << 15;
	char ibuf[L|1],*iS=ibuf,*iT=ibuf;
	char obuf[L|1],*oS=obuf,*oT=obuf+L;
	char c,st[66];int tp=0,f;
	inline char gc(){
		if(iS==iT) iT=(iS=ibuf)+fread(ibuf,sizeof(char),L,stdin);
		return (*iS++);
	}
	inline void flush() {
		fwrite(obuf,sizeof(char),oS-obuf,stdout);
		oS = obuf;
	}
	inline void pc(char c){*oS++=c;if(oS==oT) flush();}
	#define gc getchar
	#define pc putchar
	inline ll read(){
		ll x=0;f=1,c=gc();
		for(;!isdigit(c);c=gc())if(c=='-')f=-1;
		for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c&15);
		return x*f;
	}
	void write(ll x){
		if(!x) pc('0');if(x<0) pc('-'),x=-x;
		while(x) st[++tp]=x%10+'0',x/=10;
		while(tp) pc(st[tp--]);
	}
	void wri(ll x){write(x);pc(' ');}
	void writeln(ll x){write(x);pc('\n');}
	struct IOflusher{~IOflusher(){flush();}}_ioflusher_;
}
using IO::read;
using IO::writeln;
using IO::wri;
inline void gg(string s){cout << s << endl;exit(0);}
inline void gg(ll x){writeln(x);exit(0);}
const int N=1e6+10;
int n,len,p[3],q[3],cnt[3];
char s[N];
bool cmp(int x,int y){return cnt[x] < cnt[y];}
int main(){
	scanf("%s",s+1);int len=strlen(s+1);
	Rep(i,1,len) if(s[i]!=s[i-1]) s[++n] = s[i];
	Rep(i,1,n) s[i]-='A',cnt[s[i]]++;
	rep(i,0,3) p[i] = i;sort(p,p+3,cmp);sort(cnt,cnt+3);
	rep(i,0,3) q[p[i]]=i;Rep(i,1,n) s[i]=q[s[i]];
	int x = 0,y = 0;
	for(int i=1,j;i<=n;i=j+1){
		j=i;if(s[i]){
			while(j<n&&s[j+1])++j;
			if(i==j&&i!=1&&j!=n&&s[i]==2)++y; else{
				if(i!=j || s[i]==1) ++x;
				if(s[i]==2&&cnt[2]>cnt[1]) --cnt[2],s[i]=3;
				if(s[j]==2&&cnt[2]>cnt[1]) --cnt[2],s[j]=3;
			}
		}
	}int tmp=max(y-x,0);
	for(int i=2;i<n&&tmp;++i){
		if(!s[i-1]&&!s[i+1]&&s[i]==2){
			--tmp;--cnt[2],--cnt[0];
			s[i-1]=s[i]=3;
		}
	}len = 0;
	Rep(i,1,n) if(s[i]!=3) s[++len]=s[i];
	n = len;
	for(int i=1,j;i<=n;i=j+1){
		j=i;if(s[i]){
			while(j<n&&s[j+1]) ++j;
			int tmp;
			if(i==1||j==n) tmp=(j-i+1)/2; else tmp=(j-i)/2;
			for(int k=i;cnt[1]>cnt[0]&&tmp;k+=2)
				s[k]=s[k+1]=3,--cnt[1],--tmp;
		}
	}Rep(i,1,n)if(s[i]<3)pc(p[s[i]]+'A');
	return 0;
}

Measured memory_bytes: 4784
#define NOMINMAX

#include <vector>
#include <iostream>
#include <algorithm>
#include <cstddef>

struct child {
    int a;
    bool b;
    bool operator <(child const& arg) {
        return a < arg.a;
    }
};

int main() {
    auto n = int{};
    auto x = int{};
    std::cin >> n;
    std::cin >> x;
    auto children = std::vector<child>(n);
    for (auto& e : children) {
        std::cin >> e.a;
        e.b = false;
    }

    static auto const is_b = [](child const& a) {
        return a.b;
    };

    std::sort(children.begin(), children.end());
    auto next = [&children]() {
        auto it = std::find_if_not(children.begin(), children.end(), is_b);
        if (it == children.end())
            return;
        it->b = true;
        std::for_each(children.begin(), it, [](child& e) {
            e.b = false;
        });
    };

    auto sum = [&children]() {
        int result = 0;
        for (auto const& e : children) {
            if (e.b)
                result += e.a;
        }
        return result;
    };
    auto count_enabled = [&children]() {
        return int(std::count_if(
            children.begin(),
            children.end(), [](child const& e) {
                return e.b;
            }));
    };

    auto result = 0;
    auto rem = x;
    for (auto it = children.begin();
        it != children.end();
        ++it) {
        if (it == std::prev(children.end())) {
            if (it->a == rem) {
                ++result;
            }
            rem = 0;
        } else {
            if (rem < it-> a) {
                rem = 0;
                break;
            } else if (it->a <= rem) {
                rem -= it->a;
                ++result;
            }
        }
    }
    std::cout << result << std::endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> ary(n);
  
  for(int i=0; i<n; i++)
    cin >> ary.at(i);
  int a=0, b=0;
  
  for(int i=0; i<n; i++){
    int k;
    int max=0;
    for(int j=0; j<n; j++){
      if(ary.at(j) >= max){
        max=ary.at(j);
        k=j;
      }
    }
    a+=max;
    ary.at(k)=0;
    max=0;
    
    for(int j=0; j<n; j++){
      if(ary.at(j) >= max){
        max=ary.at(j);
        k=j;
      }
    }
    b+=max;
    ary.at(k)=0;
  }
  cout << a - b << endl;
}
    
      


Measured memory_bytes: 256
#include <stdio.h>
int main(void) {

	int S_number, T_number;
	int S_array[100000], T_array[5000];
	int mid;
	int overaycount = 0;

	scanf("%d", &S_number);
	for (int si = 0; si<S_number; si++) {
		scanf("%d", &S_array[si]);
	}

	scanf("%d", &T_number);




	
	for (int ti = 0; ti<T_number; ti++) {
		scanf("%d", &T_array[ti]);
		int left = 0;
		int right = S_number ;
		while (left<right) {
			mid = (left + right) / 2;
			if (S_array[mid] == T_array[ti]) {
				overaycount++;
				break;
			}
			else if (S_array[mid]<T_array[ti]) {
				left = mid + 1;
			}
			else {
				right = mid;
			}
		}
	}
	printf("%d\n", overaycount);
	return 0;
}


Measured memory_bytes: 2128
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
a=lnii()

money=1000
kabu=0
for i in range(n-1):
  if a[i]<a[i+1]:
    t_kabu=money//a[i]
    kabu+=t_kabu
    money-=t_kabu*a[i]
  elif a[i]>a[i+1]:
    money+=kabu*a[i]
    kabu=0

money+=kabu*a[n-1]
print(money)

Measured memory_bytes: 9148
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int main(){
    long long int N;
    cin >> N;
    long long int ans = 0;
    for(long long int i = 1; i * i < N; i++){
        if((N - i) % i == 0 && (N - i) / i > i){
            ans += (N - i) / i;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
cal=0
for i in range(1,n+1):
  for j in range(1,20):
    if i>=k:
      cal+=1
      break
    elif i*2**(j-1)<k and i*2**j>=k:
      cal+=(1/2)**(j)
      break
print(cal/n)

Measured memory_bytes: 3060
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

typedef unsigned long long ULLONG;
typedef long long LLONG;

template <class _T> static _T tp_abs(const _T& a) {
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void get3int(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}
static void getstring(char* buff) {
	if (scanf(" %s", buff) < 0) {
		printf("getstr error!\n");
	}
}
static const long long MOD_NUM = 1000000007LL;

static void B_task();

int main()
{
	B_task();
	fflush(stdout);
	return 0;
}

static void B_task()
{
	int N, K;
	get2int(N, K);

	int ans = 0;
	for (int i = 0; i < N; i++) {
		int h;
		get1int(h);
		if (h >= K) ans++;
	}
	printf("%d\n", ans);
}


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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    int n,k;
    cin >> n >> k;
    if(n%k)cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 896
# coding: utf-8
# 56

m = input()

K = m.count('K')
U = m.count('U')
P = m.count('P')
C = m.count('C')

A = int(0)

while True:
    if K==0 or U ==0 or P ==0 or C==0:
        break
    
    elif K>=1 or U>=1 or P>=1 or C>=1:
        A += 1
        K -= 1
        U -= 1
        P -= 1
        C -= 1
print(A)


Measured memory_bytes: 5560
import itertools
import math
n=int(input())
N=math.factorial(n)
P=tuple(map(int,input().split()))
Q=tuple(map(int,input().split()))
l=list(itertools.permutations(range(1,n+1)))
for i in range(N):
    if l[i] == P:
        a = i
for j in range(N):
    if l[j] == Q:
        b = j
print(abs(b-a))

Measured memory_bytes: 7972
N = int(input())
L = list(map(int, input().split()))

L2 = list(set(L)) # 重複を削除

ans = 0

for i in range(len(L2)):
  for j in range(i+1, len(L2)):
    for k in range(j+1, len(L2)):
      l = [L2[i], L2[j], L2[k]]
      l = sorted(l, reverse = True)
      if l[0] < l[1] + l[2]:
        ans += L.count(L2[i]) * L.count(L2[j]) * L.count(L2[k])

print(ans)      
    


Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    string t,s;
    cin>>s>>t;
    string tt="";
    for(int i=0;i<t.length()-1;i++)
    {
        tt+=t[i];
    }
    if(s.compare(tt)==0)
        cout<<"Yes";
    else
    {
            cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 3600
#include <cstdio>

using namespace std;

const int maxn=510;

#define LL long long

int a[maxn][maxn];

int main()
{
	int n,m,h,w;
	scanf("%d%d%d%d",&n,&m,&h,&w);
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
		{
			a[i][j]=4000;
		}
	}
	a[h][w]=-4000ll*h*w+3999;
	for(int i=h+1;i<=n;i++)
	{
		for(int j=1;j<=w;j++)
		{
			a[i][j]=a[i-h][j];
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=w+1;j<=m;j++)
		{
			a[i][j]=a[i][j-w];
		}
	}
	LL sum=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			sum+=a[i][j];
		}
	}
	if(sum>0)
	{
		printf("Yes\n");
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=m;j++)
			{
				printf("%d ",a[i][j]);
			}
			printf("\n");
		}
	}
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 2432
// 
// 
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define is_in(i, s) (s.find(i) != s.end())
#define all(x) (x).begin(),(x).end()
#define outl(x) cout<<x<<endl
#define outsp(x) cout<<x<<" "
typedef long long ll;
typedef pair<int,int> P;


#define MAX_N 1000000005


int main() {
	string s;
	cin >> s;
	char c = s[s.size()-1];
	if(c=='2'||c=='4'||c=='5'||c=='7'||c=='9'){
		outl("hon");
	}else if(c=='3'){
		outl("bon");
	}else{
		outl("pon");
	}
    return 0;
}



Measured memory_bytes: 3628
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();
		int sum = 0;
		int cnt = 0;

		List<Integer> list = new ArrayList<>();
		while (sc.hasNext()) {
			int temp = sc.nextInt();
			list.add(temp);
			sum += temp;
		}

		for (int a : list) {
			if (a * 4 * m < sum) {
				continue;
			}
			cnt++;
		}

		if (m <= cnt) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}
}


Measured memory_bytes: 23636
#include<bits/stdc++.h>
#define int long long
#define all(a) a.begin(),a.end()
#define sz(a) a.size()
#define re return 
#define MP make_pair
#define pb push_back
#define pii pair<int,int>
#define se second
#define fi first
using namespace std;

signed main(){
	ios_base::sync_with_stdio(0);
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if((abs(a-b)<=d&&abs(b-c)<=d)||abs(a-c)<=d) cout<<"Yes";
	else cout<<"No";
	re 0;
}

Measured memory_bytes: 3652
#include<stdio.h>
int main(void)
{
	int h,w,i,j;
	while(1){
		scanf("%d %d",&h,&w);
		if(h==0 && w==0) break;
		for(i=0;i<w;i++){
			printf("#");
		}
		printf("\n");
		for(i=0;i<h-2;i++){
			printf("#");
			for(j=0;j<w-2;j++){
				printf(".");
			}
			printf("#\n");
		}
	
		for(i=0;i<w;i++){
			printf("#");
		}
		printf("\n");
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2592
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

Int N, M;
vector<Int> a;
vector<Int> s(N + 1);

Int solve(Int D) {

	Int cnt = 0;
	Int tot = 0;
	Int num;

	for (Int i = 0; i < N; i++) {
		auto temp = lower_bound(a.begin(), a.end(), D - a[i]);
		num = a.end() - temp;
		cnt += num;//両手の総和がD以上になる手の個数

		tot += num * a[i] + (s[N] - s[N - num]);
	}

	tot -= (cnt - M) * D;

	return tot;
}

bool isOK(Int x) {//両手の和がx以上になる組み合わせ総数がM通り以上になるか

	Int cnt = 0;

	for (Int i = 0; i < N; i++) {//左手をiで固定
		auto temp = lower_bound(a.begin(), a.end(), x - a[i]);
		cnt += a.end() - temp;
	}

	return cnt >= M;

}

// 汎用的な二分探索のテンプレ
Int binary_search() {
	Int ng = 1000000;
	Int ok = 0;

	/* ok と ng のどちらが大きいかわからないことを考慮 */
	while (abs(ok - ng) > 1) {
		Int mid = (ok + ng) / 2;

		if (isOK(mid)) ok = mid;
		else ng = mid;
	}
	return ok;
}

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	cin >> N >> M;

	a.resize(N);
	for (Int i = 0; i < N; i++) {
		cin >> a[i];
	}

	sort(a.begin(), a.end());

	//握手回数がM以上になる両手の総和Dを二分探索
	Int D = binary_search();

	//累積和
	s.resize(N + 1);
	for (Int i = 0; i < N; i++) {
		s[i + 1] = s[i] + a[i];
	}

	Int ans = solve(D);

	cout << ans << "\n";

}


Measured memory_bytes: 1792
import numpy as np

D = int(input())
C = np.array(list(map(int, input().split())))
S = np.array([list(map(int, input().split())) for d in range(D)])

L = np.empty(26, int)
L[:] = -1

score = 0
for d in range(D):
    t = int(input())-1
    L[t] = d
    score += S[d, t] - np.dot(C, d-L)
    print(score)


Measured memory_bytes: 27472
#include<bits/stdc++.h>
using namespace std;
 int main()
 {
   int n,i,j;
   cin >> n;
   vector<int> b(n),c(n),flag(n);
   for(i=0;i<n;i++)
   { c.at(i)=0;
    flag.at(i)=0;
     cin >> b.at(i);
     if(b.at(i)>i+1)
     {
        cout << "-1" << endl;
        return 0;
     }
     
   }
   for(i=0;i<n;i++)
   {
     for(j=0;j<n;j++)
     {
        if(flag.at(n-1-j)==1) continue;
        if(b.at(n-1-j)==c.at(n-1-j)+1)
        {
          flag.at(n-1-j)=1;
          cout << b.at(n-1-j) << endl;
          break;
        }
        c.at(n-1-j)++;
     }
   }
 }



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repn(i,n) for(ll i=0;i<=(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
//cin.tie(0);
//ios::sync_with_stdio(false);



signed main(){
  string s;cin>>s;
  ll g=0,p=0;

  for(int i=0;i < siz(s);i++)
  {
    if(s[i]=='g')g++;
    else p++;
  }

  cout<<(g-p)/2<<endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <numeric>

using namespace std;


void func()
{
	string N;
	cin >> N;

	switch (*N.rbegin())
	{
	case '3':
		cout << "bon\n";
		break;
	case '0':
	case '1':
	case '6':
	case '8':
		cout << "pon\n";
		break;
	default:
		cout << "hon\n";
		break;
	}
	return;
}

int main() {

//	while (1)
		func();
	return 0;
}


Measured memory_bytes: 3044
import java.util.*;

public class Main {
  static final double H_SPEED = 2*Math.PI/720;
  static final double M_SPEED = 2*Math.PI/60;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    double a = sc.nextDouble();
    double b = sc.nextDouble();
    double h = sc.nextDouble();
    double m = sc.nextDouble();
    double res = Math.sqrt(a*a+b*b-2*a*b*Math.cos((60*h+m)*H_SPEED-m*M_SPEED));
    System.out.println(res);
    sc.close();
  }
}

Measured memory_bytes: 37440
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
const int M=2002;
int a[M];
bool solve(int x,int sm,int k,int q,int n)
{
	vector<int> cur;
	int tot=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]<sm)
		{
			sort(all(cur));
			for(int j=0;j<=sz(cur)-k;j++)
			{
				if(cur[j]<=x)
					tot++;
			}
			cur.clear();
		}
		else
		{
			cur.pb(a[i]);
		}
	}
	sort(all(cur));
	for(int i=0;i<=sz(cur)-k;i++)
	{
		if(cur[i]<=x)
			tot++;
	}
	// if(x==1 && sm==1)
	// {
	// 	cout<<tot<<endl;
	// }
	if(tot>=q)
		return 1;
	return 0;
}
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n,k,q;
	cin>>n>>k>>q;
	vector<int> v;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		v.pb(a[i]);
	}
	sort(all(v));
	int res=1e9;
	for(int i=1;i<=n;i++)
	{
		int l=0,r=sz(v)-1,p=-1;
		r=0;
		while(r<sz(v) && v[r]!=a[i])
			r++;
		while(l<r)
		{
			int m=(l+r)/2;
			if(m==p)
				m++;
			p=m;
			if(solve(a[i],v[p],k,q,n))
			{
				l=m;
			}
			else
			{
				r=m-1;
			}
		}
		if(solve(a[i],v[l],k,q,n))
		{
			res=min(res,a[i]-v[l]);
		}
	}
	cout<<res<<"\n";
	return 0;
}

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

int main() {
    ll n;
    cin >> n;
    ll a=-1;
    ll b;
    for (ll i=sqrt(n);i>0;i--){
        if (n%i==0){
            a = i;
            break;
        }
    }
    b = n / a;
    cout << a+b-2 << endl;
    return 0;
}



Measured memory_bytes: 256
N, Q = map(int, input().split())
S = input()
L = [0]*(N+1)
for i in range(N):
    if S[i:i+2] == "AC":
        L[i+1] = L[i] +1
    else:
        L[i+1] = L[i]
for i in range(Q):
    l,r = map(int, input().split())
    print(L[r-1]-L[l-1])

Measured memory_bytes: 6060
#include <iostream>
#include <vector>
typedef long long ll;
using namespace std;

ll a,b,p;

ll calc(ll x){
    return x-a;
}

ll calc2(ll x){
    ll y = 1;
    for(int i=0;i<20;i++){
        if(y>x){
            break;
        }
        y *= 10;
    }
    return y;
}

int main(){
    while(cin >> a >> b >> p&&a!=0){
        vector<ll> dp(b-a+2);
        dp[b-a] = 1;
        for(ll i=b-1;i>=a;i--){
            dp[i-a] = 1;
            ll z = min(b+1,calc2(i));
            dp[i-a] = (dp[i-a]+dp[i-a+1])%p;
            dp[i-a] = (dp[i-a]+p-dp[z-a])%p;            
            ll x = i;
            for(int j=1;j<20;j++){
                x*=10;
                if(x>b)break;
                ll y = min(b+1,calc2(x));
                dp[i-a] = (dp[i-a]+dp[x-a])%p;
                dp[i-a] = (dp[i-a]+p-dp[y-a])%p;
            }
            dp[i-a] = (dp[i-a]+dp[i-a+1])%p;
        }
        cout << dp[0]%p << endl;
    }
    return 0;
}


Measured memory_bytes: 3792
#include <bits/stdc++.h>
#include <iostream>
#include <cstring>
#include <set>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iterator>
#include<deque>
#include<cstdio>

#define lp(i,a,n) for(int i=a;i<n;++i)
#define rep(i,a,n) for(ll i=a;i<=n;++i)
#define all(v) v.begin(),v.end()
#define clr(n,a) memset(n,a,sizeof(n))
#define vi vector <int>
#define sc set <char>
#define si set<int>
#define pb push_back
#define vb vector <bool>
#define pi(n) printf("%d\n",n)
#define ln "\n"
#define mahmoud_abdelsamie ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef unsigned long long ull;
using namespace std;


int main()
{
    mahmoud_abdelsamie
    int a[4]={};
    string s[4] = {"AC","WA","TLE","RE"};
    int n;cin>>n;
    lp(i,0,n){
        string st; cin>>st;
        if(st==s[0])
            ++a[0];
        else if(st==s[1])
            ++a[1];
        else if(st==s[2])
            ++a[2];
        else
            ++a[3];
    }
    lp(i,0,4){
        cout<<s[i] << " x "<<a[i]<<ln;
    }
    return 0;
}


Measured memory_bytes: 3592
# Code for D - Road to Millionaire
# Use input() to fetch data from STDIN
from math import floor
N = int(input())
A = list(map(int, input().split()))

total = 1000
for i in range(0, N - 1):
    if A[i] < A[i+1]:
        total += floor(total / A[i]) * ( A[i + 1] - A[i] )

print(total)


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

int main() {
   int K, S;
   cin >> K >> S;
   int z, count = 0;
   for(int x=0; x<=K; x++) {
      for(int y=0; y<=K; y++) {
         z = S - x - y;
         if(z <= K && z >= 0) {
            count++;
         }
      }
   }
   cout << count << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    int x,t;
    cin>>x>>t;
    cout<<max(0,x-t)<<endl;


    return 0;
}

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

const int MAXN=1e5+10;

int a[MAXN];

int main()
{
  	ios_base::sync_with_stdio(false);
	cin.tie(0);
  	cout.tie(0);
  	int n,in,xd;
  	long long res=0;
  	cin>>n;
  	for(int i=1;i<=n+1;i++)
      cin>>a[i];
  	for(int i=1;i<=n;i++)
      cin>>in,xd=min(in,a[i]),in-=xd,a[i]-=xd,res+=xd,xd=min(in,a[i+1]),a[i+1]-=xd,res+=xd;
	cout<<res<<"\n";
}

Measured memory_bytes: 640
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>
#include <fstream>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	int h, w; cin >> h >> w;
	rep(i, h)rep(j, w)
	{
		string s; cin >> s;
		if (s == "snuke")
		{
			cout << char('A' + j) << i + 1 << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 3588
#include<iostream>
#include<string>
using namespace std;
int main(){
	string s;cin>>s;
	bool ok=true;
	for(int i=0;i<s.size();i++){
		for(int j=0;j<i;j++){
			if(s[i]==s[j])ok=false;
		}
	}
	cout<<(ok?"yes":"no")<<endl;
	return 0;
}


Measured memory_bytes: 256
from fractions import gcd

N = int(input())
A = list(map(int, input().split()))
res = 0

l = A[0]
for i in range(1, N):
    l = l * A[i] // gcd(l, A[i])

for a in A:
    res += l//a

print(res % 1000000007)

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N), b(200);
  for (int i = 0; i < N; i++){
    cin >> a[i];
  }
  sort (a.begin(), a.end());
  int ans = 0;
  for (int i = 0; i < N; i++){
    if (b[a[i]] == 1) continue;
    b[a[i]] = 1;
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#define int long long
using namespace std;
signed main()
{
    int n;
    cin >> n;
    int a[n][3], dp[n][3];
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cin >> a[i][j];
            if (i == 0)
                dp[i][j] = a[i][j];
            else
            {
                dp[i][j] = max(dp[i - 1][(j + 1) % 3], dp[i - 1][(j + 2) % 3]) + a[i][j];
            }
        }
    }
    cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << endl;
    return 0;
}

Measured memory_bytes: 4992
//https://atcoder.jp/contests/abc097/tasks/arc097_b
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

struct uf_tree {
    std::vector<int> parent;
    int __size;
    uf_tree(int size_) : parent(size_, -1), __size(size_) {}
    void unite(int x, int y) {
        if ((x = find(x)) != (y = find(y))) {
            if (parent[y] < parent[x]) std::swap(x, y);
            parent[x] += parent[y];
            parent[y] = x;
            __size--;
        }
    }
    bool is_same(int x, int y) { return find(x) == find(y); }
    int find(int x) { return parent[x] < 0 ? x : parent[x] = find(parent[x]); }
    int size(int x) { return -parent[find(x)]; }
    int size() { return __size; }
};

int main() {
    ll N,M; cin>>N>>M;
    vector<ll> pn(N+1);
    FOR(i,1,N+1){
        cin>>pn.at(i);
    }
    uf_tree ut(N+1);
    REP(m,M){
        int x,y; cin>>x>>y;
        ut.unite(x,y);
    }

    ll ans=0;
    FOR(i,1,N+1){
        if (i==pn.at(i)){
            ++ans;
        }else{
            if (ut.is_same(i,pn.at(i))) ++ans;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int dp[3][(unsigned int)1e5];
int h[3][(unsigned int)1e5];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> h[0][i] >> h[1][i] >> h[2][i];
  for (int j = 0; j < 3; j++)
    dp[j][0] = h[j][0];
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      dp[j][i] = INT_MIN;
      for (int k = 0; k < 3; k++) {
        if (k == j) continue;
        dp[j][i] = max(dp[j][i], dp[k][i - 1] + h[j][i]);
      }
    }
  }

  cout << max({dp[0][n - 1], dp[1][n - 1], dp[2][n - 1]}) << endl;
  return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
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; }

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) do{}while(0)
#endif





ll h, w, k;

int main(){
	cin >> h >> w >> k;
	
	vector<int> v(h);
	rep(i,h){
		string s;
		cin >> s;
		rep(j,w){
			if ( s[j] == '#' )
				v[i] |= (1<<j);
		}
	}
	
	ll ok = 0;
	rep(hp,1<<h){
		rep(wp,1<<w){
			ll ct = 0;
			rep(i,h){
				rep(j,w){
					if ( (hp & (1<<i)) && (wp & (1<<j)) && (v[i] & (1<<j)) )
						ct++;
				}
			}
			if ( ct == k )
				ok++;
		}
	}
	cout << ok << endl;
	
	return 0;
}




Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int n,a,b,c,an,d,e;
string s,sa;
signed main()
{
	cin>>n>>c;
	d=n;
	e=c;
	a=max(n,c);
	b=min(n,c);
	while(1){
		if(a%b==0){
			an=b;
			break;
		}
		c=b;
		n=a%b;
		a=c;
		b=n;
	}
	cout<<d*e/an;
}

Measured memory_bytes: 256
#define LL long long

#include<iostream>
#include<string>
using namespace std;

inline int judge(string x,LL be,LL size){//文字列xの(be)~(size-1)番目までと(size)~(size+size)番目を比較。
	LL s=0,ans=0;
	 for(LL num=size;num>0;num--){
	   if(x[be+s]==x[size+s]){}else{
		  ans=1;
		  break;
	    }
	   s++;
	 }
	return ans;
}

int main(){
	string s;
	cin>>s;
	int n=1;
	while(1){
		if(judge(s,0,(s.size()-n)/2)==0){
			break;
		}else{
			n++;
		}
	}
	cout<<(s.size()-n-1)<<endl;
	return 0;
}


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

int d, n;
int t[202];
int a[202], b[202], c[202];

int memo[256][256];

int dfs(int i, int pre)
{
  if (i == d - 1) {
    int maxi = 0;
    for (int x = 0; x < n; x++) {
      if (a[x] <= t[i] && t[i] <= b[x]) {
        maxi = max(maxi, abs(c[pre] - c[x]));
      }
    }
    return maxi;
  }
  int& maxi = memo[i][pre];
  if (maxi != -1) return maxi;
  maxi = 0;
  for (int x = 0; x < n; x++) {
    if (a[x] <= t[i] && t[i] <= b[x]) {
      maxi = max(maxi, dfs(i + 1, x) + abs(c[pre] - c[x]));
    }
  }
  return maxi;
}

int main()
{
  memset(memo, -1, sizeof(memo));
  cin >> d >> n;
  for (int i = 0; i < d; i++){
    cin >> t[i];
  }
  for (int i = 0; i < n; i++){
    cin >> a[i] >> b[i] >> c[i];
  }

  int maxi = 0;
  for (int i = 0; i < n; i++){
    if (a[i] <= t[0] && t[0] <= b[i]) {
      maxi = max(maxi, dfs(1, i));
    }
  }

  cout << maxi << endl;
}

Measured memory_bytes: 3352
// https://atcoder.jp/contests/abcXXX/tasks/abcXXX_x

#include <bits/stdc++.h>

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

static const ll INF = 1001001001;
static const ll LLINF = 1001001001001001001;
static const ll MOD = (ll)1e9 + 7;
static const double EPS = 1e-9;

#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define RANGE(i, m, n) for(ll i = (m); i <= (n); ++i)
#define RRANGE(i, m, n) for(ll i = (m); i >= (n); --i)
#define POSITIVE(x) (x)=((x) < 0) ? 0 : (x)

ll power(ll x, ll y) {
    ll ret = 1;
    while(y-- > 0) ret *= x;
    return ret;
}

ll gcd(ll a, ll b) {
    assert(a >= 0);
    assert(b >= 0);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll extgcd(ll a, ll b, ll& x, ll& y) {
    x = 1; y = 0;
    assert(a >= 0);
    assert(b >= 0);
    if (b == 0) return a;
    ll X, Y;
    auto d = extgcd(b, a % b, X, Y);
    x = Y;
    y = X - (a / b) * Y;
    return d;
}

int run(istream& in, ostream& out) {

    string S;
    in >> S;
    out << (S[2] == S[3] && S[4]==S[5] ? "Yes" : "No") << endl;
    return 0;
}

int main() {
    return run(cin, cout);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;


ll dp[100005][3];
ll happy[100005][3];
int main() {
    int N;
    cin >> N;
    // rep(i,N)rep(j,3) cin >> abc[i+1][j];

    for(int i = 1;i <= N;i++){
        cin >> happy[i][0] >> happy[i][1] >> happy[i][2];
    }
    for (int i = 1; i <= N; i++){
        for(int act = 0;act<3; act++){
            for (int prev = 0;prev<3;prev++){
                if (act == prev) continue;
                dp[i][act] = max(dp[i][act], dp[i-1][prev] + happy[i][act]);
                }
            }
        }
    ll ans = 0;
    rep(i,3) ans = max(ans,dp[N][i]);
    cout << ans << endl;
    return 0;
}

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

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
typedef int64_t Int;
typedef std::vector<Int> LI;
const double pi = 3.14159265358979323846264338;
const Int mod = 1000000007;

template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(Int& x) { if( scanf("%" PRId64, &x) < 0 ) exit(0); }
template<> void scan1(std::string& x) { if( not ( std::cin >> x ) ) exit(0); }
template<> void scan1(LI& xs) { for(Int &x : xs) scan1(x); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
  scan1(x); scan(xs...);
}

template<typename T>
struct Maybe {
   T x;
   bool valid;
   Maybe() : valid(false) {}
   Maybe(T x_) : x(x_), valid(true) {}
   operator T() const {
      assert( valid );
      return x;
   }
};

struct Solver {
   Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
   ~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
   void solve() {
      Int n, m; scan(n, m);
      Int res = (1900 * m + 100 * (n - m)) * pow(2, m) + 1e-10;
      printf("%ld\n", res);
   }
};

int main() {
   loop std::unique_ptr<Solver>(new Solver())->solve();
}




Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>

using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (c - (a - b) < 0) {
		cout << "0" << endl;
	}
	else {
		cout << c - (a - b) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han
//Bismillahirrahmanirrahim

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long int lo;
typedef pair< int,int > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000; 
const lo MIN = 1000000000000000000; 
const lo inf = 1000000000; 
const lo KOK = 100000; 
const lo LOG = 30; 
const lo li = 100005; 
const lo mod = 1000000007; 

int n,m,b,a[li],k,flag,cev;
string s;
vector<int> v;

int main(void){
	scanf("%d %d",&n,&m);
	printf("%d\n",n*n-m);
	
	return 0;
}


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

#define MAXN 300010

vector<int> edge[MAXN];
int fa[MAXN],color[MAXN],no,c2,el,visit[MAXN],n,m;

int findfa(int x)
{
	return fa[x]==x?x:fa[x]=findfa(fa[x]);
}

bool dfs(int u)
{
	for(auto v:edge[u])
	{
		if(color[v]==color[u])return false;
		if(color[v])continue;
		color[v]=3-color[u];
		if(!dfs(v))return false;
	}
	return true;
}

void cover(int u)
{
	visit[u]=true;
	for(auto v:edge[u])
	{
		if(visit[v])continue;
		cover(v);
	}
}

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i)fa[i]=i;
	for(int i=1;i<=m;++i)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		edge[u].push_back(v);
		edge[v].push_back(u);
		fa[findfa(u)]=findfa(v);
	}
	for(int i=1;i<=n;++i)
	{
		if(visit[i])continue;
		if(edge[i].empty())++no;
		else
		{
			color[i]=1;
			if(dfs(i))++c2;else ++el;
			cover(i);
		}
	}
	printf("%lld\n",(long long)no*no+(long long)no*(n-no)*2+(long long)el*c2*2+(long long)el*el+(long long)c2*c2*2);
}

Measured memory_bytes: 15616
#import math
from fractions import gcd

N = int(input())
As = [int(elm) for elm in input().split(" ")] 

if N >= 3:
    L = []
    R = []

    gl = As[0]
    gr = As[N-1]
    L.append(gl)
    R.append(gr)

    for i in range(1, N-1):
        gl = gcd(gl, As[i]) 
        L.append(gl)

    for i in range(1, N-1):
        gr = gcd(gr, As[N-i-1])
        R.append(gr)

    for i in range(N):
        if i == 0:
            max_g = R[N-2]
        else:
            if i == N-1:
                cur_g = L[N-2]
            else:
                cur_g = gcd(L[i-1], R[N-2-i])
            max_g = max(max_g, cur_g)

    out = max_g
else:
    out = max(As)

print(out)

Measured memory_bytes: 16640
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from functools import reduce

from collections import deque, Counter, defaultdict
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import statistics
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
def lcm(a, b):
  return a*b//gcd(a, b)

def main():
  n = int(readline())
  a = np.array(readline().split(), np.int64)
  a -= np.arange(1,n+1)
  median = np.median(a).astype(np.int64)

  print(np.abs(a-median).sum())
  
  
  
  
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 27724
#include<bits/stdc++.h>
#define int long long
#define re(i,n) for(i=0;i<n;i++)
#define bre(i,n) for(i=n;i>0;i--)
#define rep(i,l,r) for(i=l;i<r;i++)
#define brep(i,l,r) for(i=r;i>l;i--)
const int inf=1145141919810893;
const int mod=1000000007;
using namespace std;
template<class T>bool chmin(T &a,const T &b){
	if(a>b){
		a=b;
		return true;
	}
	return false;
}
template<class T>bool chmax(T &a,const T &b){
	if(a<b){
		a=b;
		return true;
	}
	return false;
}
template<class T>void debug(T *a,int l,int r,const char *name){
	for(int i=l;i<r;i++)
		cout<<name<<"["<<i<<"]="<<a[i]<<endl;
}
template<int H,int W>int wa(int x1,int y1,int x2,int y2,int(&p)[H][W]){
	return p[y2][x2]-p[y2][x1]-p[y1][x2]+p[y1][x1];
}
int A,B,C,D,N,M,K,T,H,W;
int p[100],q[100];
unordered_map<int,int> uma[2];
string s,t;
signed main(){
	int i,j,k;
	cin>>N;
	re(i,N)
		cin>>p[i];
	re(i,N)
		cin>>q[i];
	int ans=0;
	re(i,N){
		int u=0;
		re(j,i+1)
			u+=p[j];
		rep(j,i,N)
			u+=q[j];
		chmax(ans,u);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int D;
  cin >> D;
  if(D==25){
    cout << "Christmas" << endl;
  }
  if(D==24){
    cout << "Christmas Eve" << endl;
  }
  if(D==23){
    cout << "Christmas Eve Eve" << endl;
  }
  if(D==22){
    cout << "Christmas Eve Eve Eve" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std ;
typedef long long int ll ;
#define MXN 100005

ll a[MXN];

int main(){
	ios;
	int n,m;
	cin>>n>>m;
	priority_queue<ll> pq;
	for(int i=0; i<n; i++){
		ll ai;
		cin>>ai;
		pq.push(ai);
	}
	
	while(m--){
		int pp=pq.top();pq.pop();
		pq.push(pp/2);
	}
	ll sum=0;
	while(pq.size()) {
		sum+=pq.top(); pq.pop();
	}
	
	cout<<sum<<'\n'; 
	return 0;
}



Measured memory_bytes: 1400
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    int N;
    cin >> N;
    int M = N, S = 0;
    while (M > 0) {
        S += M % 10;
        M /= 10;
    }
    if (N % S == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define gcd __gcd
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define min3(a,b,c) min(a,min(b,c))
#define mai3(a,b,c) mai(a,mai(b,c))
#define all(i) i.begin(),i.end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define set_bit __builtin_popcount //gives number of set_bits
#define ff first
#define ss second
#define cases(t) int t; cin>>t; rep(casn,1,t+1)
#define el cout<<endl;
#define deci(n) int n; cin>>n;
#define decs(n) string n; cin>>n;
//SUNEET KUMAR -->  ਸੁਨੀਤ 
int power(int a,int n)//binary expo
{
    int r;
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
        r=power(a,n/2);
    if(n%2==0)
        return ((r)%mod)*((r)%mod)%mod;
    else
        return ((((r)%mod)*((r)%mod))%mod*((a)%mod))%mod;
}
int mai(int a,int b)
{
    if(a>b)
    return a;
    else 
    {
        return b;
    }
}
int madd(int a,int b)
{
    int ans;
    ans=(a%mod+b%mod)%mod;
    return ans;
}
int mmult(int a,int b)
{
    int ans=1;
    ans=((a%mod)*(b%mod))%mod;
    return ans;
}

int modinverse(int a)
{
    return power(a,mod-2);
}
signed main()
{
     deci(x);
     int cns[6]={100,101,102,103,104,105};
     if(x==0)
     {
         cout<<1;
     }
     else
     {
         int dp[x+4];
         for(int i=0;i<=x;i++)
         {
             dp[i]=0;
         }
         for(int i=100;i<=x;i++)
         {
             for(int j=0;j<6;j++)
             {
                 if(i==cns[j])
                 {
                     dp[i]=1;
                 }
                 else if(dp[i-cns[j]]==1)
                 {
                     dp[i]=1;
                 }
             }
         }
         if(dp[x]==1)
         {
             cout<<1;
         }
         else
         {
             cout<<0;
         }
     }

}

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

int main(){
    int N;
    cin >> N;
    int min_a = pow(10,9.0) , max_a = 0;

    for ( int i = 0 ; i < N ; i++ ){
        int a;
        cin >> a;
        max_a = max(a,max_a);
        min_a = min(a,min_a);
    }
    cout << max_a - min_a << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dbl;
#define sqr(int) (int * int)
#define sqr3(int) (int * int * int)
#define pi M_PI
#define nl "\n"


int main(void) {
int a, b, h, m;
 scanf("%d%d%d%d", &a, &b, &h, &m);

 long double rad = pi * 2 * (
  (long double)h / 12.0 + ((long double)m / 60.0) / 12.0 - (long
double)m / 60.0);
 long double rsq = (long double)(a * a + b * b) - (long double)(2 * a *
b) * cosl(rad);

 printf("%20.20Lf\n", sqrtl(rsq)); 
 return 0;
 }


Measured memory_bytes: 4208
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		
		Scanner sc=new Scanner(System.in);
		
		int N=sc.nextInt();
		int L=sc.nextInt();
		String[] S=new String[N];
		
		for(int i=0;i<N;i++) {
			S[i]=sc.next();
		}
				
		Arrays.sort(S);
		
		for(int i=0;i<N;i++) {
			System.out.print(S[i]);
		}
		
		sc.close();
	}
}


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

int main() {
	int n;
	cin >> n;
	if(n == 0) {
		cout << "0" << endl;
		return 0;
	}
	string s = "";
	while(n) {
		if(n % 2) {
			s.insert(0, "1");
			n--;
		} else {
			s.insert(0, "0");
		}
		n /= -2;
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256