akhauriyash/Code-Regression huggingface dataset:
def main():
    n, m = map(int, input().split())
    g = [[] for _ in range(n)]
    for _ in range(m):
        u, v = map(lambda x: int(x) - 1, input().split())
        g[u].append(v)
        g[v].append(u)

    vis = [False] * n
    ans = dfs(0, g, vis, 0)

    print(ans)


def dfs(v, g, vis, count):
    vis[v] = True

    if all(vis):
        return count + 1

    for i in g[v]:
        if vis[i]:
            continue
        count = dfs(i, g, vis, count)
        vis[i] = False

    return count


if __name__ == '__main__':
    main()


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

int main(){
    int N;
    cin >> N;
    int sum = 0;
    double ave = 0;
    double mini = 100;
    double aa = 0;
    int ans = 0;
    vector<int> a(N);
    for(int i = 0;i < N;i++){
        cin >> a.at(i);
        sum += a.at(i);
    }
    ave =  (double)sum/(double)N;
    /*cout << ave << endl;*/

    for(int i = 0;i < N;i++){
        aa = abs(ave - a.at(i));
        if(mini > aa){
            mini = aa;
            
            ans = i;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define repr(i,a,n) for(ll i = n-1;i >= a;i--)
#define LINF (ll)1e17
#define INF (int)1e9
#define MOD (ll)1e9+7
#define sMOD 1e5
#define fs first
#define sc second

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
	
}

void YNout(bool check){
	if(check)cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return;
}

void Yayout(bool check){
	if(check) cout << "Yay!" << endl;
	else cout << ":(" << endl;
	
	return;
}

/*
template <typename T>
void vecout(vector<T>& vecout_vec){
	
	rep(i,0,vecout_vec.size()){
		cout << vecout_vec.at(i) << endl;
	}
	
	return ;
}

template <typename T>
void vecin(vector<T>& vecin_vec, ll n){
	
	ll temp ;
	
	rep(i,0,n){
		cin >> temp;
		vecin_vec.push_back(temp);
		
	}
}

template <typename T>
void in(T& literal_in, T& literal_in2, ...){
	cin >> literal_in;
	in(literal_in2, ...);
	
	return;
}

template <typename T>
void in(T& literal_in){
	
	cin >> literal_in;
	
	return;
}

template <typename T>
void out(T& literal_out, T& literal_out2, ...){
	cout << literal_out << endl;
	out(literal_out2, ...);
	
	return;
}

template <typename T>
void out(T& literal_out){
	
	cout << literal_out << endl;
	
	return;
}
*/


signed main(){
	ll n;
	cin >> n;
	ll A[n] = {};
	ll B[n] = {};
	
	rep(i,0,n){
		cin >> A[i];
		B[i] = A[i];
	}
	
	sort(B,B+n,greater<ll>());
	
	rep(i,0,n){
		if(B[0] == A[i])cout << B[1] << endl;
		else cout << B[0] << endl;
	}
	return 0;
}


Measured memory_bytes: 4736
#include<stdio.h>

int main(void){
	int m,f,r;
	int n;
	while(1){
	scanf("%d %d %d",&m,&f,&r);
	n=m+f;
		if(n+r==-3){
			break;
		}
	if(n<30||m==-1||f==-1){
		printf("F\n");
	}else if(n>=80){
		printf("A\n");
	}else if(n<80&&n>=65){
		printf("B\n");
	}else if(n<65&&n>=50||r>=50){
		printf("C\n");
	}else if(n<50&&n>=30){
		printf("D\n");
	}
	}
	return 0;
}

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



int main() {
  int n, m, x;
    cin >> n >> m >> x;
    vector<vector<int>> a(n, vector<int>(m));
    vector<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 = 12345678;
    int all = 1<<n;
    for(int bit = 0; bit < all; bit++){
        vector<int> level(m);
        int cost = 0;
        for(int i = 0; i < n; i++){
            if((bit>>i)&1){
                cost += c[i];
                for(int j = 0; j < m; j++){
                    level[j] += a[i][j];
                }
            }
        }
        bool flag = true;
        for(int j = 0; j < m; j++){
            if(level[j] < x) flag = false;
        }
        if(flag) ans = min(ans,cost);
    }
    if(ans == 12345678) cout << -1 << endl;
    else cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
const string ara = "IVXLCDM\0";
const int integer[8] = {1,5,10,50,100,500,1000}; 
int Input(int num[],string in);
void Output(int p,int num[]);
 
int main(void){
  string in;
  int num[1000];

  while( cin >> in ){
    for(int i = 0 ; i < 1000; i++)num[i] = 0;
    int p = Input(num,in);
    Output(p,num);
  }
  return 0;
}

int Input(int num[],string in){

  int p = 0;
  for(int i = 0 ; i < (int)in.size(); i++){
    for(int j = 0 ; ara[j] != '\0'  ; j++ ){
      if(in[i] == ara[j]){
	num[p++] = integer[j];
	break;
      }
    }
  }
  return p;
}

void Output(int p,int num[]){
  int ans  = 0;
  for(int i = 0 ;i < p ; i++){

    if(num[i] < num[i+1]){
      ans += (num[i+1] - num[i]);
      i++;
    } else ans+=num[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
void init_ios() {ios_base::sync_with_stdio(false); cin.tie(nullptr);}

typedef struct SingleLinkedList {
	SingleLinkedList *next;
	int x;
	SingleLinkedList() {}
	SingleLinkedList(SingleLinkedList* next, const int x) : next(next), x(x) {}
} SLL;

class UnionFind {
	vector<int> par, rank, num;
	vector<SLL*> first, last;
public:
	UnionFind(const int n) {
		for (int i = 0; i < n; ++i) {
			par.push_back(i);
			SLL *tmp = new SLL(nullptr, i);
			first.push_back(tmp);
			last.push_back(tmp);
		}
		rank.assign(n, 0);
		num.assign(n, 1);
	}
	~UnionFind() {
		for (size_t i = 0; i < first.size(); ++i) {
			delete first[i];
		}
	}
	int root(const int x) {
		return par[x] == x ? x : par[x] = root(par[x]);
	}
	int size(const int x) {
		return num[root(x)];
	}
	SLL* ptr(const int x) {
		return first[root(x)];
	}
	void unite(int x, int y) {
		if ((x = root(x)) == (y = root(y))) {
			return;
		}
		if (rank[x] < rank[y]) {
			merge(y, x);
		} else {
			merge(x, y);
			if (rank[x] == rank[y]) {
				++rank[x];
			}
		}
	}
private:
	/* x <- y */
	void merge(const int x, const int y) {
		par[y] = x;
		last[x]->next = first[y];
		last[x] = last[y];
		num[x] += num[y];
	}
};

int N, M;
vector<int> a;

int main() {
	cin >> N >> M;

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

	UnionFind uf(N);
	for (int i = 0; i < M; ++i) {
		int x, y;
		cin >> x >> y;
		uf.unite(x, y);
	}

	vector<bool> used(N);
	vector<vector<pair<int, int>>> vs;
	for (int i = 0; i < N; ++i) {
		if (used[i]) continue;
		vector<pair<int, int>> v;
		auto p = uf.ptr(i);
		while (p) {
			int x = p->x;
			used[x] = 1;
			v.emplace_back(a[x], x);
			p = p->next;
		}
		vs.push_back(v);
	}

	if (vs.size() == 1) {
		cout << 0 << endl;
		return 0;
	}
	if (N < (vs.size() - 1) * 2) {
		cout << "Impossible" << endl;
		return 0;
	}

	vector<bool> used2(N);
	long long res = 0;
	for (auto& v : vs) {
		auto p = *min_element(v.begin(), v.end());
		res += p.first;
		// cout << "id:" << p.second << endl;
		used2[p.second] = 1;
	}

	vector<int> a2;
	for (int i = 0; i < N; ++i) {
		if (used2[i]) continue;
		a2.push_back(a[i]);
	}

	sort(a2.begin(), a2.end());
	for (int i = 0; i < (vs.size() - 1) * 2 - vs.size(); ++i) {
		res += a2[i];
		// cout << "id:" << i << endl;
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 13152
import java.util.*;

public class Main {
    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long sum = 0;
        for(int i = 1 ; i <= n ; i++){
            if((i % 3) != 0 && (i % 5) != 0){
                sum += i;
            }
        }
        System.out.println(sum);
    }
}


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

# ---------------------------------------
# nCr(n, r, m) テンプレ
mod = 998244353

fac = [1,1] # 階乗 n!
inv = [0,1] # 逆元 1/n
finv = [1,1] # 逆元の階乗 (n^-1)! = (1/n)!

for i in range(2, n+1):
    fac.append( (fac[-1] * i ) % mod )
    inv.append( (-inv[mod%i] * (mod//i)) % mod )
    finv.append( (finv[-1] * inv[-1]) % mod )

def nCr(n, r, m):
    if (n<0 or r<0 or n<r): return 0
    r = min(r, n-r)
    return fac[n] * finv[n-r] * finv[r] % m
# ---------------------------------------

ans = 0
colors = m
for p in range(n-1, -1, -1):
    if p <= k: ans += colors * nCr(n-1, p, mod) % mod
    colors = colors * (m - 1) % mod
ans %= mod
print(ans)


Measured memory_bytes: 32824
#include <iostream>
#include <cstring>

using namespace std;

const int MOD = 1000000007;

int main(){
	int N, M;
	static long long dp[301][301][301];
	while(cin >> N >> M){
		memset(dp, 0, sizeof(dp));
		dp[0][1][0] = 1;
		for(int day=0;day<M;day++){
			for(int ok=0;ok<N;ok++){
				for(int ng=0;ng<N;ng++){
					if(dp[day][ok][ng] == 0) continue;
					dp[day+1][ok][ng] += dp[day][ok][ng] * ng;
					dp[day+1][ok][ng] %= MOD;
					dp[day+1][ok+ng][0] += dp[day][ok][ng] * ok;
					dp[day+1][ok+ng][0] %= MOD;
					dp[day+1][ok][ng+1] += dp[day][ok][ng] * (N - ok - ng);
					dp[day+1][ok][ng+1] %= MOD;
				}
			}
			dp[day+1][N][0] += dp[day][N][0] * N;
			dp[day+1][N][0] %= MOD;
		}
		cout << dp[M][N][0] << endl;
	}
}



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

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define LB lower_bound
#define UB upper_bound

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = 1e9;
const LL MOD = 1e9+7;

//other
//-------------------------------------------
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define FI first
#define SE second

int main() {
  int A, B;
  cin >> A >> B;
  int ans = A - B*2;
  if(ans < 0) ans = 0;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

int main(){
  ll n,m;cin>>n>>m;
  vector<vector<ll>> v(ll(n+1));
  
  vector<ll> p(m),y(m);
  rep(i,m){
    cin>>p[i]>>y[i];
    v[p[i]].pb(y[i]);
  }
  rep(i,v.size()){
    sort(all(v[i]));
  }
  map<pl,ll> ans;
  rep(i,v.size()){
    rep(j,v[i].size()){
      ans[mp(i,v[i][j])]=j+1;
    }
  }

  rep(i,m){
    printf("%06lld%06lld\n", p[i],ans[mp(p[i],y[i])]);
  }
  return 0;
}

Measured memory_bytes: 14720
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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

ll N,T,A,l,r,tmp;

int main(){
    cin>>N;
    rep(i,N){
        cin>>T>>A;
        if(T>=l&&A>=r){
            l=T;
            r=A;
        }
        else{
            tmp=max((l+T-1)/T,(r+A-1)/A);
            l=T*tmp;
            r=A*tmp;
        }
        // out(l);
    }
    out(l+r);
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)

int main() {
    ll q,h,s,d,n;
    cin >> q >> h >> s >> d >> n;

    ll mn_2l = min(q*8, min(h*4, min(s*2, d)));
    ll mn_l = min(q*4, min(h*2, s));
    if(mn_2l > 2*mn_l) cout << mn_l*n << endl;
    else cout << mn_2l*(n/2)+mn_l*(n%2) << endl;
}

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

int main(){
	
	int a,b,c;
	
	cin >> a >> b >> c;
	
	if (a == b && a != c){
		cout << "Yes";
	} else if (a == c && b != c){
		cout << "Yes";
	} else if (b == c && a != c){
		cout << "Yes";
	} else {
		cout << "No";
	}
	
}


Measured memory_bytes: 256
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools
import queue
from collections import deque
from fractions import Fraction

def comb(n, r, mod):
    ans = 1
    for i in range(max(r, n - r) + 1, n + 1):
        ans *= i
        ans %= mod
    for i in range(1, min(r, n - r) + 1):
        ans *= pow(i, mod - 2, mod)
        ans %= mod
    return ans


def main():
    x, y = map(int, input().split())

    if (x + y) % 3 != 0:
        print(0)
        sys.exit()

    tate = (2 * y - x) // 3
    yoko = (2 * x - y) // 3

    if tate < 0 or yoko < 0:
        print(0)
        sys.exit()

    mod = 10 ** 9 + 7
    ans = comb(tate + yoko, tate, mod)
    print(ans)







if __name__ == '__main__':
    main()



Measured memory_bytes: 61420
#include<cstdio>
#include<iostream>
#include<algorithm>
#define N 200005
#define LL long long

using namespace std;

inline int In(){
	char c=getchar(); int x=0,ft=1;
	for(;c<'0'||c>'9';c=getchar()) if(c=='-') ft=-1;
	for(;c>='0'&&c<='9';c=getchar()) x=x*10+c-'0';
	return x*ft;
}

inline LL min(LL a,LL b){
	return a<b?a:b;
}

inline int max(int a,int b){
	return a>b?a:b;
}

int n,W[N],h[N],e_tot=0;
struct Edge{ int to,nex,w; }e[N<<1];

inline void add(int u,int v,int w){
	e[++e_tot]=(Edge){v,h[u],w}; h[u]=e_tot;
}

int rt,Sz,sz[N],f[N]; bool vis[N];

void Get_rt(int u,int pre){
	sz[u]=1; f[u]=0;
	for(int i=h[u],v;i;i=e[i].nex){
		v=e[i].to; if(vis[v]||v==pre) continue;
		Get_rt(v,u); sz[u]+=sz[v]; f[u]=max(f[u],sz[v]);
	}
	f[u]=max(f[u],Sz-sz[u]); if(f[u]<f[rt]) rt=u;
}

int Min_pos; LL Min_dis;

void dfs1(int u,int pre,LL dep){
	if(Min_dis>dep+W[u]) Min_dis=dep+W[u],Min_pos=u;
	for(int i=h[u],v;i;i=e[i].nex){
		v=e[i].to; if(vis[v]||v==pre) continue;
		dfs1(v,u,dep+e[i].w);
	}
}

int e_cnt=0;
struct E{
	int u,v; LL w;
	bool operator < (const E& r) const { return w<r.w; }
}edge[N*20];

void dfs2(int u,int pre,LL dep){
	edge[++e_cnt]=(E){u,Min_pos,dep+W[u]+Min_dis};
	for(int i=h[u],v;i;i=e[i].nex){
		v=e[i].to; if(vis[v]||v==pre) continue;
		dfs2(v,u,dep+e[i].w);
	}
}

void Solve(int u){
	vis[u]=1; Min_dis=9e18; Min_pos=0;
	dfs1(u,-1,0); if(Min_pos) dfs2(u,-1,0); 
	int Oth_sz=Sz-sz[u];
	for(int i=h[u],v;i;i=e[i].nex){
		v=e[i].to; if(vis[v]) continue;
		Sz=sz[v]>sz[u]?Oth_sz:sz[v]; rt=0; 
		Get_rt(v,u); Solve(rt);
	}
}

int fa[N],size[N]; LL ans;

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

inline void Unit(int a,int b){
	int x=Find(a),y=Find(b); if(x==y) return;
	if(sz[x]<sz[y]) swap(x,y);
	fa[y]=x; sz[x]+=sz[y];
}

int main(){
	n=In();
	for(int i=1;i<=n;++i) W[i]=In();
	for(int i=1;i<=n;++i) fa[i]=i,size[i]=1;
	for(int i=1,u,v,w;i<n;++i){
		u=In(); v=In(); w=In();
		add(u,v,w); add(v,u,w);
	}
	Sz=f[0]=n; rt=0; Get_rt(1,-1); Solve(rt);
	sort(edge+1,edge+1+e_cnt);
	for(int i=1,u,v;i<=e_cnt;++i){
		u=edge[i].u; v=edge[i].v;
		if(Find(u)!=Find(v)) Unit(u,v),ans+=edge[i].w;
	}
	printf("%lld\n",ans);
	return 0;
}

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

int main() {
  
  string O, E;
  cin >> O >> E;
  
  int s = O.size() + E.size();
  vector<string> pass(s);
  
  for(int i = 0; i < O.size(); i++) {
    pass.at(i*2) = O.at(i);
  }
  for(int i = 0; i < E.size(); i++) {
    pass.at(i*2+1) = E.at(i);
  }
  for(int i = 0; i < s; i++) {
    cout << pass.at(i);
  }
  cout << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
bool ar[35];
bool li[35][35];
int32_t main(){
	int n,m,k;cin>>n>>m;
	fill(ar,ar+m+1,1);
	for(int i=1;i<=n;i++){
		cin>>k;
		for(int j=1;j<=k;j++){
			int tmp;cin>>tmp;li[i][tmp]=1;
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			//cout<<i<<" "<<j<<" "<<li[i][j]<<" "<<ar[j]<<"\n";
			ar[j]&=li[i][j];
		}
	}
	int ans = 0;
	for(int i=1;i<=m;i++){
		ans += ar[i];
	}
	cout<<ans;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        StringBuilder tmp = new StringBuilder();
        tmp.append(a);
        tmp.append(b);
        int number = Integer.parseInt(tmp.toString());

        for(int i = 0; i < 500; i++) {
            if (number == i*i) {
                System.out.println("Yes");
                System.exit(0);
            }
        }
        System.out.println("No");
    }
}


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

#define   DEBUGG	0
#ifdef    DEBUGG
#define   VAR(x)    cout<<"L"<<__LINE__<<" | "<<#x<<" "<<x<<"\n";
#else
#define   VAR(x);
#endif
#ifdef    DEBUGG
template<typename T>void VARS(T a){cout<<a<<"\n";}
template<typename T,typename...Types>void VARS(T a,Types...bs){cout<<a<<" ";VARS(bs...);}
#else
#define   VARS(...);
#endif
#define    INF       3e9
typedef long long ll;
template<typename T> istream& operator>> (istream& is, vector<T>& the_vector) {
    for (int i = 0; i < (int)the_vector.size(); i++){
        is >> the_vector[i];
	} /*for(T& ele:the_vector)is>>ele;*/
    return is;
}
template<typename T> ostream& operator<< (ostream& os, vector<T>& the_vector) {
    for (int i = 0; i < (int)the_vector.size(); i++) {
        os << the_vector[i] << (i + 1 == (int)the_vector.size() ? "" : " ");
    }
    return os;
}
template<typename T> string join(vector<T>& the_vector, string mid = " ") {
    stringstream ss;
    for (int i = 0; i < (int)the_vector.size(); i++) {
        ss << the_vector[i] << (i + 1 == (int)the_vector.size() ? "" : mid);
    }
    return ss.str();
}


int main(){
	int n, m; cin >> n >> m;
	vector<int> a(m);
	cin >> a;
	for(int i = 0; i< (int)a.size(); ++i){
		n -= a[i];
	}
	cout << (n >= 0 ? n : -1) << "\n";
	return 0;
}

Measured memory_bytes: 3636
n = int(input())
primeL = []
for i in range(2,n+1):
    key = 0
    for j in primeL:
        if i % j == 0:
            key = 1
    if key == 0:
        primeL.append(i)
l = []
for i in primeL:
    count = 0
    a = i
    while a <= n:
        count += n//a
        a *= i
    l.append(count)
p = 0
q = 0
r = 0
s = 0
t = 0
for i in range(len(l)):
    if l[i] >= 74:
        p += 1
    if l[i] >= 24:
        q += 1
    if l[i] >= 14:
        r += 1
    if l[i] >= 4:
        s += 1
    if l[i] >= 2:
        t += 1
ans = 0
ans += p
ans += q*(t-1)
ans += r*(s-1)
ans += s*(s-1)*(t-2)//2
print(ans)

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

using namespace std;
int main()
{
  long long s = 0;
  int n;
  cin >> n;
  for(int i = 0;i <= n;i++)
  {
  	if(i % 3 == 0 || i % 5 == 0)
    {}
    else
    {
    	s += i;
    }
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

int n, m, a, b, c;
string s;

int main() {
    cin >> a >> b >> c;

    bool f = false;
    if (a == b && a != c) {
        f = true;
    } else if (a == c && a != b) {
        f = true;
    } else if (b == c && a != b) {
        f = true;
    }

    if (f) {
        std::cout << "Yes" << '\n';
    } else {
        std::cout << "No" << '\n';
    }

    return 0;
}


Measured memory_bytes: 256
import Data.List as List

main :: IO ()
main = do
    n <- (map read) . words <$> getLine
    mapM_ (putStrLn . show) (solve n)

solve :: [Int] -> [Int]
solve (a:b:k:_) = filter (\x -> a <= x && x <= b) $ union [a..a+k-1] [b-k+1..b]

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

int main(){
    int n;
    int p;
    int max=0;
    int sum=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>p;
        sum+=p;
        if(max<p)
            max=p;
    }
    sum-=max/2;
    cout<<sum<<endl;

}

Measured memory_bytes: 256
import numpy as np

def fn(a, b):
    for i in range(n-m+1):
        for j in range(n-m+1):
            if np.all(b == a[i:m+i,j:m+j]):
                return True
    return False

n, m = [int(i) for i in input().split()]
a = []
for i in range(n):
    res = []
    for j in input():
        if j == ".":
            res.append(1)
        elif j == "#":
            res.append(0)
    a.append(res)
b = []
for i in range(m):
    res = []
    for j in input():
        if j == ".":
            res.append(1)
        elif j == "#":
            res.append(0)
    b.append(res)

a = np.array(a)
b = np.array(b)

if fn(a, b):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 12508
#include <iostream>
#include <vector>
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
using namespace std;
static const int MAX_V = 100000;

//Graph Element

struct E {
	E(int t, int f) {
		to = t;
		from = f;
	}
	int to;
	int from;
	int cost;
	bool visited;
	bool use;
};
struct V {
	vector<E*> edge;
	bool visited;
};
V G[MAX_V];
/////////////////////////////////////////////

//dfs
int ans = 0;
int VS, ES;
void dfs(int n) {
	rep(i, 0, G[n].edge.size()) {
		if (G[n].edge[i]->use && !G[G[n].edge[i]->to].visited) {
			G[G[n].edge[i]->to].visited = true;
			dfs(G[n].edge[i]->to);
		}
	}
}

int main() {
	cin >> VS >> ES;

	rep(i, 0, ES)
	{
		int s, t; cin >> s >> t;
		G[s].edge.push_back(new E(t, s));
		G[t].edge.push_back(new E(s, t));
	}

	///////////////////////////////////////////////////////////

	//Edge all false
	repe(i, 1, VS) rep(j, 0, G[i].edge.size()) {
		//Edge all visited false;
		repe(k, 1, VS) rep(l, 0, G[k].edge.size()) G[k].edge[l]->use = true;
		repe(k, 1, VS) G[k].visited = false;

		G[i].edge[j]->use = false;

		//DFS
		G[1].visited = true;
		dfs(1);

		bool ok = true;
		repe(k, 1, VS)  ok &= G[k].visited;
		if (!ok)ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f

using namespace std;

struct Edge {
  int t,next;
  Edge() {}
  Edge(int a,int b):t(a),next(b) {}
};

Edge e[4005];
int head[2005];
bool in[2005];

int size[2005],dis[2005];
int f[2005];

void dfs(int x,int fa) {
  size[x]=in[x];dis[x]=f[x]=0;
  int son=0;
  for(int i=head[x];i;i=e[i].next)
    if (e[i].t!=fa) {
    	int u=e[i].t;
    	dfs(u,x);
    	size[x]+=size[u];
    	f[u]+=size[u];
    	dis[u]+=size[u];
    	if (dis[u]>dis[son]) son=u;
    	dis[x]+=dis[u];
	}
  if (!son) return;
  int s=0;
  for(int i=head[x];i;i=e[i].next)
    if (e[i].t!=fa&&e[i].t!=son) s+=dis[e[i].t];
  if (f[son]<=s) f[x]=((dis[son]^s)&1);
  else f[x]=f[son]-s;
}

char str[2005];

int main() {
  int n;
  scanf("%d%s",&n,str+1);
  for(int i=1;i<=n;i++) in[i]=str[i]-'0';
  for(int i=1;i<n;i++) {
  	int x,y;
  	scanf("%d%d",&x,&y);
  	e[2*i-1]=Edge(y,head[x]);
  	head[x]=2*i-1;
  	e[2*i]=Edge(x,head[y]);
  	head[y]=2*i;
  }
  dis[0]=-1;
  int ans=inf;
  for(int i=1;i<=n;i++) {
  	dfs(i,0);
  	if (!f[i]) ans=min(ans,dis[i]>>1);
  }
  printf("%d\n",(ans<inf)?ans:-1);
  return 0;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp26
{
    class Program
    {
        static void Main(string[] args)
        {
            int A;
            int B;
            int C;
            string a;
            string b;
            string c;
            string[] str = Console.ReadLine().Split();
            a = str[0];
            b = str[1];
            c = str[2];
            A = int.Parse(a);
            B = int.Parse(b);
            C = int.Parse(c);
            if (C >= A && C <= B)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
            Console.ReadLine();
        }
    }
}


Measured memory_bytes: 27452
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
 
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;
}
using namespace std;

void solve(){
    int n;
    cin>>n;
    vector<double>p(n);
    rep(i,n)cin>>p[i];
    vector<vector<double>>dp(n+1,vector<double>(n+1));//i枚目までで表がj枚の確率
    dp[0][0]=1.0;
    rep(i,n){
        for(int j=0;j<=i+1;++j){
            if(j==0)dp[i+1][0]=(1.0-p[i])*dp[i][0];
            else dp[i+1][j]=p[i]*dp[i][j-1]+(1.0-p[i])*dp[i][j];
        }
    }
    double ans=0;
    for(int i=(n+1)/2;i<=n;++i)ans+=dp[n][i];
    cout<<ans<<"\n";
}
 
signed main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
	cout<<fixed<<setprecision(15);
	solve();
	return 0;
}

Measured memory_bytes: 70912
#include <cstdint>
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i < (b); ++i)

long long combination(int n, int r)
{
  if (n - r < r)
    r = n - r;
  if (r == 0)
    return 1;
  if (r == 1)
    return n;

  vector<int> numerator(r);
  vector<int> denominator(r);

  for (int i = 0; i < r; i++)
  {
    numerator[i] = n - r + i + 1;
    denominator[i] = i + 1;
  }

  for (int i = 2; i <= r; i++)
  {
    int pivot = denominator[i - 1];
    if (pivot > 1)
    {
      int offset = (n - r) % i;
      for (int k = i - 1; k < r; k += i)
      {
        numerator[k - offset] /= pivot;
        denominator[k] /= pivot;
      }
    }
  }

  long long result = 1;
  for (int i = 0; i < r; i++)
  {
    if (numerator[i] > 1)
    {
      result *= numerator[i];
      result %= 1000000007;
    }
  }

  return result;
}

long long PowMod_RepeatSquaring(long long N, long long P, long long M)
{
  if (P == 0)
    return 1;
  if (P % 2 == 0)
  {
    long long t = PowMod_RepeatSquaring(N, P / 2, M);
    return t * t % M;
  }
  return N * PowMod_RepeatSquaring(N, P - 1, M);
}

int main()
{
  long long n, a, b;
  cin >> n >> a >> b;
  long long count = PowMod_RepeatSquaring(2, n, 1000000007) - 1;
  long long result1 = combination(n, a) % 1000000007;
  long long result2 = combination(n, b) % 1000000007;
  count -= (result1 + result2);
  cout << (count + 1000000007 * 2) % 1000000007 << endl;
  return 0;
}


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

int main(){
    int n;      
    unordered_map<int, int> m;
    cin >> n;
    int a;
    for(int i=0; i<n; i++){
        int a; cin >> a;
        m[a-1 ] += 1;
        m[a   ] += 1;
        m[a+1 ] += 1;
    }
    int max_num=0;
    for(auto x: m)
        max_num = max(max_num, x.second);
    cout << max_num << endl;
}

Measured memory_bytes: 4260
#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 = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}


int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n; ll k;
	cin >>n >>k;
	VI a(n);
	rep(i, n){ cin >>a[i]; a[i]--;}
	int cr = 0;
	map<int, int> mp ={{0,0}};
	int svs = -1, svc = -1;
	rep(i, n){
		cr = a[cr];
		if(mp.count(cr)){ svs = mp[cr]; svc=cr;break;}
		mp[cr] = i+1;
	}
	int lp = sz(mp)-svs;
	//dbg(lp, svs, svc);
	cr = 0;
	if(k < 2*n){
		rep(i, k) cr = a[cr];
	}else{
		ll nk = (k-svs)%lp;
		cr = svc;
		rep(i, nk) cr = a[cr];
	}
	
	//for(auto x :mp) cerr<<x.first<<": "<<x.second<<", "; dbg();
	cout << cr+1 <<"\n";
	return 0;
}


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


int main()
{
  int count;
  cin>>count;
  vector<int>all;
  for(int i=0;i<count;i++)
  {
    int first;
    cin>>first;
    all.push_back(first);
  }
  
  sort(all.rbegin(),all.rend());
  vector<int>b;
  for(int i=0;i<count;i++)
  {
    b.push_back(all[i]);
    if(i!=0)
      b.push_back(all[i]);
  }
  
  long long int ans=0;
  for(int i=0;i<count-1;i++){
    ans+=b[i];
  }
  
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 6156
#include <iomanip>
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  const int num[33] = {1, 1, 1, 2, 1, 2, 1, 5,  2, 2, 1, 5, 1, 2, 1, 14,
                       1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int K;
  cin >> K;
  K--;
  cout << num[K] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int c1,c5,c10,c50,c100,c500;
    cin>>c1>>c5>>c10>>c50>>c100>>c500;
    int C;
    C=c1+c5*5+10*c10+50*c50+100*c100+500*c500;
    if(C>=1000) cout<<"1";
    else    cout<<"0";
    cout<<endl;
}



Measured memory_bytes: 3084
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	ll N=in<ll>();
	vector<ll> P(N);

	bool has_zero=false;
	int neg=0;
	ll S=0,minAV=1LL<<60;;
	REP(i,N){
		P[i]=in();
		if(P[i]==0) has_zero=true;
		if(P[i]<0) neg++;
		S += abs(P[i]);
		if(abs(P[i])<minAV){
			minAV = abs(P[i]);
		}
	}

	if(has_zero || !(neg%2)){
		out(S);
		return 0;
	}
	
	out(S-2LL*minAV);
	return 0;
}


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  LL N, M;
  cin >> N >> M;

  VL fact(100010);
  fact[0] = 1;
  for(LL i=1;i<100010;++i)
	fact[i] = (fact[i-1] * i) % MOD;

  if(abs(N-M) > 1){
	cout << 0 << endl;
  }
  else if(N == M){
	cout << fact[N] * fact[M] * 2 % MOD << endl;
  }
  else{
	if(N > M) swap(N, M);
	cout << fact[N] * fact[M] % MOD << endl;
  }

  return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;
class MainClass
{
    static void Main()
    {
        string S = Console.ReadLine();
        var l = S.Length;
        long ans = 0;

        for(int bit = 0; bit < (1 << l-1); bit++)
        {
            long sum = int.Parse(S[0].ToString());
            
            for(int i = 1;i<l; i++)
            {
                if ((bit & (1 << i-1)) != 0)
                {
                    sum *= 10;
                    sum += int.Parse(S[i].ToString());
                }
                else
                {
                    ans += sum;
                    sum = int.Parse(S[i].ToString());
                }
            }
            ans += sum;
        }
        Console.WriteLine(ans);
    }
}


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

int main(){
    int N, D;
    cin >> N >> D;
    int ans = 0;
    int tree = 1;
    while(tree <= N){
        ans++;
        tree += 2*D + 1;
    }
    cout << ans << endl;
}


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

#define mp make_pair
#define eb emplace_back
#define ff first
#define ss second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#endif


const int MAXN = 100;
//#define int long long
const int INF = 1e9;

namespace atcoder {

// Reference: https://en.wikipedia.org/wiki/Fenwick_tree
template <class T> struct fenwick_tree {
    using U = T;

  public:
    fenwick_tree() : _n(0) {}
    fenwick_tree(int n) : _n(n), data(n) {}

    void add(int p, T x) {
        assert(0 <= p && p < _n);
        p++;
        while (p <= _n) {
            data[p - 1] += U(x);
            p += p & -p;
        }
    }

    T sum(int l, int r) {
        assert(0 <= l && l <= r && r <= _n);
        return sum(r) - sum(l);
    }

  private:
    int _n;
    std::vector<U> data;

    U sum(int r) {
        U s = 0;
        while (r > 0) {
            s += data[r - 1];
            r -= r & -r;
        }
        return s;
    }
};

}  // namespace atcoder



void solve(){
  int n, q;
  cin >> n >> q;
  int c, u, v;
  atcoder::fenwick_tree<ll> f(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> u;
    f.add(i, u);
  }
  for (int i = 0; i < q; i++){
    cin >> c >> u >> v;
    if (!c) f.add(u, v);
    else {
      cout << f.sum(u, v) << '\n';
    }
  }
}

signed main()
{
    #ifdef FILEIO
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    solve();

    return 0;
}


Measured memory_bytes: 8260
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <queue>
#include <cstring>
using namespace std;


int main() {
	long long N; cin >> N;
	vector<int> a; 
	long long x = N;
	while (x != 0) {
		long long y=x%2;
		if (y < 0)y += 2;
		a.push_back(y);
		x =(x-y)/ -2;
	}
	if (a.size() == 0)cout << 0;
	for (int i = a.size()-1; i >=0 ; i--)cout << a[i];
}





Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll INF=1e9+7;


int main()
{
    ll n,c;
    cin >> n >> c;
    vector<vector<ll>> a(c,vector<ll>(c));
    vector<vector<ll>> b(n,vector<ll>(n));
    rep(i,c){
        rep(j,c){
            cin >> a[i][j];
        }
    }
    rep(i,n){
        rep(j,n){
            cin >> b[i][j];
        }
    }
    vector<vector<ll>> cost(3,vector<ll>(c,0));
    rep(i,c){
        rep(p,n){
            rep(q,n){
                ll r=(p+q+2)%3;
                ll s=b[p][q]-1;
                if(r==0) cost[0][i]+=a[s][i];
                if(r==1) cost[1][i]+=a[s][i];
                if(r==2) cost[2][i]+=a[s][i];
            }
        }
    }
    ll ans=INF;
    rep(i,c){
        rep(j,c){
            rep(k,c){
                ll sum=0;
                if(i==j || j==k || k==i) continue;
                sum=cost[0][i]+cost[1][j]+cost[2][k];
                ans=min(ans,sum);
            }
        }
    }
    cout << ans <<endl;
    return 0;
} 


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

int main()
{
  int a,b,c,d,e;
  cin>>a>>b>>c>>d>>e;
  if(a==0)
    cout<<1<<endl;
  if(b==0)
    cout<<2<<endl;
  if(c==0)
    cout<<3<<endl;
  if(d==0)
    cout<<4<<endl;
  if(e==0)
    cout<<5<<endl;
}

Measured memory_bytes: 3544
import java.lang.Math.min

fun Boolean.toInt() = if (this) 1 else 0

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val s = readLine()!!.reversed()
    var dp = Array(2) {
        Array<Int>(n + 1) { 0 }
    }
    for (i in listOf(0, 1)) {
        for (j in 0 until n) {
            dp[0][j + 1] = dp[0][j] + (s[j] == '.').toInt()
            dp[1][j + 1] = min(dp[0][j], dp[1][j] + (s[j] == '#').toInt())
        }
    }
    println(min(dp[0][n], dp[1][n]))
}

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

int main() {
    int N, sum;
    cin >> N;
    if (N % 2 == 0) {
        sum = N + 1;
        cout << N * (N-2) / 2 << endl;
    } else {
        sum = N;
        cout << (N-1) * (N-1) / 2 << endl;
    } 
    for (int i = 1; i < N; i++)
        for (int j = i+1; j <= N; j++) {
            if (i + j != sum)
                cout << i << ' ' << j << endl;
        }
    return 0;
}

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

using namespace std;

typedef long long ll;

int n, p;
ll l;
int lc[100100], rc[100100];
bool ed[100100];

char buf[100100];

void con(int cur, int i) {
    if (!buf[i]) {
        ed[cur] = 1;
        return;
    }
    int *xc = ((buf[i]=='0')?lc:rc);
    if (xc[cur]<0) {
        xc[cur]=p;
        lc[p]=rc[p]=-1;
        p++;
    }
    con(xc[cur],i+1);
}

ll c;
void dfs(int cur, ll d=0) {
    if (ed[cur]) return;
    if (~lc[cur]) dfs(lc[cur],d+1);
    else c^=(l-d)&(d-l);
    if (~rc[cur]) dfs(rc[cur],d+1);
    else c^=(l-d)&(d-l);
}

int main() {
    int i, j;

    scanf("%d%lld",&n,&l);
    lc[0]=rc[0]=-1;p=1;
    for (i=0;i<n;i++) {
        scanf("%s",buf);
        con(0,0);
    }
    dfs(0);
    puts(c?"Alice":"Bob");

    return 0;
}


Measured memory_bytes: 2688
import java.util.Scanner;

public class Main {

	static int mod = 1000000007;

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int M = in.nextInt();
		if (Math.abs(N - M) > 1) {
			System.out.println(0);
			in.close();
			return;
		}
		long dog = 1;
		for (int i = 1; i <= N; i++) {
			dog = dog * i % mod;
		}
		long mon = 1;
		for (int i = 1; i <= M; i++) {
			mon = mon * i % mod;
		}
		long ans = N == M ? dog * mon * 2 % mod : dog * mon % mod;
		System.out.println(ans);
		in.close();
	}
}

Measured memory_bytes: 23764
#include "bits/stdc++.h"
#include <sys/timeb.h>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr = ds.begin(); itr != ds.end(); ++itr)
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295
typedef long long ll;
typedef pair<int, int> P;


void Dijkstra(vector<vector<P> > graph, int start, vector<int> &cost, int V) {
	vector<int> prev(V);
	vector<bool> visited(V);
	priority_queue<P, vector<P>, greater<P> > Q;

	fill(cost.begin(), cost.end(), INF);
	cost[start] = 0;

	Q.push(mp(0, start));	// (cost, index)

	while (!Q.empty()) {
		P pos = Q.top();
		Q.pop();
		rep(i, graph[pos.second].size()) {
			if (cost[graph[pos.second][i].first] > cost[pos.second] + graph[pos.second][i].second) {
				cost[graph[pos.second][i].first] = cost[pos.second] + graph[pos.second][i].second;
				Q.push(mp(cost[graph[pos.second][i].first], graph[pos.second][i].first));
			}
		}
	}
}

int main() {
	int V, E, r;
	cin >> V >> E >> r;
	vector<vector<P> >g(V);
	vector<int> c(V);

	rep(i, E) {
		int s, t, d;
		cin >> s >> t >> d;
		g[s].push_back(mp(t, d));
	}

	Dijkstra(g, r, c, V);

	rep(i, V) {
		if (c[i] == INF) {
			cout << "INF" << endl;
		}
		else {
			cout << c[i] << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 20596
/*
⣿⣿⣿⣿⣿⣿⡷⣯⢿⣿⣷⣻⢯⣿⡽⣻⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣇⠸⣿⣿⣆⠹⣿⣿⢾⣟⣯⣿⣿⣿⣿⣿⣿⣽⣻⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣻⣽⡿⣿⣎⠙⣿⣞⣷⡌⢻⣟⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣿⣿⡄⠹⣿⣿⡆⠻⣿⣟⣯⡿⣽⡿⣿⣿⣿⣿⣽⡷⣯⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣟⣷⣿⣿⣿⡀⠹⣟⣾⣟⣆⠹⣯⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢠⡘⣿⣿⡄⠉⢿⣿⣽⡷⣿⣻⣿⣿⣿⣿⡝⣷⣯⢿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣯⢿⣾⢿⣿⡄⢄⠘⢿⣞⡿⣧⡈⢷⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢸⣧⠘⣿⣷⠈⣦⠙⢿⣽⣷⣻⣽⣿⣿⣿⣿⣌⢿⣯⢿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣟⣯⣿⢿⣿⡆⢸⡷⡈⢻⡽⣷⡷⡄⠻⣽⣿⣿⡿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣏⢰⣯⢷⠈⣿⡆⢹⢷⡌⠻⡾⢋⣱⣯⣿⣿⣿⣿⡆⢻⡿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⡎⣿⢾⡿⣿⡆⢸⣽⢻⣄⠹⣷⣟⣿⣄⠹⣟⣿⣿⣟⣿⣿⣿⣿⣿⣿⣽⣿⣿⣿⡇⢸⣯⣟⣧⠘⣷⠈⡯⠛⢀⡐⢾⣟⣷⣻⣿⣿⣿⡿⡌⢿⣻⣿⣿
⣿⣿⣿⣿⣿⣿⣧⢸⡿⣟⣿⡇⢸⣯⣟⣮⢧⡈⢿⣞⡿⣦⠘⠏⣹⣿⣽⢿⣿⣿⣿⣿⣯⣿⣿⣿⡇⢸⣿⣿⣾⡆⠹⢀⣠⣾⣟⣷⡈⢿⣞⣯⢿⣿⣿⣿⢷⠘⣯⣿⣿
⣿⣿⣿⣿⣿⣿⣿⡈⣿⢿⣽⡇⠘⠛⠛⠛⠓⠓⠈⠛⠛⠟⠇⢀⢿⣻⣿⣯⢿⣿⣿⣿⣷⢿⣿⣿⠁⣾⣿⣿⣿⣧⡄⠇⣹⣿⣾⣯⣿⡄⠻⣽⣯⢿⣻⣿⣿⡇⢹⣾⣿
⣿⣿⣿⣿⣿⣿⣿⡇⢹⣿⡽⡇⢸⣿⣿⣿⣿⣿⣞⣆⠰⣶⣶⡄⢀⢻⡿⣯⣿⡽⣿⣿⣿⢯⣟⡿⢀⣿⣿⣿⣿⣿⣧⠐⣸⣿⣿⣷⣿⣿⣆⠹⣯⣿⣻⣿⣿⣿⢀⣿⢿
⣿⣿⣿⣿⣿⣿⣿⣿⠘⣯⡿⡇⢸⣿⣿⣿⣿⣿⣿⣿⣧⡈⢿⣳⠘⡄⠻⣿⢾⣽⣟⡿⣿⢯⣿⡇⢸⣿⣿⣿⣿⣿⣿⡀⢾⣿⣿⣿⣿⣿⣿⣆⠹⣾⣷⣻⣿⡿⡇⢸⣿
⣿⣿⣿⣿⣿⣿⣿⣿⡇⢹⣿⠇⢸⣿⣿⣿⣿⣿⣿⣿⣿⣷⣄⠻⡇⢹⣆⠹⣟⣾⣽⣻⣟⣿⣽⠁⣾⣿⣿⣿⣿⣿⣿⣇⣿⣿⠿⠛⠛⠉⠙⠋⢀⠁⢘⣯⣿⣿⣧⠘⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⡈⣿⡃⢼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⡙⠌⣿⣆⠘⣿⣞⡿⣞⡿⡞⢠⣿⣿⣿⣿⣿⡿⠛⠉⠁⢀⣀⣠⣤⣤⣶⣶⣶⡆⢻⣽⣞⡿⣷⠈⣿
⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⠘⠁⠉⠉⠉⠉⠉⠉⠉⠉⠉⠙⠛⠛⢿⣄⢻⣿⣧⠘⢯⣟⡿⣽⠁⣾⣿⣿⣿⣿⣿⡃⢀⢀⠘⠛⠿⢿⣻⣟⣯⣽⣻⣵⡀⢿⣯⣟⣿⢀⣿
⣿⣿⣿⣟⣿⣿⣿⣿⣶⣶⡆⢀⣿⣾⣿⣾⣷⣿⣶⠿⠚⠉⢀⢀⣤⣿⣷⣿⣿⣷⡈⢿⣻⢃⣼⣿⣿⣿⣿⣻⣿⣿⣿⡶⣦⣤⣄⣀⡀⠉⠛⠛⠷⣯⣳⠈⣾⡽⣾⢀⣿
⣿⢿⣿⣿⣻⣿⣿⣿⣿⣿⡿⠐⣿⣿⣿⣿⠿⠋⠁⢀⢀⣤⣾⣿⣿⣿⣿⣿⣿⣿⣿⣌⣥⣾⡿⣿⣿⣷⣿⣿⢿⣷⣿⣿⣟⣾⣽⣳⢯⣟⣶⣦⣤⡾⣟⣦⠘⣿⢾⡁⢺
⣿⣻⣿⣿⡷⣿⣿⣿⣿⣿⡗⣦⠸⡿⠋⠁⢀⢀⣠⣴⢿⣿⣽⣻⢽⣾⣟⣷⣿⣟⣿⣿⣿⣳⠿⣵⣧⣼⣿⣿⣿⣿⣿⣾⣿⣿⣿⣿⣿⣽⣳⣯⣿⣿⣿⣽⢀⢷⣻⠄⠘
⣿⢷⣻⣿⣿⣷⣻⣿⣿⣿⡷⠛⣁⢀⣀⣤⣶⣿⣛⡿⣿⣮⣽⡻⣿⣮⣽⣻⢯⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣯⢀⢸⣿⢀⡆
⠸⣟⣯⣿⣿⣷⢿⣽⣿⣿⣷⣿⣷⣆⠹⣿⣶⣯⠿⣿⣶⣟⣻⢿⣷⣽⣻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢀⣯⣟⢀⡇
⣇⠹⣟⣾⣻⣿⣿⢾⡽⣿⣿⣿⣿⣿⣆⢹⣶⣿⣻⣷⣯⣟⣿⣿⣽⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⢀⡿⡇⢸⡇
⣿⣆⠹⣷⡻⣽⣿⣯⢿⣽⣻⣿⣿⣿⣿⣆⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠛⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠇⢸⣿⠇⣼⡇
⡙⠾⣆⠹⣿⣦⠛⣿⢯⣷⢿⡽⣿⣿⣿⣿⣆⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠃⠎⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠏⢀⣿⣾⣣⡿⡇
⣿⣷⡌⢦⠙⣿⣿⣌⠻⣽⢯⣿⣽⣻⣿⣿⣿⣧⠩⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡏⢰⢣⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⢀⢀⢿⣞⣷⢿⡇
⣿⣽⣆⠹⣧⠘⣿⣿⡷⣌⠙⢷⣯⡷⣟⣿⣿⣿⣷⡀⡹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣈⠃⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⢀⣴⡧⢀⠸⣿⡽⣿⢀
⢻⣽⣿⡄⢻⣷⡈⢿⣿⣿⢧⢀⠙⢿⣻⡾⣽⣻⣿⣿⣄⠌⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠛⢁⣰⣾⣟⡿⢀⡄⢿⣟⣿⢀
⡄⢿⣿⣷⢀⠹⣟⣆⠻⣿⣿⣆⢀⣀⠉⠻⣿⡽⣯⣿⣿⣷⣈⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⢀⣠⠘⣯⣷⣿⡟⢀⢆⠸⣿⡟⢸
⣷⡈⢿⣿⣇⢱⡘⢿⣷⣬⣙⠿⣧⠘⣆⢀⠈⠻⣷⣟⣾⢿⣿⣆⠹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⣠⡞⢡⣿⢀⣿⣿⣿⠇⡄⢸⡄⢻⡇⣼
⣿⣷⡈⢿⣿⡆⢣⡀⠙⢾⣟⣿⣿⣷⡈⠂⠘⣦⡈⠿⣯⣿⢾⣿⣆⠙⠻⠿⠿⠿⠿⡿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠛⢋⣠⣾⡟⢠⣿⣿⢀⣿⣿⡟⢠⣿⢈⣧⠘⢠⣿
⣿⣿⣿⣄⠻⣿⡄⢳⡄⢆⡙⠾⣽⣿⣿⣆⡀⢹⡷⣄⠙⢿⣿⡾⣿⣆⢀⡀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⣀⣠⣴⡿⣯⠏⣠⣿⣿⡏⢸⣿⡿⢁⣿⣿⢀⣿⠆⢸⣿
⣿⣿⣿⣿⣦⡙⣿⣆⢻⡌⢿⣶⢤⣉⣙⣿⣷⡀⠙⠽⠷⠄⠹⣿⣟⣿⣆⢙⣋⣤⣤⣤⣄⣀⢀⢀⢀⢀⣾⣿⣟⡷⣯⡿⢃⣼⣿⣿⣿⠇⣼⡟⣡⣿⣿⣿⢀⡿⢠⠈⣿
⣿⣿⣿⣿⣿⣷⣮⣿⣿⣿⡌⠁⢤⣤⣤⣤⣬⣭⣴⣶⣶⣶⣆⠈⢻⣿⣿⣆⢻⣿⣿⣿⣿⣿⣿⣷⣶⣤⣌⣉⡘⠛⠻⠶⣿⣿⣿⣿⡟⣰⣫⣴⣿⣿⣿⣿⠄⣷⣿⣿⣿
*/

#include <bits/stdc++.h>

using namespace std;

int main(){
  ios::sync_with_stdio(false);

  string s;
  cin >> s;

  int x = stoi(s.substr(0,2));
  int y = stoi(s.substr(2));

  string ans;
  if(x <= 12 and x > 0){
    if(y > 12) ans = "MMYY";
    else if(y == 0) ans = "MMYY";
    else ans = "AMBIGUOUS";
  }
  else if(x > 12 or x == 0){
    if(y <= 12 and y > 0) ans = "YYMM";
    else ans = "NA";
  }
  if(x == 0 and y == 0) ans = "NA";

  cout << ans << endl;

  return 0;

}


Measured memory_bytes: 256
#include <iostream>
 using namespace std;
 int main(){
 string s;
 cin >> s;
 int ans;
 if(s == "SUN")ans = 7;
 else if(s == "MON")ans = 6;
 else if(s == "TUE")ans = 5;
 else if(s == "WED")ans = 4;
 else if(s == "THU")ans = 3;
 else if(s == "FRI")ans = 2;
 else if(s == "SAT")ans = 1;
 cout << ans << endl;
 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)x.size()
#define int ll

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, m;
	cin >> n >> m;
	vector<vector<char>> ans1(n + 1, vector<char>(m + 1, '.')), ans2(n + 1, vector<char>(m + 1, '.'));
	for (int i = 1; i <= n; i++) {
		ans1[i][1] = '#';
		ans2[i][m] = '#';
	}
	for (int i = 1; i <= n; i++) {
		if (i & 1) {
			for (int j = 2; j < m; j++) {
				ans2[i][j] = '#';
			}
		}
		else {
			for (int j = 2; j < m; j++) {
				ans1[i][j] = '#';
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			char c;
			cin >> c;
			if (c == '#') {
				ans1[i][j] = ans2[i][j] = c;
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			cout << ans1[i][j];
		}
		cout << '\n';
	}
	cout << '\n';	
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			cout << ans2[i][j];
		}
		cout << '\n';
	}
}

Measured memory_bytes: 1280