akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ld long double
#define sz(a) (ll)(a).size()

typedef tree<pair<ll,ll> ,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//K-th smallest
//cout << k << "kth smallest: " << *A.find_by_order(k-1) << endl;
//NO OF ELEMENTS < X
//cout << "No of elements less than " << X << " are " << A.order_of_key(X) << endl;

const int MAXN = 25;

ll n, a[MAXN][MAXN], mod = 1e9 + 7;
ll dp[1ll<<MAXN];

ll countones(ll no)
{
	ll ans = 0;
	while(no)
	{
		if(no % 2) ans++;
		no /= 2;
	}
	return ans;
}

ll rec(ll mask)
{
	if(countones(mask) == n) return 1;
	if(dp[mask] != -1) return dp[mask];
	ll ind = countones(mask), ans = 0;
	for(int i=0;i<n;i++)
	{
		if(((1ll<<(ll)i) & mask) == 0 && a[ind][i] == 1)
		{
			ll temp = (mask | (1ll << (ll)i));
			ans = (ans + rec(temp)) % mod;
		}
	}
	return dp[mask] = ans;
}

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

    cin >> n;
    for(int i=0;i<n;i++) for(int j=0;j<n;j++) cin >> a[i][j];
    memset(dp, -1, sizeof(dp));
    cout << rec(0) << endl;		
    return 0;
}

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

int main() {
  char c;
  cin >> c;

  // ここにプログラムを追記
  if(c == 'a'||c == 'i'||c == 'u'||c == 'e'||c == 'o'){
    cout << "vowel" << endl;
  }else{
    cout << "consonant" << endl;
  }
  
}

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

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n;
		while((n=scan.nextInt())!=0){
			int max=0;
			int min=1000;
			int ans=0;
			int[] s=new int[n];
			for(int i=0;i<n;i++){
				s[i]=scan.nextInt();
				ans+=s[i];
				if(s[i]<min){
					min=s[i];
				}
				if(s[i]>max){
					max=s[i];
				}
			}
			ans-=(max+min);
			System.out.println(ans/(n-2));
		}
	}
}

Measured memory_bytes: 28904
#include<stdio.h>
#include<math.h>
int main()
{
	double x1,x2,y1,y2;
	scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
	double dis;
	dis=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
	dis=sqrt(dis);
	printf("%.8lf",dis);
	printf("\n");
	return 0;
} 


Measured memory_bytes: 2740
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>

#define isNum(a) (a >= '0' && a <= '9')
#define SP putchar(' ')
#define EL putchar('\n')
#define File(a) freopen(a ".in", "r", stdin), freopen(a ".out", "w", stdout)

template<class T>
void read(T&);
template<class T>
void write(const T&);

typedef long long ll;
typedef const long long & cll;
typedef const int & ci;
typedef std::pair<int, int> pii;
const int iinf = 2147483647;
const ll llinf = 9223372036854775807ll;
using std::min;
using std::max;
using std::abs;
using std::sort;
const int N = 205;
const long double PI = acos(-1);

class Vector {
public:
  long double x, y;
  Vector(long double x = 0, long double y = 0) : x(x), y(y) {}
  Vector operator + (const Vector i) {
    return Vector(x + i.x, y + i.y);
  }
  bool operator < (const Vector i) const {
    return atan2(y, x) < atan2(i.y, i.x);
  }
}v[N];

int main () {
  int n;
  read(n);
  for (int i = 1; i <= n; ++i) {
    std::cin >> v[i].x >> v[i].y;
  }
  sort(v + 1, v + n + 1);
  for (int i = 1; i <= n; ++i) {
    v[i + n] = v[i];
  }
  long double ans = 0;
  for (int i = 1; i <= n; ++i) {
    Vector now;
    for (int j = i; j <= (n << 1); ++j) {
      if (j - i >= n) {
        break;
      }
      now = now + v[j];
      ans = max(ans, now.x * now.x + now.y * now.y);
    }
  }
  std::cout.precision(20);
  std::cout << std::fixed << sqrt(ans) << std::endl;
  return 0;
}

template<class T>
inline void read(T &Re) {
  T k = 0;
  char ch = getchar();
  int flag = 1;
  while (!isNum(ch)) {
    if (ch == '-') {
      flag = -1;
    }
    ch = getchar();
  }
  while (isNum(ch)) {
    k = (k << 1) + (k << 3) + ch - '0';
    ch = getchar();
  }
  Re = flag * k;
}
template<class T>
inline void write(const T &Wr) {
  if (Wr < 0) {
    putchar('-');
    write(-Wr);
  } else {
    if (Wr < 10) {
      putchar(Wr + '0');
    } else {
      write(Wr / 10);
      putchar((Wr % 10) + '0');
    }
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define rg register
using namespace std;
const int MAXN=66e3+10;
const int Mod=998244353;
char Sa[MAXN],Sb[MAXN];
int Ls,Ys,Gs,G[MAXN],Invf[MAXN],Fac[MAXN]={1};
int Ans,F[MAXN],Help[MAXN],Di[MAXN];
inline int Read()
{   rg int a=0,c=1;   rg char b=getchar();
    while(b!='-'&&(b<'0'||b>'9'))b=getchar();
    if(b=='-')c=-1,b=getchar();
    while(b>='0'&&b<='9')a=a*10+b-48,b=getchar();
    return a*c;
}
inline int Fast(rg int Di,rg int Mi)
{   rg int Back=1;
    for(;Mi>=1;Mi>>=1,Di=1ll*Di*Di%Mod)
	if(Mi&1) Back=1ll*Back*Di%Mod;
    return Back;
}
namespace Poly
{   int Len,Ms,Invl,A[MAXN],B[MAXN],Rader[MAXN];
    inline void NTT(int *P,rg int opt)
    {   for(rg int i=0;i<Len;i++)
	    if(i<Rader[i]) swap(P[i],P[Rader[i]]);
	for(rg int i=1;i<Len;i<<=1)
	{   rg int Euler=Fast(3,(Mod-1)/(i<<1));
	    if(opt<0) Euler=Fast(Euler,Mod-2);
	    for(rg int Pos=i<<1,j=0;j<Len;j+=Pos)
	    {   rg int Wi=1;
		for(rg int k=0;k<i;k++,Wi=1ll*Wi*Euler%Mod)
		{   rg int X=P[j+k],Y=1ll*Wi*P[i+j+k]%Mod;
		    P[j+k]=(X+Y)%Mod,P[i+j+k]=(1ll*X-Y+Mod)%Mod;
		}
	    }
	}
	if(opt>0) return ;   Invl=Fast(Len,Mod-2);
	for(rg int i=0;i<Len;i++) P[i]=1ll*P[i]*Invl%Mod;
    }
    inline void Prepare(rg int Lx)
    {   Ms=-1;
	for(Len=1;Len<=Lx;Len<<=1) Ms++;
	for(rg int i=0;i<Len;i++) Rader[i]=(Rader[i>>1]>>1)|((i&1)<<Ms);
    }
    inline void Get_Mul(int *X,int *Y,int *T,rg int Lx)
    {   Prepare(Lx<<1);
	for(rg int i=0;i<Lx;i++) A[i]=X[i],B[i]=Y[i];
	for(rg int i=Lx;i<Len;i++) A[i]=B[i]=0;
	NTT(A,1),NTT(B,1);
	for(rg int i=0;i<Len;i++) A[i]=1ll*A[i]*B[i]%Mod;
	NTT(A,-1);
	for(rg int i=0;i<Len;i++) T[i]=A[i];
    }
    inline void Get_Fast(int *X,int *T,rg int Lx,rg int Mi)
    {   if(!Mi)
	{   for(rg int i=0;i<Lx;i++) T[i]=0;
	    return T[0]=1,(void)0;
	}
	Prepare(Lx<<1),Mi--;
	for(rg int i=0;i<Len;i++) Help[i]=Di[i]=X[i];
	for(;Mi>=1;Mi>>=1,Get_Mul(Di,Di,Di,Lx))
	    if(Mi&1) Get_Mul(Help,Di,Help,Lx);
	for(rg int i=0;i<Lx;i++) T[i]=Help[i];
    }
}using Poly::Get_Fast;using Poly::Get_Mul;using Poly::Prepare;
int main()
{   scanf("%s\n%s",Sa+1,Sb+1),Ls=strlen(Sa+1);
    for(rg int i=1;i<=Ls;i++)
	Ys+=Sa[i]=='1'&&Sb[i]!='1',Gs+=Sa[i]=='1'&&Sb[i]=='1';
    for(rg int i=1;i<=2*Ls;i++) Fac[i]=1ll*Fac[i-1]*i%Mod;
    Invf[2*Ls]=Fast(Fac[2*Ls],Mod-2);
    for(rg int i=2*Ls-1;i>=0;i--) Invf[i]=1ll*Invf[i+1]*(i+1)%Mod;
    for(rg int i=0;i<=Gs;i++) G[i]=Invf[i+1];
    F[0]=1,Get_Fast(G,G,Gs+1,Ys),Get_Mul(F,G,F,Gs+1);
    for(rg int i=0;i<=Gs;i++) Ans=(Ans+F[i])%Mod;
    printf("%lld\n",1ll*Ans*Fac[Ys]%Mod*Fac[Gs]%Mod*Fac[Ys+Gs]%Mod);
}


Measured memory_bytes: 1280
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<algorithm>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

using namespace std;

int main(){

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

  cout << 'A' << s[0] << 'C' <<endl;
  return 0;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
list_a = []
list_b = []
g = [[0 for i in range(N)] for j in range(N)]
for i in range(M):
    a,b = map(int,input().split())
    list_a.append(a-1)
    list_b.append(b-1)
    g[a-1][b-1] = 1
    g[b-1][a-1] = 1


def dfs(v):
    seen[v] = 1 #vを訪問済みにする
    ret = 1
    for v2 in range(N):
        if g[v][v2] == 1 and seen[v2] == 0:
           
            dfs(v2)
    if seen == [1] * N: #すべての頂点を訪問したらretを返す
        ret = 0

    return ret

ans = 0
for i in range(M):
    seen = [0] * N
    g[list_a[i]][list_b[i]] = 0
    g[list_b[i]][list_a[i]] = 0
    ans += dfs(0)
    g[list_a[i]][list_b[i]] = 1
    g[list_b[i]][list_a[i]] = 1
print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <limits.h>
using namespace std;

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

int n, q;
vector<ll> v;

ll query(int a, int b, int k, int l, int r) {
	if(r <= a || b <= l) return 0;
	if(a <= l && r <= b) return v[k];
	ll vl = query(a, b, k*2+1, l, (l+r)/2);
	ll vr = query(a, b, k*2+2, (l+r)/2, r);
	return vl + vr;
}

int main() {
	cin >> n >> q;
	int _n = n;
	n = 1;
	while(n < _n) n *= 2;
	v.resize(2*n-1, 0);
	rep(i, q) {
		int c, x, y;
		cin >> c >> x >> y;
		if(c == 0) {
			x += n-1 - 1;
			v[x] += y;
			while(x > 0) {
				x = (x-1) / 2;
				v[x] += y;
			}
		}
		else {
			cout << query(x-1, y+1-1, 0, 0, n) << endl;
		}
	}
	return 0;
}

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

vector<pair<int,int> > v;
int main( ) {
	int n;
	int i;
	cin>>n;
	for(i=1;i<=n;i++) {
		int a, b;
		cin>>a>>b;
		v.push_back({b, a});
	}
	sort(v.begin(), v.end());
	int day = 0;
	bool ans =1;
	for(auto p:v) {
		//cout<<p.first<<" , "<<p.second<<"\n";
		int deadline = p.first;
		int dayTaken = p.second;
		if(day  + dayTaken<= deadline) day+=dayTaken;
		else ans =0;
		//cout<<day<<", "<<ans<<"\n";
	}
	if(ans)
		cout<<"Yes\n";
	else
		cout<<"No\n";
	return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
 
int main(int argc, char const *argv[])
{
  string w;
  cin >> w;
  bool b = true;
 
  for(char ch = 'a'; ch <= 'z'; ch++)
  {
    int num = 0;
    for(int i = 0; i < w.length(); i++)
    {
      if(w[i] == ch)
        num++;
    }
    if(num % 2 != 0)
    {
      b = false;
      break;
    }
  }
  cout << (b ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 384
//#include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>

using namespace std;

long long powmod(long long a, long long n, long long amari) {
    long long res = 1;
    while(n > 0) {
        if(n & 1) res = res * a % amari;
        a = a * a % amari;
        n >>= 1;
    }
    return res;
}
 
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    long long N; 
 
    long long amari = 998244353;
 
    cin >> N;
 
    vector<long long> D(N);
 
    long long first = 0;
    cin >> first;
    if(first != 0) {
        cout << 0;
        return 0;
    }
 
    D[0]++;
 
    for(int i = 1; i < N; i++) {
        int x;
        cin >> x;
        D[x]++;
    }
 
    if(D[0] != 1) {
        cout << 0;
        return 0;
    }
 
    bool zero = false;
    long long count = 1;
    long long re_num = D[0];
 
    for(int i = 1; i < N; i++) {
        if(!zero) {
            if(D[i] == 0) {
                zero = true;
                continue;
            }
            //long long a = pow(re_num, D[i]);
            count *= powmod(re_num, D[i], amari);
            count %= amari;
            re_num = D[i];
        } else {
            if(D[i] != 0) {
                cout << 0;
                return 0;
            }
        }
    }
 
    cout << count;
}

Measured memory_bytes: 1024
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#include <cmath>

using namespace std;

void a_bichrome_cells(void) {
	int n, a;
	cin >> n >> a;

	n *= n;

	cout << (n - a) << endl;
}

int main()
{
    a_bichrome_cells();
    return 0;
}

Measured memory_bytes: 3532
sa = list(input())
sb = list(input())
sc = list(input())
turn = 0

while turn != 3:
    if turn == 0:
        if sa[0] == "a":
            turn = 0
        elif sa[0] == "b":
            turn = 1
        elif sa[0] == "c":
            turn = 2
        elif sa[0] == "x":
            turn = 3
            print("A")
            break
        sa.pop(0)
        if len(sa) == 0:
            sa.append("x")

    if turn == 1:
        if sb[0] == "a":
            turn = 0
        elif sb[0] == "b":
            turn = 1
        elif sb[0] == "c":
            turn = 2
        elif sb[0] == "x":
            turn = 3
            print("B")
            break
        sb.pop(0)
        if len(sb) == 0:
            sb.append("x")

    if turn == 2:
        if sc[0] == "a":
            turn = 0
        elif sc[0] == "b":
            turn = 1
        elif sc[0] == "c":
            turn = 2
        elif sc[0] == "x":
            turn = 3
            print("C")
            break
        sc.pop(0)
        if len(sc) == 0:
            sc.append("x")

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;



const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
//const ll MOD = 1e9 + 7;
const ll MOD = 998244353;




int main() {
	ll x, k, d;
	cin >> x >> k >> d;

	x = abs(x);

	if (x / d >= k) {
		cout << x - k * d << endl;
		return 0;
	}

	k -= x / d;
	x = x % d;

	if (k % 2 == 0) {
		cout << x << endl;
	}
	else {
		cout << d - x << endl;
	}
}


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

signed main(){
	int n;cin >>n;
	vector<int> t(n),a(n),s(n);
	for(int i=0;i<n;i++)cin >>t[i] >>a[i];
	int x=1,y=1,m;
	for(int i=0;i<n;i++){
		m=max((x-1)/t[i]+1,(y-1)/a[i]+1);
		x=m*t[i];y=m*a[i];
	}
	cout<<x+y<<endl;
}

Measured memory_bytes: 256
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
a = [aa-1 for aa in a]
check = [0 for i in range(n)]

count = 0
point = 0
check[0] = 1
path = [0]
for i in range(min(n, k)):
    if i == 0 or check[point] == 0:
        check[point] = i+1
        point = a[point]
        path.append(point)
    else:
        break


cycle_len = len(path)-check[point]
pre = check[point]
if pre > k:
    print(path[k])
else:
    k -= pre
    k %= cycle_len
    print(path[pre+k]+1)


Measured memory_bytes: 32412
#include <bits/stdc++.h>
using namespace std;
struct Edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<Edge>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define rrep(i,m, n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<int>(n,a)));
typedef long long ll;
const int INF = 2000000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
typedef unsigned int uint;
int main(){
    int h,w,n;
    std::cin >> h>>w;
    n=h*w;
    std::vector<char> a(h*w);
    rep(i,n)std::cin >> a[i];
    sort(all(a));
    std::vector<int> c;
    int co=1;
    rep(i,n-1){
      if(a[i+1]==a[i])co++;
      else{
        c.pb(co);
        co=1;
      }
    }
    c.pb(co);
    rep(i,c.size()){
      c[i]%=4;
    }
    co=0;
    int ch=0;
    
    rep(i,c.size()){
      co+=c[i]/2;
      ch+=c[i]%2;
    }
    int kyo=(h%2)*(w/2)+(w%2)*(h/2),kyo1=0;
    if(h%2==1&&w%2==1)kyo1++;
    if(co<=kyo&&ch<=kyo1)std::cout << "Yes" << std::endl;
    else std::cout << "No" << std::endl;
    
}

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

int main()
{
    char c;
    cin >> c;
    string v = "aeiou";
    int f = 0;
    for (int i = 0; i < v.size(); i++)
    {
        if (c == v.at(i))
        {
            f = 1;
            break;
        }
    }
    if (f == 1)
        cout << "vowel" << endl;
    else
        cout << "consonant" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
typedef long long ll;

int main()
{
  int a, b;
  while(cin >> a >> b){
    if (a==0&& b==0) {
      break;
    }
    string s = "";
    REP(i,b){
      s += "#";
    }
    REP(j,a){
      cout << s << endl;
    }
    cout << endl;
  }


  /*
  int i;
	cin >> i;
	*/
   
	//cout << i/j << " " <<  i%j << " ";
	//cout << fixed << setprecision(5) << i/(double)j << endl;
}




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

// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

// type
using ll = int_fast64_t;
using ull = uint_fast64_t;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
//using pair<T1, T2> = p12;

//container
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
#define ALL(v) v.begin(),v.end()

//repetition
#define REP(n) for(int i=0; i<(n); i++)
#define REPj(n) for(int j=0; j<(n); j++)
#define REPinit(i,a,n) for(int i=(a); i<(n); i++)
#define REPinitj(j,a,n) for(int j=(a); j<(n); j++)

//algorithm
//#define SORT(c) sort((c).begin(),(c).end())

//constant

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//Optimizer
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/* 
	add utility Algorithm
*/

int main(int argc, char const *argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int K, X;
    cin >> K >> X;
    
    if (500 * K >= X) cout << "Yes";
    else cout << "No";

    cout << endl;

    return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <stack>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <string.h>
#include <set>
using namespace std;



int main()
{
	string s;
	while (cin >> s) {
		printf("%c%d%c\n", s[0], s.size() - 2, s[s.size() - 1]);
	}
	return 0;
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 10;

ll d[MAXN], s[MAXN];

ll quick_pow(ll a, ll b, ll mod) {
	ll ans = 1;
	while(b) {
		if(b & 1) {
			ans = ans * a % mod;
		}
		a = a * a % mod;
		b >>= 1;
	}
	return ans;
}

int main() {
	ios::sync_with_stdio(false);
	ll n, num, mod = 998244353;
	while(cin >> n) {
		ll maxd = -1;
		memset(d, 0, sizeof(d));
		memset(s, 0, sizeof(s));
		for(int i = 0; i < n; i++) {
			cin >> num;
			s[i] = num;
			d[num]++;
			maxd = max(maxd, num);
		}
		ll ans;
		if(s[0] != 0 || d[0] != 1) {
			ans = 0;
		} else if(n == 1) {
			if(d[0] == 1 && s[0] == 0) {
				ans = 1;
			} else {
				ans = 0;
			}
		} else {
			ans = 1;
			for(int i = 0; i <= maxd; i++) {
				ans = ans * quick_pow(d[i], d[i + 1], mod) % mod;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1792
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
gosa = 1.0 / 10**10
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    n = I()
    s = set()
    for _ in range(n):
        a = I()
        if a in s:
            s.remove(a)
        else:
            s.add(a)

    return len(s)

print(main())





Measured memory_bytes: 14544
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
int n,siz[5050];
vector<int> G[5050];
ll dp[5050][5050],g[5050],t[5050];
void dfs(int x,int fa){
	siz[x]=1;
	dp[x][1]=1;
	for(int i=0;i<G[x].size();i++){
		int y=G[x][i];
		if(y==fa) continue;
		dfs(y,x);
		for(int j=0;j<=siz[x];j++)t[j]=dp[x][j],dp[x][j]=0;
		for(int j=0;j<=siz[x];j++)
			for(int k=0;k<=siz[y];k++) dp[x][j+k]=(dp[x][j+k]+t[j]*dp[y][k]%mod)%mod;
		siz[x]+=siz[y];
	}
	for(int i=0;i<=siz[x];i++) dp[x][0]=(dp[x][0]-dp[x][i]*g[i]%mod+mod)%mod;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		G[u].push_back(v);
		G[v].push_back(u);
	}
	g[0]=1;
	for(int i=2;i<=n;i+=2) g[i]=g[i-2]*(i-1ll)%mod;
	dfs(1,0);
	printf("%lld",mod-dp[1][0]);
	return 0;
}

Measured memory_bytes: 92768
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k,sum=1;
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		if(sum<k) sum+=sum;
		else sum+=k;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class Combination:
    def __init__(self, n, mod):

        g1 = [1, 1]
        g2 = [1, 1]
        inverse = [0, 1]
        for i in range(2, n + 1):
            g1.append((g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod//i)) % mod)
            g2.append((g2[-1] * inverse[-1]) % mod)
        self.MOD = mod
        self.N = n
        self.g1 = g1
        self.g2 = g2
        self.inverse = inverse

    def __call__(self, n, r):
        if (r < 0 or r > n):
            return 0
        r = min(r, n-r)
        return self.g1[n] * self.g2[r] * self.g2[n-r] % self.MOD


class Mod:
    def __init__(self, m):
        self.m = m

    def add(self, a, b):
        return (a + b) % self.m

    def sub(self, a, b):
        return (a - b) % self.m

    def mul(self, a, b):
        return ((a % self.m) * (b % self.m)) % self.m

    def div(self, a, b):
        return self.mul(a, pow(b, self.m-2, self.m))

    def pow(self, a, b):
        return pow(a, b, self.m)


def slv(N, K):
    MOD = 10**9 + 7
    C = Combination(2000, MOD)
    M = Mod(MOD)
    R = N-K
    for i in range(1, K+1):
        print(M.mul(C(R+1, i), C(K-1, i-1)))


def main():
    N, K = read_int_n()
    slv(N, K)

    # for i in range(1, 2001):
    #     for k in range(1, i):
    #         slv(i, k)


if __name__ == '__main__':
    main()


Measured memory_bytes: 6428
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<vector<pair<int, int> > > vvp;
typedef vector<pair<int,int> > vp;
typedef vector<vector<int> > vvi;
typedef vector<int> vi;
typedef vector<vector<bool> > vvb;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef pair<string, int> psi;
typedef pair<int, int> pii;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define yn(f) (f?"yes":"no")
#define YN(f) (f?"YES":"NO")
#define Yn(f) (f?"Yes":"No")
#define mod 1000000007
#define intmax 2147483647
#define intmin -2147483648
#define longmax 9223372036854775807
#define longmin -9223372036854775808
#define black 0
#define gray 127
#define white 255
class disjointset {
public:
	vi p, rank;
	disjointset(int size) {
		p.resize(size, 0);
		rank.resize(size,0);
		for (int i = 0; i < size; i++)makeSet(i);
	}
	void makeSet(int x) {
		p[x] = x;
		rank[x] = 0;
	}
	bool same(int x,int y) {
		return findSet(x) == findSet(y);
	}
	void unite(int x,int y) {
		link(findSet(x),findSet(y));
	}
	void link(int x,int y) {
		if (rank[x]<rank[y]) {
			p[x] = y;
		}
		else {
			p[y] = x;
			if(rank[x]==rank[y]){
				rank[x]++;
			}
		}
	}
	int findSet(int x) {
		if (x!=p[x]) {
			p[x]=findSet(p[x]);
		}
		return p[x];
	}
};
int main() {
	int n, q;
	cin >> n >> q;
	disjointset ds = disjointset(n);
	for (int i = 0; i < q; i++)
	{
		int q,x,y;
		cin >> q>>x>>y;
		if (q) {
			cout<<(int)ds.same(x,y)<<endl;
		}
		else {
			ds.unite(x,y);
		}
	}

}



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

using namespace std;

int main(){
    const int INF=1000000;
    int n;
    cin >> n;
    vector<int> p(n);
    int m=INF;
    int cnt=0;
    for(int i=0;i<n;i++){
        cin >> p[i];
        m=min(p[i],m);
        if(m>=p[i]){
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1024
# B - Buffet
n = (int)(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

total = 0
before = -1
for i in a:
    if before + 1 == i: total = b[i - 1] + c[i - 2] + total
    else: total = b[i - 1] + total
    before = i

print(total)

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll N, M, X;
    cin >> N >> M >> X;
    vector<ll> C(N);
    vector<ll> A[N];
    REP(i, N)
    {
        cin >> C[i];
        REP(j, M)
        {
            ll a;
            cin >> a;
            A[i].push_back(a);
        }
    }

    ll ans = LONG_MAX;
    bool isEble = false;
    for (ll i = 1; i < (1 << N); ++i)
    {
        vector<ll> master(M, 0);
        ll cost = 0;
        REP(j, N)
        {
            ll num = i;
            if (((num >> j) & 1) == 1)
            {
                cost += C[j];
                REP(k, M)
                {
                    master[k] += A[j][k];
                }
            }
        }
        bool flag = true;
        REP(j, M)
        {
            if (master[j] < X) 
            {
                flag = false;
                break;
            }
        }
        if (flag)
        {
            isEble = true;
            ans = min(ans, cost);
        }
    }
    if (!isEble)
    {
        ans = -1;
    }

    cout << ans << endl;
}


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

#define sswap(x, y) { x+=y; y=x-y; x-=y; }
#define LSOne(S) ((S) & (-S))

#define EPS 1e-6
#define MOD 1000000007

#define fi first
#define se second
#define pb push_back
#define ende '\n'

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mset(x, y) memset(&x, (y), sizeof(x))

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

bool almeidaraulsort(int i, int j) {
	return (i%10 != 0) && (i % 10 < j % 10);
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
	vi A;
	int e;
	while (cin >> e) A.pb(e);
	sort(all(A), almeidaraulsort);
	int ans = A[0];
	for (int i = 1; i < A.size(); i++)
		ans += A[i] + (A[i] % 10 == 0 ? 0 : 10-(A[i]%10));
	cout << ans << ende;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<ctime>
#include<iostream>
using namespace std;

long long MaxN = 1e18;
long long x,y,sum = 0;

int main()
{
	scanf("%lld%lld",&x,&y);
	sum = x;
	while(sum < MaxN)
	{
		if(x % y == 0)
		{
			printf("-1\n");
			break;
		}
		sum += x;
		if(sum % y != 0)
		{
			printf("%lld\n",sum);
			break;
		}
		else if(sum >= MaxN)
		{
			printf("-1\n");
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int X = sc.nextInt();
		int money = 100000000;
		int ans = -1;
		int[] C = new int[N];
		int[][] A = new int[N][M];
		for(int i = 0;i < N;i++){
			C[i] = sc.nextInt();
			for(int j = 0;j < M;j++){
				A[i][j] = sc.nextInt();
			}
		}
		for(int i = 0;i < (1 << N);i++){
			int valueSum = 0;
			boolean flg = true;
			int[] buf = new int[M];
			for(int j = 0;j < N;j++){
				if((1 & (i >> j)) == 1){
					valueSum += C[j];
					for(int k = 0;k < M;k++){
						buf[k] += A[j][k];
					}
				}
			}
			for(int j = 0;j < M;j++){
				if(buf[j] < X){
					flg = false;
				}
			}
			if(flg){
				money = Math.min(money,valueSum);
			}
		}
		if(money < 100000000){
			ans = money;
		}
		System.out.println(ans);
	}
}

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

int main() {
    int a, b, k;
    cin >> a >> b >> k;
    int c = __gcd(a,b);
    int cnt = 0;
    for(int i = c; i >= 1; i--){
        if(c%i == 0) cnt++;
        if(cnt == k){
            cout << i << endl;
            break;
        }
    }
}


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

int solve(int a, int b) {
        if (a > 9 || b > 9) {
                return -1;
        }
        else {
                return a * b;
        }
}

int main() {
	int a,b;
	cin >> a >> b;
	cout << solve(a,b);
	return 0;
}


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

int main(){
  vector< vector<int> > A(3,vector<int> (3));
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin >> A.at(i).at(j);
    }
  }
  int N;
  cin >> N;
  set<int> s;
  for(int i=0;i<N;i++){
    int b;
    cin >> b;
    s.insert(b);
  }
  for(int i=0;i<3;i++){
    if(s.count(A.at(i).at(0))){
      if(s.count(A.at(i).at(1))){
        if(s.count(A.at(i).at(2))){
          cout << "Yes" << endl;
          return 0;
        }
      }
    }
  }
  for(int i=0;i<3;i++){
    if(s.count(A.at(0).at(i))){
      if(s.count(A.at(1).at(i))){
        if(s.count(A.at(2).at(i))){
          cout << "Yes" << endl;
          return 0;
        }
      }
    }
  }
  if(s.count(A.at(0).at(0))){
    if(s.count(A.at(1).at(1))){
      if(s.count(A.at(2).at(2))){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  if(s.count(A.at(0).at(2))){
    if(s.count(A.at(1).at(1))){
      if(s.count(A.at(2).at(0))){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
from functools import cmp_to_key
n, w = [int(e) for e in input().split()]
d = [[int(e) for e in input().split()] for i in range(n)]
d.sort(key = cmp_to_key(lambda x, y: x[1] / x[0] - y[1] / y[0]))
t = {}
t[w] = 0
for i in range(n):
  keys = list(sorted(t.keys())) # sort しないと品物iを複数回ナップサックに詰める可能性がある
  tw, tv = d[i]
  updates = []
  for j in keys:
    nw = j - tw
    if nw < 0:
      continue
    nv = t[j] + tv
    if nw not in t or nv > t[nw]:
      updates.append([nw, nv])
  for u in updates:
    t[u[0]] = u[1]
print(max(t.values()))


Measured memory_bytes: 135680
N = int(input())
S1 = input()
S2 = input()

skip = False
double = False
for i in range(N):
    if skip:
        skip = False
        continue
    if i == 0:
        if S1[i] == S2[i]:
            ans = 3
        else:
            ans = 6
            skip = True
            double = True
    else:
        if S1[i] == S2[i]:
            if double:
                ans *= 1
            else:
                ans *= 2
            double = False            
        else:
            if double:
                ans *= 3
            else:
                ans *= 2
            skip = True
            double = True


ans = ans % 1000000007
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}
void OUT(bool b){cout<<(b?"YES":"NO")<<endl;}
void Out(bool b){cout<<(b?"Yes":"No")<<endl;}
void out(bool b){cout<<(b?"yes":"no")<<endl;}
template<class T>
void puta(T&&t){cout<<t<<endl;}
template<class H,class...T>
void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}

int popcnt(int x){return __builtin_popcount(x);}
int popcnt(ll x){return __builtin_popcountll(x);}
int bsr(int x){return 31 - __builtin_clz(x);}
int bsr(ll x){return 63 - __builtin_clzll(x);}
int bsf(int x){return __builtin_ctz(x);}
int bsf(ll x){return __builtin_ctzll(x);}
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
/*他のライブラリを入れる場所*/

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s,t;
	cin>>s>>t;
	int n=s.size(),m=t.size();
	vvi dp(n+1,vi(m+1,0));
	vvi bt(n+1,vi(m+1,-1));
	rep(i,n){
		dp[i+1]=dp[i];
		rep(j,m){
			if(s[i]==t[j]){
				chmax(dp[i+1][j+1],dp[i][j]+1);
			}else{
				chmax(dp[i+1][j+1],dp[i+1][j]);
				chmax(dp[i+1][j+1],dp[i][j+1]);
			}
		}
		//cout<<dp[i]<<endl;
	}
	//cout<<dp[n]<<endl;
	string ans="";
	while(n>0 and m>0){
		if(s[n-1]==t[m-1]){
			//puta(n,m,s[n-1]);
			ans=s[n-1]+ans;
			n--; m--;
		}else{
			if(dp[n][m]==dp[n-1][m]){
				n--;
			}else{
				m--;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 70912
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::cmp::Ordering;
use std::f64::consts::PI;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    loop {
        let a: i32 = sc.read();
        let op: String = sc.read();
        let b: i32 = sc.read();
        if op == "?" { break }
        let ans = match &*op {
            "+" => a + b,
            "-" => a - b,
            "*" => a * b,
            "/" => a / b,
            _ => 0,
        };
        println!("{}", ans);
    }
}



Measured memory_bytes: 5032
#include<bits/stdc++.h>
using namespace std;
long long md=1e9+7;
long long f(int a){
	long long rez=1;
	for(int i = 1 ; i <= a ; i ++)
		rez=rez*i%md;
	return rez;
}
long long pw(int a,int b){
	if(b==0)return 1;
	if(b==1)return a;
	long long g=pw(a,b/2);
	g=g*g%md;
	if(b%2)return g*a%md;
	return g;
}
long long cmb(int c,int k){
	long long fu=f(c);
	long long fd=pw(f(k)*f(c-k)%md,md-2);
	return fu*fd%md;
}
int main(){
	int x,y;
	cin>>x>>y;
	int a=(2*y-x);
	int b=(2*x-y);
	if(a%3||b%3||(x+y)%3||a<0||b<0){
		cout<<0;
		return 0;
	}
	a/=3;b/=3;
	// cout<<a<<" "<<b<<endl;
	cout<<cmb(a+b,a);
}

Measured memory_bytes: 768
#include<iostream>

using namespace std;

int main() {
	int n[999], a, b;
	int i;
	
	n[0] = 1;
	for (i = 1; i < 999; i++)
		n[i] = n[i-1] + i + 1;

	cin >> a >> b;
	i = b - a;

	cout << n[i - 1] - b;

	return 0;
}

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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	    String S = sc.next();
	    sc.close();
	    
	    int c_0=0;
	    int c_1=0;
        for(int i = 0; i < S.length(); i++){
        	if (S.charAt(i)=='0')
        		c_0++;
        	else 
        		c_1++;
        }
        System.out.println(2*Math.min(c_0, c_1));
      
       

	}

}


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

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int count = 0;
		int[] a = new int[n+1];
		for(int i = 0; i < n; i++) {
			a[sc.nextInt()]++;
		}
		Arrays.sort(a);
		for(int i = n; i > n-k ; i--) {
			count += a[i];
		}
		System.out.println(n-count);
		sc.close();
	}

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 84680
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
using namespace std;
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; }
using Graph = vector<vector<int> >;
using P = pair<int, int>; 
// MOD
const int MOD = 1000000007;
using ll = long long;
long long INF = 1<<30;
long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
//int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }

int H, W;
int field[100][100];

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double PI=3.14159265358979323846;
bool seen[100][100];

bool memo[110];
bool flag;
Graph G;

int dist[100][100];

bool compare_f(pair<int, int> &x, pair<int, int> &y) {
  return x.second< y.second;
}

struct Unionfind{
    vector<int> par;

    Unionfind(int n) : par(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)];
    }
};
int ss[50];
int main() {
    int n, m, x; cin >> n>> m >> x;
    int a[n][m];
    int c[n];
    
    for(int i=0; i<n; i++){
        cin >> c[i];
        for(int j=0; j<m; j++) cin >> a[i][j];
    }
    int ans = INF;
    for(int bit=0; bit<(1<<n); bit++){
        int sum = 0;
        for(int j=0; j<m; j++) ss[j] = 0;
        bool flag = true;
        for(int i=0; i<n; i++){
            if(bit & 1<<i){
                sum += c[i];
                for(int j=0; j<m; j++){
                    ss[j] += a[i][j];
                    //cout << ss[j] << endl;
                }
            }
        }
        for(int j=0; j<m; j++){
            if(ss[j] < x) flag =false; 
        }
        if(flag == true) ans = min(ans, sum);
    }
    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;
}

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

typedef pair <int, int> pii;

const int MAXN = 2e5 + 5;
const int offset = 1 << 18;
const int INF = 0x3f3f3f3f;

int N, Q;
vector <int> op[MAXN];
int bit[MAXN];
int dp[MAXN];
int suff[MAXN];
int t[2 * offset];

void load() {
	scanf("%d", &N);
	for (int i = 1; i <= N; i++)
		scanf("%d", bit + i);
	scanf("%d", &Q);
	while (Q--) {
		int l, r;
		scanf("%d%d", &l, &r);
		op[l].push_back(r);
	}
}

void update(int x, int lo, int hi, int from, int to, int val) {
	if (lo >= to || hi <= from)
		return;
	if (lo >= from && hi <= to) {
		t[x] = min(t[x], val);
		return;
	}
	int mid = (lo + hi) / 2;
	update(2 * x, lo, mid, from, to, val);
	update(2 * x + 1, mid, hi, from, to, val);
}

int query(int x) {
	int res = INF;
	for (x += offset; x; x /= 2)
		res = min(res, t[x]);
	return res;
}

int solve() {
	memset(t, INF, sizeof t);
	
	for (int i = N; i; i--)
		suff[i] = suff[i + 1] + !bit[i];
		
	for (int i = N; i; i--) {
		dp[i] = dp[i + 1] + bit[i];
		vector <pii> tmp;
		for (auto it : op[i]) {
			int val = dp[it + 1] - suff[it + 1];
			val = min(val, query(it));
			tmp.push_back({it, val});
			dp[i] = min(dp[i], val + suff[i]);
		}
		for (auto it : tmp)
			update(1, 0, offset, i, it.first, it.second);
	}
	
	return dp[1];
}

int main() {
	load();
	printf("%d\n", solve());
	return 0;
}

Measured memory_bytes: 13684
/*
 * Shubham Jain
 */
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define mem(x,val) memset((x),(val),sizeof(x));
#define rite(x) freopen(x,"w",stdout);
#define read(x) freopen(x,"r",stdin);
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define sqr(x) ((x)*(x))
#define clr clear()
#define ll long long int
#define inf (1<<30)
#define ins insert
#define endl '\n'
#define xx first
#define yy second
#define eps 1e-9
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define INF 1000000000000000000
#define mx 0
inline ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
inline ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }


int main() {
    FAST_IO
    string s;
    cin>>s;
    ll ans=s.length();
    for(ll i=0;i<s.length()-1;i++)
    {
	if(s[i]!=s[i+1])
        ans=min(ans,max(i+1,(int)s.length()-i-1));
    }

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


Measured memory_bytes: 512
#include <iostream> // cout, endl, cin
#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
#include <math.h>
#include <cstdlib>
#include <iomanip>
#define rep(i,x) for(ll i=0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 10010010010;
typedef pair<ll, ll> P;
using graph = vector<vector<ll>>;
const ll mod = 1000000007;
ll gcd(ll a, ll b) {//a>b
    if (a < b)swap(a, b);
    if (a % b == 0) return b;
    else return gcd(b, a % b);
}/*フィボナッチテンプレ
ll memo[50];
ll fibo(ll n) {
    if (memo[n] != 0)return memo[n];
    if (n <= 1)return memo[n] = n;
    else return memo[n] = fibo(n - 1) + fibo(n - 2);
}
*/

int main() {
	ll N;
  cin >> N;
  vector<ll> slime(N);
  rep(i,N)cin >> slime[i];
  ll ans = 0;
  rep(i,N - 1){
    if(slime[i] == slime[i + 1]){
      ans++;
      slime[i + 1] = -1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::collections::HashMap;
use std::collections::HashSet;

fn main() {
    input! {
        n: usize,
        cs: [chars; n],
    }
    let mut hs = HashSet::new();
    for c in &cs {
        hs.insert(c);
        //    println!("{}", c);
    }
    //println!("{}", hs.len());
    let res = if hs.len() == 3 { "Three" } else { "Four" };

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


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
 
int main() {
  int n,k,ans=0;
  cin>>n>>k;
  int p[n];
  for(int i=0;i<n;i++){
    cin>>p[i];
  }
  sort(p,p+SIZE_OF_ARRAY(p));
  for(int i=0;i<k;i++)
    ans+=p[i];
  cout<<ans<<endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <cstdint>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

int main(void)
{
    int64_t A, B;
    std::cin >> A >> B;

    std::vector<int64_t> ans(4, 0);

    ans.at(A) = 1;
    ans.at(B) = 1;

    for (int64_t i = 1; i <= 3; ++i) {
        if (ans.at(i) == 1) continue;
        std::cout << i << std::endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define sort(v,n) sort(v,v+n);
#define vsort(v) sort(v.begin(),v.end());
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
typedef pair<int,int> p;
typedef pair<ll,ll> lp;
bool is_uruu(int y) {
        return y % 4 == 0 && (y % 100 != 0 || y % 400 == 0);
}
const ll MOD=1e9+7;
//---------------------------------------------------------------------------//

int main(){
        int s,k,sum=0;
        cin>>k;
        cin>>s;
        for(int i=0; i<=k; i++) {
                for(int j=0; i+j<=s && j<=k; j++) {
                        if((s-i-j)<=k) sum++;
                }
        }
        cout<<sum<<endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

N = int(input())*2
s_L = input()
L = []
for i in s_L.split():
    L.append(int(i))

L.sort()

ans = 0
for i in range(0,N,2):
    ans += L[i]

print(ans)


Measured memory_bytes: 3572