akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
static const int INF = (1<<30)-1;
struct C{ int x; int y; };
bool asc( const C& left, const C& right ) {
  return left.x == right.x ? left.y < right.y : left.x < right.x;
}

int n;
C a[109],b[109];
int main(){
  cin >> n;
  for(int i=0;i<n;i++) cin >> a[i].x >> a[i].y;
  for(int i=0;i<n;i++) cin >> b[i].x >> b[i].y;

  sort(a,a+n,asc);
  sort(b,b+n,asc);

  int ret = 0, j = 0;
  for(int i=0;i<n;i++){
    int ymax = -1,r;
    for(int j=0;j<n;j++){
      if(a[j].x < b[i].x && a[j].y < b[i].y){
        if(ymax < a[j].y){
          ymax = a[j].y;
          r = j;
        }
      }
    }
    if(ymax != -1){
      a[r].x = INF; a[r].y = INF;
      ret++;
    }
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int i,j,k;
  int h[508],m,n;
  h[0]=1;
  k=1;
  for(i=2;i<=1000000;i++){
    j=i;
    for(;;){
      if(j%2==0)
	j/=2;
      else if(j%3==0)
	j/=3;
      else if(j%5==0)
	j/=5;
      else
	break;
      if(j==1){
	h[k]=i;
	k++;
      }
    }
  }
  h[k]=1000001;
  for(;;){
    scanf("%d",&m);
    if(m==0)
      break;
    scanf("%d",&n);
    for(i=0;i<507;i++){
      if(h[i]<m&&m<h[i+1]){
	i++;
	break;
      }else if(h[i]==m)
	break;
    }
    for(j=507;j>0;j--){
      if(h[j-1]<n&&n<h[j]){
	j--;
	break;
      }else if(h[j]==n)
	break;
    }
    printf("%d\n",j-i+1);
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
// ll mod=1000000007;
// ld pi = 3.14159;

int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);
    ll t,t1,i,j,k,temp,temp2,n,m,x,y,z,sum=0,o;
    string a;
    cin >> a;
    for(i=0;i<a.size()-1;i++){
        if(a[i]=='?'&&a[i+1]=='?'){
            a[i]='P';
            a[i+1]='D';
        }
        else if(a[i]=='?'){
            if(a[i+1]=='D') a[i] = 'P';
            else a[i]='D';
        }
        else if(a[i+1]=='?'){
            if(a[i]=='P') a[i+1] = 'D';
        }
    }
    if(a[a.size()-1]=='?') a[a.size()-1] = 'D';
    cout << a;
}


Measured memory_bytes: 3740
#include<stdio.h>
int main(void){
    char string[101];
    int num_string;
    int i,j,k=0;
    char X[100],Y[100];
    int kinds=0;
    int count=0,max=0;
    //printf("Input the length of string:");
    scanf("%d",&num_string);
    //printf("Input string:");
    scanf("%s",string);
 
    for(i=0;i<num_string-1;i++){
        //printf("i:%d ",i);
        for(j=0;j<=i;j++){
            X[j]=string[j];
        }
        //printf("X:%s\n",X);
        k=0;
        for(j=i+1;j<num_string;j++){
            Y[k]=string[j];
            //printf("Y[%d]:%c\n",k,Y[k]);
            for(int m=0;m<=i;m++){
                if(Y[k]==X[m]){
                    count++;
                    //printf("count:%d\n",count);
                    for(int n=m;n<=i;n++){
                        //printf("n:%d\n",n);
                        if(Y[k]==X[n]){
                            X[n]=' ';
                        }
                    }
                }
            }
            k++;
            if(kinds<count){
            kinds=count;
            }
        }
        count=0;
 
    }
    printf("%d",kinds);
    return 0;
}

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

int main() {
  
  vector<int> c(9);
  for(int i = 0; i < 9; i++) {
    cin >> c.at(i);
  }
  
  bool ans = true;
  if(c.at(0) + c.at(4) != c.at(1) + c.at(3))
    ans = false;
  if(c.at(2) + c.at(4) != c.at(1) + c.at(5))
    ans = false;
  if(c.at(4) + c.at(6) != c.at(3) + c.at(7))
    ans = false;
  if(c.at(4) + c.at(8) != c.at(5) + c.at(7))
    ans = false;
  if(c.at(0) + c.at(8) != c.at(2) + c.at(6))
    ans = false;
  if(c.at(3) + c.at(8) != c.at(5) + c.at(6))
    ans = false;
  if(c.at(0) + c.at(5) != c.at(2) + c.at(3))
    ans = false;
  if(c.at(1) + c.at(8) != c.at(2) + c.at(7))
    ans = false;
  if(c.at(0) + c.at(7) != c.at(1) + c.at(6))
    ans = false;
  
  if(ans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
import heapq

N, M = map(int, input().split())
A = list(map(lambda x: int(x) * -1, input().split()))
heapq.heapify(A)

for _ in range(M):
    a_min = heapq.heappop(A)
    heapq.heappush(A, -1 * (-a_min//2))

print(-sum(A))


Measured memory_bytes: 14180
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
const int MAX_N=500000;
int n,dat[2000000];
void init(int n_){
    n=1;
    while(n<n_) n*=2;
    rep(i,2*n-1) dat[i]=0;
}
void update(int k,char a){
    k+=n-1;
    dat[k]=int(pow(2,a-'a'));
    while(k>0){
        k=(k-1)/2;
        dat[k]=dat[k*2+1]|dat[k*2+2];
    }
}
int query(int a,int b,int k,int l,int r){
    if(r<=a||b<=l) return 0;
    if(a<=l&&r<=b) return dat[k];
    else{
        int vl=query(a,b,k*2+1,l,(l+r)/2);
        int vr=query(a,b,k*2+2,(l+r)/2,r);
        return vl|vr;
    }
}
int main(){
    int N,Q;
    string s;
    cin>>N>>s>>Q;
    init(N);
    rep(i,N) update(i,s[i]);
    vec ANS;
    rep(i,Q){
        int q,iq,lq,rq;
        char cq;
        cin>>q;
        if(q==1) cin>>iq>>cq,update(iq-1,cq);
        else{
            cin>>lq>>rq;
            ll p=query(lq-1,rq,0,0,n),ans=0;
            while(p>0) ans+=p%2,p/=2;
            ANS.push_back(ans);
        }
    }
    for(auto i:ANS) cout<<i<<"\n";
}

Measured memory_bytes: 7300
//Reference : https://atcoder.jp/contests/abc167/submissions/13005847
#include<bits/stdc++.h>
//macros
using namespace std;
typedef long long ll;
typedef pair<int, int > Pii;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef vector<ll> Vll;
#define pb push_back
#define rs resize 
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define repll(i, a, b) for(ll i=(a); i<(b); i++)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define COUT(a) cout << a << endl
#define ALL(a) (a).begin(),(a).end()
const long long int mod = 1e9 + 7;
const int INF = 1001001001;
int a[12][12];

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false); 
    int n,m,x;
    int ans = INF;
    cin >> n >> m >> x;
    vector<int> c(n);
    rep(i,0,n){
        cin >> c[i];
        rep(j,0,m) cin >> a[i][j];
    }
    rep(i,0,(1<<n)){
        int cost=0;
        vector<int> d(m);
        rep(j,0,n){
            if((i>>j)&1){
                //cout<<i<<endl;
                cost += c[j];
                rep(k,0,m) d[k] += a[j][k];
            }
        }
        bool flag = true;
        rep(j,0,m) if(d[j] < x) flag = false;
        if(flag) ans = min(ans, cost);
        //cout << cost << endl;
    }
    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}


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

int digits(int n) {
	int sum = 0;

	while (n > 0) {
		sum += n % 10;
		n /= 10;
	}

	return sum;
}

int main() {
	int N, A, B;
	cin >> N >> A >> B;

	int ans = 0;

	for (int i = 0; i < N; i++) {
		if (A <= digits(i + 1) && digits(i + 1) <= B) {
			ans += i+1;
		}
	}

	cout << ans << "\n";

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int sum(int n)
{
  	int x=0;
  	while(n)
    {
      	x+=n%10;
      	n/=10;
    }
  	return x;
}
  	
  	int main()
    {
      	int n;
      	cin>>n;
      	int x=sum(n);
      	if(n%x==0)
          cout<<"Yes\n";
      	else
          cout<<"No\n";
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		int x=s.nextInt(), y=s.nextInt(), z=s.nextInt();
		int a,b,c;
		a=y;
		b=x;
		c=a;
		a=z;
		System.out.println(a+" "+b+" "+c);

	}


}


Measured memory_bytes: 21076
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>

using namespace std;

int main(){
	int A, B, C, D;
	int right, left;

	cin >> A >> B >> C >> D;

	left = A + B;
	right = C + D;

	if(left > right){
		cout << "Left" << endl;
	}
	else if(left < right ){
		cout << "Right" << endl;
	}
	else{
		cout << "Balanced" << endl;
	}
}

Measured memory_bytes: 3644
#include<iostream>
using namespace std;
 
 
int main(){
	int t=0;
	cin>>t;
	while(t!=0){
		int a=t%10;
		if(a==7){
			cout<<"Yes";
          		return 0;
		}
		t/=10;
    }
	cout<<"No";
  	return 0;
}

Measured memory_bytes: 3624
N,M,R = map(int,input().split())
R = list(map(int,input().split()))
ABC = [tuple(map(int,input().split())) for i in range(M)]

INF = float('inf')
d = [[INF]*N for _ in range(N)]
for i in range(N):
    d[i][i] = 0
for a,b,c in ABC:
    a,b = a-1,b-1
    d[a][b] = d[b][a] = c

for k in range(N):
    for i in range(N):
        for j in range(N):
            d[i][j] = min(d[i][j], d[i][k] + d[k][j])

ans = INF
import itertools
for ptn in itertools.permutations(R):
    tmp = 0
    for a,b in zip(ptn,ptn[1:]):
        tmp += d[a-1][b-1]
    ans = min(ans, tmp)
print(ans)

Measured memory_bytes: 77892
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
std::mt19937 rnd(time(NULL));
#define rand rnd
#define pr std::pair<int,int>
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
template<class T>void cxk(T&a,T b){a=a>b?a:b;}
template<class T>void cnk(T&a,T b){a=a<b?a:b;}
#ifdef mod
int pow(int x,int y){
	int ret=1;
	while(y){
		if(y&1)ret=1ll*ret*x%mod;
		x=1ll*x*x%mod;y>>=1;
	}
	return ret;
}
template<class Ta,class Tb>void inc(Ta&a,Tb b){a=a+b>=mod?a+b-mod:a+b;}
template<class Ta,class Tb>void dec(Ta&a,Tb b){a=a>=b?a-b:a+mod-b;}
#endif
ll len[41],x[1001],y[1001];
int main(){
#ifdef LOCAL
	freopen("in.in","r",stdin);
	//freopen("out.out","w",stdout);
#endif
	int n=gi(),s=0;
	for(int i=1;i<=n;++i)x[i]=gi(),y[i]=gi(),s|=1<<(x[i]+y[i]&1);
	if(s==3)puts("-1"),exit(0);
	int m=0;len[++m]=1;if(s==1)len[++m]=1;
	for(int i=1;i<=31;++i)len[++m]=1ll<<i;
	std::reverse(len+1,len+m+1);
	printf("%d\n",m);for(int i=1;i<=m;++i)printf("%lld ",len[i]);puts("");
	for(int i=1;i<=n;++i){
		ll X=0,Y=0;
		for(int j=1;j<=m;++j){
			ll dL=llabs(X-len[j]-x[i])+llabs(Y-y[i]);
			ll dR=llabs(X+len[j]-x[i])+llabs(Y-y[i]);
			ll dU=llabs(X-x[i])+llabs(Y+len[j]-y[i]);
			ll dD=llabs(X-x[i])+llabs(Y-len[j]-y[i]);
			ll mn=std::min({dL,dR,dU,dD});
			if(mn==dL)X-=len[j],putchar('L');
			else if(mn==dR)X+=len[j],putchar('R');
			else if(mn==dU)Y+=len[j],putchar('U');
			else Y-=len[j],putchar('D');
		}
		assert(X==x[i]&&Y==y[i]);
		puts("");
	}
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
int Max(int(a), int(b), int(c)) {
	return max(max(a, b), c);
}
int Min(int(a), int(b), int(c)) {
	return min(min(a, b), c);
}
int gcd(ll(a), ll(b)) {
	ll q = a;
	ll w = b;
	ll e = q;
	while (q % w != 0) {
		e = q % w;
		q = w;
		w = e;
	}
	return w;

}





int main() {
	ll A,B,K;
	cin >> A >> B >> K;
	int i = 0;
	while (i < K) {
		if (i % 2 == 0) {
			if (A % 2 ==1) {
				A--;
			}
			A /= 2;
			B += A;
			i++;
		}
		else {
			
				if (B % 2 == 1) {
					B--;
				}
				B /= 2;
				A += B;
				i++;
		}
	}
	cout << A << " " << B << endl;


	
	
}

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

#define pb push_back
#define rep(i, a, n) for(int (i)=a; (i)<(n); (i)++)
#define FOR(i, n) rep(i, 0, n)
#define F(n) FOR(i, n)
#define FF(n) FOR(j, n)
#define repi(i, a, n) for(int (i)=a; (i)<=(n); (i)++)
#define FORI(i, n) repi(i, 1, n)
#define FI(n) FORI(i, n)
#define FFI(n) FORI(j, n)
#define IN(x) int x; cin>>(x);
#define SIN(x) string x; cin>>x;
#define INN(x, y) int x, y; cin>>(x)>>(y);
#define INFO(a) cout<<"info "<<a<<endl
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int, int>
#define vpii vector<pair<int, int> >
#define sortv(x) sort((x).begin(), (x).end())
#define sortvd(x) sort((x).begin(), (x).end(), greater<int>())
#define lboundv(x,v) lower_bound((x).begin(),(x).end(),(v))-(x).begin();
#define uboundv(x,v) upper_bound((x).begin(),(x).end(),(v))-(x).begin();
#define ite iterator
#define fi first
#define se second
#define mems(a, v) memset((a), (v), sizeof((a)))
#define lmid(l, r) ((l)+(r)-1)/2
#define rmid(l, r) ((l)+(r))/2+1
#define mp make_pair

typedef long long ll;
typedef long double LD;

using namespace std;

#define N 50
vi a(N);
ll memo[N];
int n;
ll solve(int i) {
	if(i==n) return 1;
	if(memo[i]!=-1) return memo[i];
	if(a[i]&1) return memo[i] = solve(i+1);
	else return memo[i] = 2*solve(i+1);
}
int main() {
	ios::sync_with_stdio(0);
	cin>>n;
	//vi a(n);
	F(n) cin>>a[i];
	ll ans = 1;
	F(n) ans *= 3;
	mems(memo, -1);
	ans -= solve(0);
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

static const long long MOD=1e9+7;

long long modpow(long long b, long long e, long long p=MOD) {
    /* Exponentiation by squaring */
    // returns n == b**e (mod p)
    long long n=1, a=b%p;
    while (e) {
        if (e & 1)
            (n *= a) %= p;

        (a *= a) %= p;
        e >>= 1;
    }
    return n;
}

int main() {
    size_t N;
    scanf("%zu", &N);

    vector<int> B(N);
    for (size_t i=0; i<N; ++i) {
        size_t A;
        scanf("%zd", &A);
        if (++B[A] > 2)
            return !printf("0\n");
    }

    if (N & 1) {
        if (B[0] != 1)
            return !printf("0\n");

        for (size_t i=1; i<N; ++i) {
            if (i & 1) {
                if (B[i]) return !printf("0\n");
            } else {
                if (B[i] != 2) return !printf("0\n");
            }
        }
    } else {
        for (size_t i=0; i<N; ++i) {
            if (i & 1) {
                if (B[i] != 2) return !printf("0\n");
            } else {
                if (B[i]) return !printf("0\n");
            }
        }
    }

    printf("%lld\n", modpow(2, N/2));
    return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<map>

using namespace std;

int main(){
  int i,n,mc,mcount,b;
  map<int,int > cl;
  map<int,int >::iterator it;
  while(1){
    scanf("%d",&n);
    if(!n) break;
    cl.clear();
    scanf("%d",&mc);
    cl.insert(pair<int,int>(mc,1));
    mcount=1;
    for(i=1;i<n;i++){
      scanf(" %d",&b);
      it=cl.find(b);
      if(it==cl.end()){
	cl.insert(pair<int,int>(b,1));
      }else{
	(*it).second++;
	if((*it).second>mcount){
	  mc=b;
	  mcount=(*it).second;
	}
      }
    }
    if(2*mcount>n){
      printf("%d\n",mc);
    }else{
      printf("NO COLOR\n");
    }
  }
  return 0;
}

Measured memory_bytes: 1848
/*input
4
10 30 40 20
*/

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long 
#define vl vector<ll> 
#define pl pair<ll,ll> 
#define vpl vector<pl> 
#define vvl vector<vl> 
using namespace std;
const int N = 1e5+5;
ll h[N], ans[N];
int main()

{
	ios_base::sync_with_stdio(false); 
    cin.tie(0); cout.tie(0);
   
    ll n;
    cin>>n;
    for(int i=0; i<n; ++i) cin>>h[i];
    ans[n-1]=0;
	ans[n-2] = (ll)(abs(h[n-1]-h[n-2]));
	// ans[i] --> i se n tak jaane ki cost
	for(int i=n-3; i>=0; --i){
		// ans[3] = min(ans[4]+3 to 4,    ans[5] + 3 to 5)
		ans[i] = min(ans[i+1]+(ll)(abs(h[i]-h[i+1])), ans[i+2]+(ll)(abs(h[i]-h[i+2])));
	}


	cout<<ans[0];
        

  return 0;
   		
}

Measured memory_bytes: 5208
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                             \
  cerr << __LINE__ << ": " << #x << " = {";          \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) { \
    cerr << ((hoge) ? "," : "") << x[hoge];          \
  }                                                  \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N, M;
  cin >> N >> M;
  cout << N * (N - 1) / 2 + M * (M - 1) / 2 << endl;
  return 0;
}


Measured memory_bytes: 3648
# coding: utf-8
import sys
from collections import Counter

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

S = sr()
T = sr()
cnt_S = Counter(S)
cnt_T = Counter(T)
num_S = sorted(list(cnt_S.values()))
num_T = sorted(list(cnt_T.values()))

bl = num_S == num_T
print('Yes' if bl else 'No')


Measured memory_bytes: 4136
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define vll vector<ll>
#define vvll vector<vll>
#define vvi vector<vector<int>>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define pii pair<int, int>
#define vpli vector<pair<long long, int>>
#define deb(x) cout << "deb " << #x << " " << x << endl
#define all(x) x.begin(), x.end()
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define endl "\n"
template <typename T>
void printvec(vector<T> &v, int n, int start = 0)
{
    //cout << "\nprinting vector\n";
    for (int i = start; i < n; i++)
    {
        cout << v[i] << " ";
    }
    cout << "done printing";
    cout << endl;
}
const int mod = 1e9 + 7;
const int BIG = 1e7 + 7;
inline void swap(int &a, int &b)
{
    int t = a;
    a = b;
    b = t;
}

void solve()
{
    string s;
    cin>>s;
    if(s[s.size()-1] == 's')
    {
        s=s+"es";
    }
    else
    {
        s = s+"s";
    }
    cout<<s<<endl;
    
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}


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

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

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

const int MAXN = 1e5 + 5;

int n, m;
int par[MAXN], comp[MAXN], sz[MAXN];

int f(int x) {
  if(par[x] == x) return x;
  return par[x] = f(par[x]);
}

void unija(int x, int y) {
  x = f(x); y = f(y);
  if(x == y) return;

  sz[y] += sz[x];
  par[x] = y;
}

vector<int> ee, e[MAXN];

int c[MAXN];

bool bipartite(int x, int y) {
  if(c[x]) {
    if(c[x] != y) return false;
    return true;
  }

  c[x] = y;

  bool ret = true;
  for(auto w: e[x]) {
    ret &= bipartite(w, 3 - y);
  }

  return ret;
}

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

  cin >> n >> m;

  REP(i, n) {
    par[i] = i;
    sz[i] = 1;
  }

  REP(i, m) {
    int x, y; cin >> x >> y;
    x --; y --;
    e[x].push_back(y);
    e[y].push_back(x);
    ee.push_back(x);
    unija(x, y);
  }

  for(auto &x: ee) {
    comp[f(x)] ++;
  }

  ll sol = 0;
  int pola = 0, cijela = 0, prazni = 0;

  REP(i, n) {
    if(f(i) != i) continue;

    if(sz[i] > 1) {
      sol ++;
      if(bipartite(i, 1)) {
        sol ++;
        sol += cijela * 2;
        sol += pola * 4;
        pola ++;
      }
      else {
        sol += cijela * 2;
        sol += pola * 2;
        cijela ++;
      }
    }
    else {
      sol += n * 2 - 1;
      sol -= prazni * 2;
      prazni ++;
    }
  }

  cout << sol;
}


Measured memory_bytes: 11764
#include <bits/stdc++.h>
using namespace std;
#define rep2(i,m,n) for (int i = (m); i < (n); ++i)
#define rep(i,n) rep2(i,0,n)
#define debug(x) cerr << x << endl
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> P;
template<typename T> struct V : vector<T> { using vector<T>::vector; };
V() -> V<int>;
V(size_t) -> V<int>;
template<typename T> V(size_t, T) -> V<T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
const int INF = 1<<30;
const ll LINF = 1LL<<61;
const ll MOD = 1000000007;

int main()
{
    int n;
    cin >> n;
    V<ll> dp(4);
    dp[0] = 1;
    rep(i,n)
    {
        V<ll> dp2(4);
        rep(j, 4)
        {
            if(j == 0) //なし
            {
                dp2[1] += dp[j]; //0
                dp2[2] += dp[j]; //9
                dp2[0] += dp[j] * 8; //1-8
            }
            else if(j == 1) //0
            {
                dp2[1] += dp[j] * 9; //0-8
                dp2[3] += dp[j]; //9
            }
            else if(j == 2) //9
            {
                dp2[2] += dp[j] * 9; //1-9
                dp2[3] += dp[j]; //0
            }
            else if(j == 3) //0, 9
            {
                dp2[3] += dp[j] * 10;
            }
        }
        rep(j,4) dp2[j] %= MOD;
        swap(dp, dp2);
    }
    cout << dp[3] << endl;
}


Measured memory_bytes: 3652
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	int ans = k* pow((k-1),n-1);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {


    Scanner sc =new Scanner(System.in);
   int a = sc.nextInt();
   if(a>=100) {
	   if(a%100==11) {
		   System.out.println(3);

	   }
	   else if(a%100==1) {
		   System.out.println(2);
	   }
	   else if(a%100==10) {System.out.println(2);}
		   else {System.out.println(1);}

	   }

   else if(a>=10) {
	   if(a%10==1) {System.out.println(2);}
	   else {System.out.println(1);}


   }
   else if(a>=1) {System.out.println(1);}
   else {System.out.println(0);}
	}

}


Measured memory_bytes: 21844
h,w,k = map(int,input().split())
mod = 10**9+7
am = [1,1,2,3,5,8,13,21]
DP = [[0 for i in range(w+1)] for j in range(h+1)]
DP[0][1] = 1
for i in range(1,h+1):
  for j in range(1,w+1):
    DP[i][j] = (DP[i-1][j]*am[j-1]*am[w-j])%mod
    if j > 1:
      DP[i][j] += (DP[i-1][j-1]*am[j-2]*am[w-j])%mod
    if j < w:
      DP[i][j] += (DP[i-1][j+1]*am[j-1]*am[w-j-1])%mod
print((DP[h][k])%mod)

Measured memory_bytes: 3192
#include <climits>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define int long long 
const int _ = 1e5 + 100;
int read() { int x; scanf("%lld", &x); return x; }
struct Node_t{
    int x, y, i;
}Node[_];
int n;
bool CMPByX(const Node_t &x, const Node_t &y) { return x.x < y.x; }
bool CMPByY(const Node_t &x, const Node_t &y) { return x.y < y.y; }

struct edges{ int u, v, w; edges(){} edges(int a, int b, int c) { u = a; v = b; w = c; } };
vector<edges> E;
int bucx[_], txt = 0;
int bucy[_], tyt = 0;
int GetXNodeID(int x) { return (lower_bound(bucx + 1, bucx + 1 + txt, x) - bucx + n); }
int GetYNodeID(int y) { return (lower_bound(bucy + 1, bucy + 1 + tyt, y) - bucy + n + txt); }
bool CMP (const edges & A, const edges & B) { return A.w < B.w; }

int fa[_];
void init(int n) { for(int i = 1; i <= n; i++)fa[i] = i; }
int  find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
void merge(int x, int y) { x = find(x); y = find(y); fa[x] = y; }
bool ask(int x, int y)  { return find(x) == find(y); }

signed main(){
    n = read();
    for(int i = 1; i <= n; i++) {
        Node[i].x = read(); bucx[i] = Node[i].x;
        Node[i].y = read(); bucy[i] = Node[i].y;
        Node[i].i = i;
    }
    sort(bucx + 1, bucx + 1 + n);
    txt = unique(bucx + 1, bucx + 1 + n) - bucx - 1;
    sort(bucy + 1, bucy + 1 + n);
    tyt = unique(bucy + 1, bucy + 1 + n) - bucy - 1;
    for(int i = 1; i <= txt - 1; i++) E.push_back(edges(GetXNodeID(bucx[i]), GetXNodeID(bucx[i + 1]), bucx[i + 1] - bucx[i]));
    for(int i = 1; i <= tyt - 1; i++) E.push_back(edges(GetYNodeID(bucy[i]), GetYNodeID(bucy[i + 1]), bucy[i + 1] - bucy[i]));
    for(int i = 1; i <= n; i++){
        E.push_back(edges(     i, GetXNodeID( Node[i].x ), 0     ));
        E.push_back(edges(     i, GetYNodeID( Node[i].y ), 0     ));
    }
    sort(E.begin(), E.end(), CMP);
    int all = n + txt + tyt;
    init(all);
    int ans = 0;
    for(int i = 0; i < E.size(); i++){
        edges &now = E[i];
       if(ask(now.u, now.v)) continue;
       ans += now.w; merge(now.u, now.v);
    }
    printf("%lld\n", ans);
    
    return 0;
}

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

using namespace std;

int main(){

    unsigned long L, R;
    cin >> L >> R;

    if(R-L >= 2018){
        cout << 0 << endl;
        return 0;
    }

    vector<unsigned long> v(R-L+1);

    unsigned long i, j;
    for(i=L, j=0; i<=R; i++, j++){
        v.at(j) = i % 2019;
        if(v.at(j) == 0){
            cout << 0 << endl;
            return 0;
        }
    }

    unsigned long mn = 2019;
    for(i=0; i<v.size()-1; i++){
        for(j=i+1; j<v.size(); j++){
            mn = min(mn, (v.at(i) * v.at(j)) % 2019);
        }
    }

    cout << mn << endl;

    return 0;
}



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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long  ll; typedef vector<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}

ll p[1100000][2][4];
ll fnc1(string sn){
	//string sn = to_string(n);
	int cn=sz(sn); memset(p, 0, sizeof p);
	p[0][0][0]=1; //p[桁数][未確定(0)・確定済(1)][0,9有無]=存在数;
	rep(i, cn) rep(k, 4) rep(d, 10) {
		int nk = k | (d==0) ;
		nk  |=  (d==9)<<1;
		if(d < sn[i] -'0') (p[i+1][1][nk] += p[i][0][k]) %=MD;
		else if(d== sn[i] -'0') (p[i+1][0][nk] += p[i][0][k]) %=MD;
		(p[i+1][1][nk] += p[i][1][k])%=MD;
	}
	return (p[cn][0][3]+p[cn][1][3])%MD;
}
int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	string s;
	rep(i, n) s+='9';
	
	cout<< fnc1(s) <<"\n";
	return 0;
}



Measured memory_bytes: 74000
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (n);i++)
using ll = long long;
const ll MOD=1000000007;
const double pi=acos(-1);





int main() 
{
  ll N,K; cin>>N>>K;
  vector<double> E(N);
  rep(i,N)
  {
    double p; cin>>p;
    E.at(i)=(p+1)/2;
  }
  /*
  rep(i,N)
  {
    if(i!=0) cout<<" ";
    cout<<E.at(i);
  }
  cout<<endl;
  */
  double sum=0;
  rep(i,K)
  {
    sum+=E.at(i);
  }
  
  double ans=sum;
  for(int i=K;i<=N-1;i++)
  {
    sum+=E.at(i);
    sum-=E.at(i-K);
    ans=max(sum,ans);
    //if(i!=K) {cout<<" ";}
    //cout<<sum;
  }
  cout<<fixed<<setprecision(15)<<ans<<endl;
  return 0;
}


Measured memory_bytes: 4848
a,b=map(int,input().split())
L=[[] for i in range(a)]
u=0
for i in range(b):
    u+=1
    c=list(map(int,input().split()))
    c.append(u)
    L[int(c[0])-1].append(c)
for i in L:
    i.sort(key=lambda x:x[1])
for i in L:
    e=0
    for j in i:
        e+=1
        j.append(e)
q=[]
for w in L:
   q.extend(w) 
q.sort(key=lambda x:x[2])
for r in range(b):
        print('0'*(6-len(str(q[r][0])))+str(q[r][0])+'0'*(6-len(str(q[r][3])))+str(q[r][3]))

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

int main() {
    string s,t; cin >> s >> t;
    vector<string> ans;
    int l = s.size()-t.size()+1;
    for(int i = 0; i < max(0, l); i ++) {
        string tmp = s;
        for(int j = 0; j < t.length(); j ++) {
            if(i+j>s.size()-1) break;
            if(tmp[i+j]=='?' || tmp[i+j]==t[j]) tmp[i+j] = t[j];
            else break;
            if(j==t.length()-1) {
                for(int k = 0; k < tmp.length(); k ++) {
                    if(tmp[k]=='?') tmp[k] = 'a';
                }
                ans.push_back(tmp);
            }
        }
    }
  
  
  
    sort(ans.begin(), ans.end());
    cout << (ans.size() > 0 ? ans[0] : "UNRESTORABLE") << endl;
    return 0;
}



Measured memory_bytes: 256
import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;
import std.complex;
import std.math;
import std.ascii;
import std.bigint;
import std.container;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

const real eps = 1e-10;

void main(){
	while(true) {
		auto h = readInt();
		if(h == 0) return;

		auto p = new int[][](5, 100);
		for(int i; i < 5; ++i) {
			for(int j; j < 100; ++j) {
				p[i][j] = 10000 + 100*i + j;
			}
		}
		for(int i; i < h; ++i) {
			auto r = readInts();
			for(int j; j < 5; ++j) {
				p[j][h-i-1] = r[j];
			}
		}
		int ans;
		bool f = true;
		while(f) {
			f = false;
			for(int i = h-1; i >= 0; --i) {
				int l;
				int u;
				while(u < 5 && l < 3) {
					if(p[l][i] == p[u][i]) {
						++u;
					} else {
						if(u-l >= 3) {
							ans += p[l][i] * (u-l);
							f = true;
							for(int j = l; j < u; ++j) {
								p[j][i..$-1] = p[j][i+1..$].dup[];
							}
						}
						l = u;
					}
				}
				if(u-l >= 3) {
					ans += p[l][i] * (u-l);
					f = true;
					for(int j = l; j < u; ++j) {
						p[j][i..$-1] = p[j][i+1..$].dup[];
					}
				}
			}
		}
		writeln(ans);
	}
}

Measured memory_bytes: 3196
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(){
  int N;
  cin >> N;
  vector<int> a(N), b(N);
  rep(i, N) cin >> a[i];
  rep(i, N) cin >> b[i];
  int p = 0;
  rep(i, N) {
    while(p < N && a[i] > b[i]) {
      int tmp = b[p]-a[p];
      if(tmp > 0) {
        if(a[i]-b[i] >= tmp/2) {
          b[i] += tmp/2;
          a[p] += tmp/2*2;
          p++;
        } else {
          int n = a[i]-b[i];
          b[i] += n;
          a[p] += 2*n;
        }
      } else {
        p++;
      }
    }
    if(p >= N)
      break;
  }
  rep(i, N) {
    if(a[i] > b[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N;
    cin >> N;
    cout << (N + 1) / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)
import Data.List (group, sortBy)

sortDesc::[Int]->[Int]
sortDesc = sortBy $ flip compare

getInts :: IO [Int]
getInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine

solve::[(Int,Int)]->Int
solve sn | length sn > 0 = if (snd $ head sn) >= 4 then (fst $ head sn) ^ 2 else product . map fst $ take 2 sn
         | otherwise = 0

main = do
  getLine
  an <- getInts
  let sn = map (\x -> (head x,length x)) . filter (\x -> length x > 1) . group $ sortDesc an
  print $ solve sn


Measured memory_bytes: 21500
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100000;

int main() {
	int k,x;cin>>k>>x;
	if(k*500>=x) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


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

int main() {
  int N,K,x,s=0;
  cin>>N>>K;
  for(int i=0;i<N;i++){
    cin>>x;
    if(x<K-x) s+=2*x;
    else s+=2*(K-x);
  }
  cout<<s<<endl;
}

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

int main() {
    int N, M, A, B;
    cin >> N >> M >> A >> B;
    vector<int> D(N);
    for (auto& i : D) cin >> i;

    vector<int> ded;
    for (auto i : D) {
        if (i >= A) ded.push_back(i);
        else break;
    }

    int count = 0;
    if (N - ded.size() < M) {
        reverse(ded.begin(), ded.end());
        for (auto i : ded) {
            if (i <= B) count++;
            else break;
        }
    }

    cout << ded.size() - count << endl;

    return 0;
}

Measured memory_bytes: 3156
#include <stdio.h>

int main(void)
{
    size_t n, k;
    scanf("%zu %zu", &n, &k);
    size_t u[100002] = { 0 };
    for (size_t i = 0; i < n; ++i) {
        size_t a, b;
        scanf("%zu %zu", &a, &b);
        u[a - 1] += b;
    }
    size_t t = 0;
    for (size_t i = 0; i < 100001; ++i) {
        t += u[i];
        if (t >= k) {
            printf("%zu\n", i + 1);
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 896
#ifdef DEBUG_IS_VALID
#define DEB 1 
#define _LIBCPP_DEBUG 0
#else
#define DEB 0
#define NDEBUG
#endif

#include <bits/stdc++.h>
using namespace std;

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#define fi first
#define se second
#pragma GCC optimize ("-O3")

using namespace std;

#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){cout << "{"; for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<Pl>;
using vvp = vector<vp>;

const int INF = 1<<29;
const long long LINF=1LL<<59;


void solve(long long N, std::string S){
  ll ans = 0;
  rep(i,N-2) ans += ll(S[i]=='A' && S[i+1]=='B' && S[i+2]=='C');
  cout << ans << endl;
}

int main(){
  std::cout << std::fixed << std::setprecision(15);
  long long N;
  scanf("%lld",&N);
  std::string S;
  std::cin >> S;
  solve(N, S);
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int n, x;
	long int dp[5000];
	long int max;
	int i, j;

	while (1) {
		scanf("%d", &n);
		if (n == 0) break;

		for (i = 0; i < n; i++){
			scanf("%d", &x);
			if (i == 0) {
				dp[i] = x;
			} else {
				if ((dp[i - 1] + x) > x) {
					dp[i] = dp[i - 1] + x;
				}
				else {
					dp[i] = x;
				}
			}
		}
		max = dp[0];
		for (j = 0; j < i; j++) {
			if (dp[j] > max) max = dp[j];
		}
		printf("%d\n", max);
	}

	return (0);
}

Measured memory_bytes: 632
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	ll x, k, d; cin>>x>>k>>d;
	x=abs(x);
	using lll=__int128_t;
	if(x>=(lll)k*d){
		cout<<x-k*d<<endl;
		return 0;
	}
	ll m=x/d;
	ll r=x%d;
	if((k-m)%2==0){
		cout<<r<<endl;
	}else{
		cout<<d-r<<endl;
	}
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<double,double> pdd;
#define SQ(i) ((i)*(i))
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) int(i.size())
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef tmd
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,deque<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif

const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int iNF = 0x3f3f3f3f;
const ll MAXN = 502;

int n, a[MAXN], k, sum;
int ans;

bool solve(int bs) {
    vector<int> po, na;
    int tot = 0, cnt = 0;
    REP (i, n) {
        int u = (a[i] / bs + 1) * bs - a[i];
        int d = a[i] - (a[i] / bs * bs);
        if (u < d) {
            po.eb(d - u);
            tot += u;
            cnt += u;
        } else {
            na.eb(u - d);
            tot -= d;
            cnt += d;
        }
    }
    sort(ALL(na));
    sort(ALL(po));

    if (tot > 0) {
        REP (i, tot / bs) {
            cnt += po[i];
        }
    } else {
        REP (i, (-tot) / bs) {
            cnt += na[i];
        }
    }

    cnt /= 2;

    debug(bs, cnt);
    return cnt <= k;
}
/********** Good Luck :) **********/
int main()
{
    IOS();
    cin >> n >> k;
    REP (i, n) {
        cin >> a[i];
        sum += a[i];
    }

    for (int i=1; i*i <= sum; i++) {
        if (sum % i == 0) {
            if (solve(i)) {
                ans = max(ans, i);
            }
            if (solve(sum / i)) {
                ans = max(ans, sum / i);
            }
        }
    }

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


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

using namespace std;

const int OO = 1e9;
const double EPS = 1e-9;

#define ndl cout << '\n'
#define sz(v) int(v.size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define present(a, x) (a.find(x) != a.end())
#ifdef LOCAL
#define db(...) ({cout << "> Line " << __LINE__  \
		<< ": "; _db(#__VA_ARGS__, __VA_ARGS__);})
#define RNG() rng()
#else
#define db(...) true
#define RNG() true
#endif

template<class T>
void _db(const char *dbStr, T e) {
	cout << dbStr << " = " << e << endl;
}
template<class T, class... L>
void _db(const char *dbStr, T e, L... r) {
  while(*dbStr != ',') cout << *dbStr++;
  cout << " = " << e << ','; _db(dbStr + 1, r...);
}
template<class S, class T>
ostream& operator<<(ostream& o, const map<S, T>& v) {
	o << "["; int i = 0;
	for (const pair<S, T>& pr : v) o << (!i++ ? "" : ", ") << "{"
	<< pr.fs << " : " << pr.sc << "}"; return o << "]";
}
template<template <class, class...> class S, class T, class... L>
ostream& operator<<(ostream& o, const S<T, L...>& v) {
	o << "["; int i = 0;
	for (const auto& e : v) o << (!i++ ? "" : ", ") << e;
	return o << "]";
}
template<class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& pr) {
	return o << "(" << pr.fs << ", " << pr.sc << ")";
}
ostream& operator<<(ostream& o, const string& s) {
	for (const char& c : s) o << c;
	return o;
}

template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = VV<V<T>>;
using ll = long long;
using pii = pair<int, int>;
using vi = V<int>;
using vii = V<pii>;
using vvi = VV<int>;
using mii = map<int, int>;
using umii = unordered_map<int, int>;
using si = set<int>;
using usi = unordered_set<int>;





int main() {
	#ifdef LOCAL
	auto stTime = clock();
//	freopen("in.txt", "r", stdin);
	mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
	#endif
	ios::sync_with_stdio(false);
	cout.precision(10);
	cin.tie(0);


	int N;
	si s;

	cin >> N;

	for (int i = 0; i < N; ++i) {
		int ai;
		cin >> ai;
		s.insert(ai);
	}

	cout << (sz(s) == N ? "YES\n" : "NO\n");



	#ifdef LOCAL
	cout << "\n\n\nExecution time: " <<
		(clock() - stTime) * 1e3 / CLOCKS_PER_SEC << " ms" << endl;
	#endif
	return 0;
}


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

typedef long long ll;
const ll mod = 1000000007;

ll modpow(ll a, ll b, ll p = 1e9+7){
    if(b == 0)  return 1;

    if(b % 2 == 0){
        ll d = modpow(a, b/2, p);
        return (d*d) % p;
    }else{
        return (a%p * modpow(a, b-1, p)) % p;
    }
}

ll nCm(ll n, ll m, ll p = mod){
    ll ret = 1;
    
    // nCm == nC(n-m)
    if(m > n/2) m = n-m;

    for(ll i = 1; i <= m; i++){
        ret *= n-(i-1);
        ret %= p;
        ret *= modpow(i, p-2, p);
        ret %= p;
    }
    
    return ret;
}

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

    map<int,int> fact;
    for(int i = 2; i*i <= m; i++){
        while(m%i == 0){
            fact[i]++;
            m /= i;
        }
    }
    if(m != 1)  fact[m]++;

    ll ans = 1;
    for(auto p : fact){
        ans *= nCm(n+p.second-1, p.second);
        ans %= mod;
    }

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


Measured memory_bytes: 256
#include<iostream>
using namespace std;
const int MAXN = 100 + 5;
char a[MAXN][MAXN];
bool print[MAXN][MAXN];
int n,m;
int main()
{
	cin>>n>>m;
	for(int i = 1 ; i <= n ; i ++)
		for(int j = 1 ; j <= m ; j++)
			cin>>a[i][j];
	for(int i = 1 ; i <= n ; i++)
	{
		bool k = false;
		for(int j = 1 ;j <= m ; j++)
			if(a[i][j] == '#')
				k = true;
		if(!k)
			for(int j = 1 ; j <= m ; j++)
				print[i][j] = true;
	}
	for(int i = 1 ; i <= m ; i++)
	{
		bool k = false;
		for(int j = 1 ;j <= n ; j++)
			if(a[j][i] == '#')
				k = true;
		if(!k)
			for(int j = 1 ; j <= n ; j++)
				print[j][i] = true;
	}	
	for(int i = 1 ; i <=n ; i ++)
	{
		bool out = false;
		for(int j = 1 ; j <= m ;j++)
		{
			
			if(!print[i][j])
				cout<<a[i][j] , out = true;
		}
		if(out)
			cout<<endl;
	}	
}

Measured memory_bytes: 256
x, n = map(int, input().split())
l = list(map(int, input().split()))

la = list(range(102))

for i in l:
    la.remove(i)

ans = la[0]
d = 200
for i in la:
    if d > abs(i-x):
        d = abs(i-x)
        ans = i

print(ans)

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

using namespace std;
#define INF (1<<28)
#define DEKAI 1000000007
#define lp(i,n) for(int i=0;i<n;i++)
#define int long long

string removerev(string s){
    int stat=0;
    stack<int> st;
    lp(i,s.size()){
      if(s[i]=='[') st.push(i);
      if(s[i]==']'){
        int bef=st.top();
        st.pop();
        reverse(s.begin()+bef+1,s.begin()+i);
      s.erase(s.begin()+i);
      s.erase(s.begin()+bef);
      //cout<<s<<endl;
      i-=2;
      }
    }
  return s;
}

string calcs(string s){
  int n=0;
  lp(i,s.size()){
    if(s[i]==']'||s[i]=='[') continue;
    else if(s[i]=='+') n++;
    else if(s[i]=='-') n--;
    else{
      if(s[i]=='?') s[i]='A';
      else{
        char c=s[i];
        c+=n%26;
        while(1){
        if(c<'A') c+=26;
        else if(c>'Z') c-=26;
        else break;
        }
        s[i]=c;
      }
      n=0;
    }
  }
  return s;
}

signed main(){
  while(1){
    string s;
    cin>>s;
    if(s==".") break;
    s=calcs(s);
    s=removerev(s);
    lp(i,s.size()){
      if('A'<=s[i]&&s[i]<='Z'){
        cout<<s[i];
      }
    }
    cout<<endl;
  }
  return 0;
}


Measured memory_bytes: 3172