akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
#define m_p make_pair
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pr;
typedef vector<pr> vpr;
typedef vector<vector<int>> vvi;
const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

int main()
{
    ll n,m,a,b,c,ans=0;
    map<ll,ll> mp;
    cin >> n >> m;
    vector<pair<ll,ll>> v;
    rep(i,n){
        cin >> a;
        v.pb(m_p(a,1));
    }
    rep(i,m){
        cin >> b >> c;
        v.pb(m_p(c,b));
    }
    sort(rall(v));
    ll y=0;
    while(n>0){
        ans+=v[y].first*min(v[y].second,n);
        n-=min(v[y].second,n);
        y++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6384
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <tuple>
#include <cmath>
using namespace std;

int main(int argc, const char * argv[]) {
  int a, b, c;
  cin >> a >> b >> c;
  for(int i = a; i < a*b; i++){
    if(i*a%b == c){
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "cstring"
#include "cmath"
#include "cstdio"
#include "algorithm"
using namespace std;

int main(int argc, char const *argv[]) {
  string s;
  cin>>s;
  int c=0;
  for(int i=1;i<s.length()-1;i++){
    c++;
  }
  cout<<s[0]<<c<<s[s.length()-1]<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
long N,A;
main()
{
	cin>>N>>A;
	long ans=N;
	for(int k=1;k<40;k++)
	{
		long p=pow(N,1./(k+1));
		long now=1;
		for(int i=0;i<k;i++)now*=p;
		for(int i=0;i<=k;i++)
		{
			ans=min(ans,A*k+p*k+i+(N+now-1)/now);
			now=now/p*(p+1);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,a[N],f[N];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    a[n+1]=1e9+1;
    int ans=0;
    for(int i=n;i>=1;i--)
        if(a[i+1]>a[i]) f[i]=1;
    else f[i]=f[i+1]+1;
    for(int i=1;i<=n;i++)
        ans=max(ans,f[i]);
    printf("%d\n",ans-1);
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cctype>
using namespace std;

int main()
{
	char ch;
	while(1){
		scanf("%c",&ch);
		if(ch == '\n') break;
		if(islower(ch)) ch = toupper(ch);
		else ch = tolower(ch);
		
		cout << ch;
	}
	cout << endl;
	
	return 0;

}

Measured memory_bytes: 3136
#include<bits/stdc++.h>
using namespace std;
#define N 100003

int n,m;
int g[N];
long long k,a[N],Max,ans,lim,sum;

inline int read(){
	int X=0,w=0;
	char ch=0;
	while (ch<'0' || ch>'9')
	  w|=ch=='-',ch=getchar();
	while (ch>='0' && ch<='9')
	  X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
	return w ? -X : X;
}

int main(){
	n=read();
	scanf("%lld",&k);
	Max=0;
	for (int i=1;i<=n;i++){
	  	scanf("%lld",&a[i]);
		Max=max(Max,a[i]);
	}
	for (lim=1;lim<=k;lim<<=1);
	ans=0;
	for (lim;lim;lim>>=1){
		int res=0;
		for (int j=1;j<=n;j++)
		  if ((a[j] & lim)==lim) res++;
		if (res<n-res && ans+lim<=k) ans+=lim; 	
	}
	sum=0; 
	for (int i=1;i<=n;i++)
	  sum=(sum+(ans^a[i]));
	printf("%lld\n",sum);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> P;

struct UnionFind{
	vector<int> rnk,par,num;
	UnionFind(int N) : rnk(N),par(N),num(N){
		init();
	}
	void init(){
		for(int i = 0;i < rnk.size();i++){
			rnk[i] = 0;
			par[i] = i;
			num[i] = 1;
		}
	}
	int find(int x){
		if(par[x] == x) return x;
		return par[x] = find(par[x]);
	}
	void unite(int x,int y){
		x = find(x);
		y = find(y);
		if(x == y) return;
		if(rnk[x] < rnk[y]){
			par[x] = y;
			num[y] += num[x];
		}
		else{
			par[y] = x;
			num[x] += num[y];
			if(rnk[x] == rnk[y]) rnk[x]++;
		}
	}
	bool same(int x,int y){
		return (find(x) == find(y));
	}
	int size(int x){
		return num[find(x)];
	}
};

struct edge{int u, v, cost;};

bool comp(const edge& e1, const edge& e2){
  return e1.cost < e2.cost;
}

signed main(){
  int N; cin >> N;
  vector<P> x(N), y(N);
  for(int i = 0; i < N; i++){
	int x1, y1; cin >> x1 >> y1;
	x[i] = P(x1, i); y[i] = P(y1, i);
  }
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  vector<edge> es;
  for(int i = 1; i < N; i++){
	  edge e1 = {x[i - 1].second, x[i].second, abs(x[i].first - x[i - 1].first)};
	  edge e2 = {y[i - 1].second, y[i].second, abs(y[i].first - y[i - 1].first)};
	  es.push_back(e1), es.push_back(e2);
  }
  sort(es.begin(), es.end(), comp);
  int ans = 0;
  UnionFind tree(2 * N);
  for(int i = 0; i < es.size(); i++){
	  edge e = es[i];
	  if(!tree.same(e.u, e.v)){
		  ans += e.cost;
	  }
	  tree.unite(e.u, e.v);
  }
  cout << ans << endl;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define fst first
#define sc second
#define snd second
#define sz(X) (int)(X).size()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define fornr(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define forab(i, a, b) for(int i = int(a); i < int(b); i++)
#define forabr(i, a, b) for(int i = int(b)-1; i >= int(a); i--)
#define all(X) X.begin(), X.end()

typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef double dbl;
typedef long double ld;
typedef vector<int> vi;

const int N = 3001;
const int T = 3000;

int pref[N][T], suff[N][T];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(20);
    int n, t;
    cin >> n >> t;
    vector<pii> a(n);
    forn(i, n) cin >> a[i].fst >> a[i].snd;
    vector<pii> b = a;
    reverse(all(b));
    forn(i, n) {
        forn(j, T) {
            pref[i + 1][j] = max(pref[i + 1][j], pref[i][j]);
            if (j + a[i].fst < T) pref[i + 1][a[i].fst + j] = max(pref[i + 1][a[i].fst + j], pref[i][j] + a[i].snd);
        }
    }
    forn(i, n) {
        forn(j, T) {
            suff[i + 1][j] = max(suff[i + 1][j], suff[i][j]);
            if (j + b[i].fst < T) suff[i + 1][b[i].fst + j] = max(suff[i + 1][b[i].fst + j], suff[i][j] + b[i].snd);
        }
    }
    int ans = 0;
    forn(i, n) {
        forn(j, t) {
            ans = max(ans, pref[i][j] + a[i].snd + suff[n - 1 - i][t - j - 1]);
        }
    }
    cout << ans << "\n";
    return 0;
}

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

const int MAX = 200000;

int main(){
    int N;
    int A[MAX];

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

    sort(A,A+N);

    long long ans = A[N - 1];
    priority_queue< pair<int,int> > q;

    q.push(pair<int,int>(A[N - 2],A[N - 1]));
    q.push(pair<int,int>(A[N - 2],A[N - 1]));

    for(int i = N - 3;i >= 0;i--){
        pair<int,int> p = q.top();q.pop();
        ans += p.first;
        q.push(pair<int,int>(A[i],p.first));
        q.push(pair<int,int>(A[i],p.second));
    }


    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5676
/*{{{*/
//#define HOME
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;

#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define F first
#define S second

template<class T> void _R(T &_x) { cin >> _x; }
void _R(int &_x) { scanf("%d", &_x); }
void _R(int64_t &_x) { scanf("%" SCNd64, &_x); }
void _R(double &_x) { scanf("%lf", &_x); }
void _R(char &_x) { scanf(" %c", &_x); }
void _R(char *_x) { scanf("%s", _x); }
template<class T, class U> void _R(pair<T, U> &_x) {_R(_x.F); _R(_x.S);}
void R() {}
template<class T, class... U> void R(T &_head, U &... _tail) { _R(_head); R(_tail...); }

template<class T> void _W(const T &_x) { cout << _x; }
void _W(const int &_x) { printf("%d", _x); }
void _W(const int64_t &_x) { printf("%" PRId64, _x); }
void _W(const double &_x) { printf("%.16f", _x); }
void _W(const char &_x) { putchar(_x); }
void _W(const char *_x) { printf("%s", _x); }
template<class T, class U> void _W(const pair<T, U> &_x) {_W(_x.F); putchar(' '); _W(_x.S);}
template<class T> void _W(const vector<T> &_x) { for (auto i = _x.begin(); i != _x.end(); _W(*i++)) if (i != _x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &_head, const U &... _tail) { _W(_head); putchar(sizeof...(_tail) ? ' ' : '\n'); W(_tail...); }
template<class T, class... U> void DB(const T &_head, const U &... _tail) {
#ifdef HOME
    W('#', _head, _tail...);
#endif
}

#define SZ(x) (int)((x).size())
#define ALL(x) (x).begin(), (x).end()
#define RAN(x,n) (x).begin(), (x).begin()+(n)
#define UNIQUE(x) {sort(ALL(x)); (x).erase(unique(ALL(x)), (x).end());}

#define REP(i,a,b) for (int i = (a); i <= (b); ++i)
#define REPD(i,a,b) for (int i = (a); i >= (b); --i)
#define FORI(i,n) REP(i,1,n)
#define FOR(i,n) REP(i,0,int(n)-1)
//#define ITER(i,t) for (auto i = t.begin(); i != t.end(); ++i)
#define IT3(i,st,ed) for (auto i = st; i != ed; ++i)
#define IT2(i,range) IT3(i,range)

#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define MS(X, v) memset((X), (v), sizeof((X)))

template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

inline int LG (const unsigned int &_x) { return 31-__builtin_clz(_x); }  // floor: LG(x), ceil: LG(x-1)+1
/*}}}*/

int n;
vector<ll> as;

int main(){
    R(n);
    as.assign(n, 0LL);
    FOR(i, n) R(as[i]);

    ll s = 0;
    FOR(i, n) s ^= as[i];
    FOR(i, n) as[i] &= ~s;

    ll m = 0;
    REPD(b, 59, 0){
        ll f = 0;
        FOR(i, n) if(as[i] & (1LL << b)){ f = as[i]; break; }
        FOR(i, n) if(as[i] & (1LL << b)) as[i] ^= f;
        if(~m & (1LL << b)) m ^= f;
    }

    W((s^m) + m);

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int n;
int a[50][26];
string ans="";
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        string s;cin>>s;
        for(int j=0;j<s.size();j++){
            a[i][s.at(j)-'a']++;
        }
    }
    for(int j=0;j<26;j++){
        int M=100;
        for(int i=0;i<n;i++){
            M=min(M,a[i][j]);
        }
        string s(M,'a'+j);
        ans+=s;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define re register
#define LL long long
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
inline int read() {
	char c=getchar();int x=0;while(c<'0'||c>'9') c=getchar();
	while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+c-48,c=getchar();return x;
}
const int mod=1e9+7;const int maxn=2e5+5;
struct Seg{int x,y;}c[maxn];
struct Goast{int x,v;}a[maxn];
int n,mx[maxn],mn[maxn],b[maxn],pre[maxn],dp[maxn];
inline int dqm(int x) {return x<0?x+mod:x;}
inline int qm(int x) {return x>=mod?x-mod:x;}
inline int cop(const Goast &A,const Goast &B) {return A.x<B.x;}
inline int ctp(const Seg &A,const Seg &B) {return A.y==B.y?A.x<B.x:A.y<B.y;}
inline int find(int v) {
	int l=0,r=n,nw=-1;
	while(l<=r) {
		int mid=l+r>>1;
		if(c[mid].y<v) nw=mid,l=mid+1;else r=mid-1;
	}
	return nw;
} 
int main() {
	//freopen("data.in","r",stdin);
	//freopen("my.out","w",stdout);
	n=read();for(re int i=1;i<=n;i++) a[i].x=read(),b[i]=a[i].v=read();
	std::sort(b+1,b+n+1);
	for(re int i=1;i<=n;i++) a[i].v=std::lower_bound(b+1,b+n+1,a[i].v)-b;
	std::sort(a+1,a+n+1,cop);c[n].x=a[n].v;
	for(re int i=n-1;i;i--) c[i].x=min(c[i+1].x,a[i].v);
	for(re int i=1;i<=n;i++) c[i].y=max(c[i-1].y,a[i].v);
	std::sort(c+1,c+n+1,ctp);dp[0]=pre[0]=1;int ans=0;
	for(re int i=1;i<=n;i++) {
		int t=find(c[i].x-1);
		dp[i]=dqm(pre[i-1]-(t==-1?0:pre[t]));
		pre[i]=qm(pre[i-1]+dp[i]);
	}
	//for(re int i=1;i<=n;i++) printf("%d %d %d\n",c[i].x,c[i].y,dp[i]);
	for(re int i=1;i<=n;i++)if(c[i].y==n)ans=qm(ans+dp[i]);
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 7296
import java.io.*;
import java.util.StringTokenizer;
class Main {
public static void main(String args[]) {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
try {
String buf = br.readLine();
StringTokenizer st = new StringTokenizer(buf);
int W = Integer.parseInt(st.nextToken());
int H = Integer.parseInt(st.nextToken());
int x = Integer.parseInt(st.nextToken());
int y = Integer.parseInt(st.nextToken());
int r = Integer.parseInt(st.nextToken());
if (x-r<0||x+r>W||y-r<0||y+r>H) 
System.out.println("No");
else System.out.println("Yes");
} catch (IOException e) {
System.out.println("IOException!");
}
}
}

Measured memory_bytes: 24352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ans;
int num[100010];
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		scanf("%d",&num[i]);
		if(num[i]==i) ans++;
	}
	if(!ans){
		cout<<0<<endl;
		return 0;
	}
	ans=0;
	for(int i=1;i<=n;i++){
		if(num[i]==i){
			ans++;
			swap(num[i],num[i+1]);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 640
from collections import deque
import sys
input = sys.stdin.readline
import bisect as bi

def main():
    n = int(input())
    l = sorted(map(int, input().split()))

    ans = 0
    for i in range(n):
        for j in range(i+1, n):
            ind = bi.bisect_left(l, l[i]+l[j])
            ans += max(ind-j-1, 0)

    print(ans)

main()


Measured memory_bytes: 3572
N=int(input())
S=input()
lis=list(S)
maxi=0

for i in range(1,N):
  left=set(lis[0:i])
  right=set(lis[i:])
  uni=left&right
  #print(left,right,uni)
  maxi=max(maxi,len(uni))
  
print(maxi)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll mo = 1000000007;
const ll INF = 1LL << 59; //MAX 9223372036854775807
ll ans = 0;

int main()
{
ll n;
cin >> n;
ll t[n] = {};
rep(i, n){
    cin >> t[i];
}
ll xxor=0;
rep(i,n){
    xxor=xxor^t[i];
}

if(xxor!=0)cout << "No" << endl;
else cout << "Yes" << endl;
return 0;
}


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

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

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

	sort(h.begin(), h.end(), greater<long long>());

	for (int i = 0; i < min(n, k); ++i) h[i] = 0;
	long long ans = 0;

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

	cout << ans << endl;
}

Measured memory_bytes: 4028
#include<bits/stdc++.h>
using namespace std;
int n,m,s[10],c[10];
int main() {
	scanf("%d %d",&n,&m);
	for(int i=1; i<=m; i++)
		scanf("%d %d",&s[i],&c[i]);
	int a[4];
	if(n==1) {
		for(a[1]=0; a[1]<=9; a[1]++) {
			bool flag=1;
			for(int j=1; j<=m; j++)
				if(a[s[j]]!=c[j]) {
					flag=0;
					break;
				}
			if(flag) {
				printf("%d",a[1]);
				return 0;
			}
		}
		printf("-1");
	}
	if(n==2) {
		for( a[1]=1; a[1]<=9; a[1]++)
			for(a[2]=0; a[2]<=9; a[2]++) {
				bool flag=1;
				for(int j=1; j<=m; j++)
					if(a[s[j]]!=c[j]) {
						flag=0;
						break;
					}
				if(flag) {
					printf("%d",a[1]*10+a[2]);
					return 0;
				}
			}
		printf("-1");
	}
	if(n==3) {
		for(a[1]=1; a[1]<=9; a[1]++)
			for(a[2]=0; a[2]<=9; a[2]++)
				for(a[3]=0; a[3]<=9; a[3]++) {
					bool flag=1;
					for(int j=1; j<=m; j++)
						if(a[s[j]]!=c[j]) {
							flag=0;
							break;
						}
					if(flag) {
						printf("%d",a[1]*100+a[2]*10+a[3]);
						return 0;
					}
				}
		printf("-1");
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int x;
    cin, x;
    int rad = 0;
    REP(i, 1, 360 + 1) {
        rad += x;
        rad %= 360;
        if (rad == 0) {
            print(i);
            return 0;
        }
    }
    return 0;
}


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

int main(void)
{
    int n, d;
    cin >> n >> d;
    vector<vector<int>> x(n, vector<int>(d));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < d; j++) {
            cin >> x[i][j];
        }
    }

    int count = 0;
    for (int i = 0; i < n-1; i++) {
        for (int j = i+1; j < n; j++) {
            int distance = 0;
            for (int k = 0; k < d; k++) {
                distance += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
            }
            if (pow(floor(sqrt(distance)+0.5), 2) == distance) count++;
        }
    }
    cout << count << endl;

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ull unsigned long long
#define mp make_pair
#define F first
#define S second
#define mod 1000000007

void add_self(ll& a, ll b)
{
    a += b;
    if(a >= mod)
        a -= mod;
}

int main()
{
    int n;
    scanf("%d", &n);

    vector<vector<int> > v(n, vector<int>(n));

    for(int i=0; i<n; i++)
        for(int j=0; j<n; j++)
            scanf("%d", &v[i][j]);
    
    vector<ll> dp( 1 << n );
    dp[0] = 1;
    for(int mask = 0; mask < (1 << n) -1; mask++)
    {
        int a = __builtin_popcount(mask); 
        for(int b=0; b<n; b++)
        {
            if(v[a][b] && !( mask & (1 << b)))
            {
                int m2 = mask ^ (1 << b);
                add_self(dp[m2], dp[mask]);
            }
        }
    }

    printf("%lld\n", dp[(1<<n) - 1]);
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
const int INFINT = INT_MAX/2;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

struct Edge{
    int dst;
    int weight;
    Edge(int dst, int weight): dst(dst), weight(weight) {}
};

struct TmpDist{
    int vertex;
    int dist;
    TmpDist(int vertex, int dist): vertex(vertex), dist(dist) {}
    bool operator< (const TmpDist& right)const{
        return dist > right.dist;
    }
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

vector<int> dijkstra(Graph &G, int r){
    int V = G.size();
    vector<int> dist(V, INFINT);
    priority_queue<TmpDist> pq;
    vector<bool> check(V, false);
    TmpDist init(r, 0);
    pq.push(init);
    while(!pq.empty()){
        TmpDist td = pq.top();pq.pop();
        int now = td.vertex;
        if(!check[now]){
            check[now] = true;
            dist[now] = td.dist;
            for (int i=0;i<G[now].size();i++){
                if(dist[G[now][i].dst] > td.dist + G[now][i].weight){
                    TmpDist tdCandidate(G[now][i].dst, td.dist + G[now][i].weight);
                    pq.push(tdCandidate);
                }
            }
        }
    }
    return dist;
}

int main(){
	int K;
	cin >> K;

	Graph G(K);
	REP(i, K){
		Edge e((i+1)%K, 1);
		Edge f((10*i)%K, 0);
		G[i].push_back(e);
		G[i].push_back(f);
	}

	auto dist = dijkstra(G, 1);
	cout << dist[0]+1 << endl;
	//vprint(dist);
    return 0;
}

Measured memory_bytes: 6780
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <bitset>
using namespace std;

typedef long long LL;

LL dist, ans = (LL)1e18;
int n, m;
vector<int> S, intr;
vector<LL> D;

vector<int> ptn;

void enumpattern(int a, int i){
	if(i >= n - 1){
		ptn.push_back(a);
	}
	else{
		enumpattern(a, i + 1);
		enumpattern(a | 1 << i, i + 2);
	}
}


void calcans(){
	vector<LL> stm(n + 1, -1LL);
	LL lst0 = -1, lft0 = 0;	// last start/finish time

	vector<vector<int> > odr(m + 1, vector<int>(n));
	for(int i = 0; i < n; ++i){
		odr[0][i] = i;
	}
	
	int cnt = 0;
	for(int j = 0; j < m; ++j){
		odr[j + 1] = odr[j];
		for(int i = 0; i < n; ++i){
			if(intr[j] >> i & 1){
				++cnt;
				int a = odr[j][i], b = odr[j][i + 1];
				if(a > b || S[a] <= S[b]){
					return;
				}
				swap(odr[j + 1][i], odr[j + 1][i + 1]);
				++i;
			}
		}
	}

	for(int i = 0; i < n; ++i){
		if(stm[i] != -1LL) continue;

		stm[i] = 0;
		bool updated = true;
		while(updated){
			updated = false;

			for(int j = 0; j < m; ++j){
				for(int k = i; k < n; ++k){
					if((intr[j] >> k & 1) == 0){
						continue;
					}

					int a = odr[j][k], b = odr[j][k+1];
					if(stm[a] == -1LL && stm[b] != -1LL){
						updated = true;
						stm[a] = stm[b] + D[j] * (S[b] - S[a]);
					}
					else if(stm[a] != -1LL && stm[b] == -1LL){
						updated = true;
						stm[b] = stm[a] + D[j] * (S[a] - S[b]);
					}
				}
			}
		}

		for(int j = i; stm[j] != -1LL; ++j)
		for(int k = j + 1; stm[k] != -1LL; ++k){
			if(S[j] <= S[k]){ continue; }
			LL ip = (stm[k] - stm[j]) / (S[j] - S[k]);
			if(ip < 0 || ip >= dist){ continue; }
			if((stm[k] - stm[j]) % (S[j] - S[k]) != 0){
				return;
			}
			
			int x = find(D.begin(), D.end(), ip) - D.begin();
			if(x >= m) return;
			int y = find(odr[x].begin(), odr[x].end(), j) - odr[x].begin();
			if(y >= n - 1 || odr[x][y+1] != k ||
			  odr[x+1][y] != k || odr[x+1][y+1] != j){
				return;
			}
			--cnt;
		}
		
		int u = find(stm.begin(), stm.end(), -1LL) - stm.begin() - 1;	//[i,u]
		int farv = odr[m][i], larv = odr[m][u];	//first/last arrival
		LL lst1 = stm[u];
		LL fft1 = S[farv] * dist + stm[farv];
		LL lft1 = S[larv] * dist + stm[larv];

		for(int j = i; j < u; ++j){
			if(stm[j] >= stm[j + 1]){ return; }
		}

		LL offset;
		if(lst0 + fft1 + 1 >= lft0){	//start as early as possible
			offset = lst0 + 1;
		}
		else{
			offset = lft0 - fft1;
		}
		lst0 = offset + lst1;
		lft0 = offset + lft1;

		i = u;
	}
	if(cnt != 0) return;

	ans = min(ans, lft0);
}

void solve(int i){
	if(i == m){
		calcans();
	}
	else{
		for(int j = 0; j < ptn.size(); ++j){
			intr[i] = ptn[j];
			solve(i + 1);
		}
	}
}


int main(){
	cin >> dist >> n;
	S.resize(n);

	for(int i = 0; i < n; ++i){
		cin >> S[i];
	}
	cin >> m;
	D.resize(m);
	intr.resize(m);
	for(int i = 0; i < m; ++i){
		cin >> D[i];
	}
	sort(D.begin(), D.end());

	enumpattern(0, 0);

	solve(0);

	cout << ans << '\n';
}

Measured memory_bytes: 1228
/*
* @Author: _dp95
* @Date:   2020-04-14 11:50:42
*/
#include "bits/stdc++.h"
using namespace std ;

#define timesaver ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll ;
typedef long double ldb ;

#define mp make_pair
#define pb push_back
#define F first
#define S second
#define nl '\n'

#define all( x ) x.begin(),x.end() 
#define sz( x ) ( int )( x ).size( )
#define mem( a, val ) memset(a, val, sizeof( a ) )
#define deci( x ) cout<<fixed<<setprecision( x );
#define bitcount( x ) __builtin_popcountll( x )

const int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};

const int MAX = 2*1000*1000 + 10 ;
const ll INF = 1e18 ;
const int MOD = 1e9 + 7 ;

int BIT[MAX] ;

void update( int pos, int val ){
  while( pos and pos < MAX ){
    BIT[pos] += val ;
    pos += (pos&-pos);
  }
}

int get( int pos, int val=0 ){
  while( pos ){
    val += BIT[pos] ;
    pos -= (pos&-pos) ;
  }
  return val ;
}

vector< pair<int,int> > v ;
vector< int > ans ;

signed main( ){
  timesaver ;
  int q, n ;
  cin >> q >> n ;
  ans.resize(n);
  for( int i = 0 ; i < q ; i++ ){
    int l, r ;
    cin >> l >> r ;
    v.pb({l, r});
    update(l,1);
    update(r+1,-1);
  }
  sort(all(v),[&](const pair<int,int>&a, const pair<int,int>&b){
    return (a.S-a.F+1)>(b.S-b.F+1);
  });
  int tmp(0), i(0) ;
  while( n ){
    int tmp2(0) ;
    while( i < q ){
      int l = v[i].F, r = v[i].S ;
      int len = r-l+1 ;
      if( len >= n ){
        tmp++ ;
        i++ ;
        update(l,-1);
        update(r+1,1);
      }
      else{
        break ;
      }
    }
    for( int j = n ; j < MAX ; j += n )
      tmp2 += get(j);
    ans[n-1] = tmp+tmp2 ;
    n-- ;
  }
  for( int i : ans )
    cout << i << nl ;
}

Measured memory_bytes: 11376
using System;

namespace aoj
{
    public static class Program
    {
        static void Main()
        {
            var data1 = Console.ReadLine();
            var data2 = data1.Split(' ');
            var a = int.Parse(data2[0]);
            var b = int.Parse(data2[1]);
            Console.WriteLine(a*b + " " + (2*a+2*b));
        }
    }
}



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

int main()
{
	int N, t;
	list<int> l;
	string cmd;
	
	cin >> N;
	for(int i = 0; i < N; ++i)
	{
		cin >> cmd;
		if(cmd == "insert")
		{
			cin >> t;
			l.push_front(t);
		}
		else if(cmd == "delete")
		{
			cin >> t;
			for(list<int>::iterator j = l.begin(); j != l.end(); ++j)
			{
				if((*j) == t)
				{
					l.erase(j);
					break;
				}
			}
		}
		else if(cmd == "deleteFirst")
		{
			l.erase(l.begin());
		}
		else if(cmd == "deleteLast")
		{
			l.erase(--l.end());
		}
	}
	
	for(list<int>::iterator i = l.begin(); i != l.end(); ++i)
	{
		if(i != l.begin())
		{
			cout << " ";
		}
		cout << (*i);
	}
	cout << endl;

    return 0;
}



Measured memory_bytes: 34412
fun main(args: Array<String>) {

    val (n, m) = readLine()!!.split(" ").map { it.toInt() }

    val cardPassGateList = (1..m).map { readLine()!!.split(" ").map { it.toInt() } }

    val l = cardPassGateList.maxBy { it.first() }?.first()!!
    val r = cardPassGateList.minBy { it.last() }?.last()!!

    if(r < l){
        println(0)
        return
    }
    var ans = 0
    for(i in 1..n){
        if(i in (l..r)) ans++
    }
    println(ans)
}


Measured memory_bytes: 64980
import sys, heapq, bisect, math, fractions
from collections import deque

N, M = map(int, input().split())
AB = [list(map(int, sys.stdin.readline().rsplit())) for _ in range(M)]

AB.sort(key=lambda x: x[1])
res = 0
bridge = 0

for a, b in AB:
    if not a <= bridge: 
        res += 1
        bridge = b - 1

print(res)


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

int main() {
  string a,b;
  bool flag = false;
  cin >> a >> b;
  int c = stod(a + b);
  for(double i=1 ;i<1010 ;i++){
    if(c/i == i){
      flag = true;
    }
  }
  cout << (flag?"Yes":"No") << endl;
}

Measured memory_bytes: 256
//Love and Freedom.
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#define ll long long
#define inf 20021225
using namespace std;
int read()
{
	int s=0,t=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')	t=-1; ch=getchar();}
	while(ch>='0' && ch<='9')	s=s*10+ch-'0',ch=getchar();
	return s*t;
}
int a,b,c,d;
int main()
{
	int q=read();
	while(q--)
	{
		a=read(),b=read(),c=read(),d=read();
		int k=(max(a,b)-1)/(min(a,b)+1)+1; int l=0,r=a+b+1;
		while(l<r)
		{
			int mid=l+r>>1; int d=mid/(k+1);
			int A=d*k+mid%(k+1),B=mid-A;
			if(b-B<=1ll*(a-A)*k)	l=mid+1;
			else	r=mid;
		}
		int A=(l/(k+1))*k+l%(k+1),B=l-A; A=a-A,B=b-B; r=l+B-A*k+1;
		for(int i=c;i<=min(d,l);i++)	printf("%c",i%(k+1)?'A':'B');
		for(int i=max(l+1,c);i<=d;i++)	printf("%c",(i-r)%(k+1)?'B':'A');
		puts("");
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int N;
  scanf("%d",&N);
  int A[N];
  for(int i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  int a=1;
  int max_1=0;
  int max_2=0;
  for(int i=0;i<N;i++){
    if(A[i]==max_1)
      a++;
    else if(max_2<A[i]&&A[i]<max_1)
      max_2=A[i];
    if(A[i]>max_1){
      max_2=max_1;
      a=1;
      max_1=A[i];
    }
  }
    for(int i=0;i<N;i++){
      if(a==1){
      	if(A[i]==max_1)
        	printf("%d\n",max_2);
      	if(A[i]!=max_1)
        	printf("%d\n",max_1);
      }
      if(a>=2)
        printf("%d\n",max_1);
    }
  return 0;
}


Measured memory_bytes: 2304
/***************************************
    codeforces = topcoder = sahedsohel
    IIT,Jahangirnagar University(42)
****************************************/
#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define ull unsigned long long int
#define inf (INT_MAX/10)
#define linf (LLONG_MAX/10LL)
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define sc3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sc4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)
#define fl(c,i,n) for(i=c;i<n;i++)
#define f(i,n) for(i=0;i<n;i++)
#define mem(a) memset(a,0,sizeof(a))
#define memn(a) memset(a,-1,sizeof(a))
#define pb push_back
#define aov(a) a.begin(),a.end()
#define mpr make_pair
#define PI (2.0*acos(0.0)) //#define PI acos(-1.0)
#define xx first
#define yy second
#define mxv(a) *max_element(aov(a))
#define mnv(a) *min_element(aov(a))
#define LB(a,x) (lower_bound(aov(a),x)-a.begin())
#define UB(a,x) (upper_bound(aov(a),x)-a.begin())
#define to_c_string(a) a.c_str()
#define strtoint(c) atoi(&c[0])
#define pll pair< ll , ll >
#define pii pair< int , int >
#define pcs(a) printf("Case %d: ", a)
#define nl puts("")
#define endl '\n'
#define dbg(x) cout<<#x<<" : "<<x<<endl

template <class T> inline T bigmod(T p,T e,T M){ll ret = 1;for(; e > 0; e >>= 1){if(e & 1) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}   // M is prime}
template <class T> inline T bpow(T p,T e){ll ret = 1;for(; e > 0; e >>= 1){if(e & 1) ret = (ret * p);p = (p * p);}return (T)ret;}

int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
int toLlint(string s){long long int sm;stringstream ss(s);ss>>sm;return sm;}


///int mnth[]={-1,31,28,31,30,31,30,31,31,30,31,30,31};  //Not Leap Year
///int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
///int dx[]={-1,+1,0,1,0,-1}; // Hexagonal Direction   **
///int dy[]={-1,+1,1,0,-1,0}; //                       *#*
///                                                     **
///const double eps=1e-9;
///int dx[]={0,1,0,-1};int dy[]={1,0,-1,0}; //4 Direction

/*****************************************************************/
/// ////////////////////   GET SET GO    ////////////////////// ///
/*****************************************************************/


#define intx(i,j,k,l) ((a[i]*b[j]-b[i]*a[j])*(a[k]-a[l])-(a[i]-a[j])*(a[k]*b[l]-b[k]*a[l]))/((a[i]-a[j])*(b[k]-b[l])-(b[i]-b[j])*(a[k]-a[l]))
#define inty(i,j,k,l) ((a[i]*b[j]-b[i]*a[j])*(b[k]-b[l])-(b[i]-b[j])*(a[k]*b[l]-b[k]*a[l]))/((a[i]-a[j])*(b[k]-b[l])-(b[i]-b[j])*(a[k]-a[l]))
#define dst(u,v,x,y) sqrt((x*1.0-u*1.0)*(x*1.0-u*1.0)+(y*1.0-v*1.0)*(y*1.0-v*1.0))
#define area(p1,p2,p3) (p1.xx*p2.yy+p2.xx*p3.yy+p3.xx*p1.yy-p1.yy*p2.xx-p2.yy*p3.xx-p3.yy*p1.xx)

int ts,kk=1;

#define M 1000006
#define MD 99991LL
#define MX 33330

int n,a[205],rs=0;

int main()
{
    int t,i,j,k;

    sc(n);
    f(i,n+n)sc(a[i]);
    sort(a,a+n+n);

    f(i,n+n)
    {
        rs+=a[i];
        i++;
    }
    printf("%d\n",rs);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int MAX = 10000000;
vector<int> sosuu(MAX,1);
vector<int> sosuuMap;
vector<int> sosuuSum;
int n,m;
void makeSosuu(){
  sosuu[1] = 0;
  for(int i = 2;i <= MAX;i++){
    if(sosuu[i] == 1){
      sosuuMap.push_back(i);
      for(int j = i + i;j <= MAX;j = j + i){
	sosuu[j] = 0;
      }
    }
  }
  
}
void makeSumSosuu(){
  sosuuSum = vector<int>();
  int keep;
  for(int i = 0;i <= MAX;i++){
    if(sosuuMap[i] > n){
      keep = i;
      break;
    }
  }
  for(int i = keep;i <= keep+100;i++){
    for(int j = i;j <= keep+100;j++){
     	sosuuSum.push_back(sosuuMap[i]+sosuuMap[j]);
    }
    
    sort(sosuuSum.begin(),sosuuSum.end());
  }
}
int main(){

  makeSosuu();

  while(1){
    cin >> n >> m;
    if(n == -1 && m == -1)break;
    makeSumSosuu();
    cout << sosuuSum[m-1] << endl;
  }
}

Measured memory_bytes: 44388
#include<bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int a,b,c;
    Scd(a);

    printf ( a == 7 || a == 5 || a == 3 ? "YES\n" : "NO\n");

    return 0;
}



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

// code
bool isprime(int x){
    // 2は素数
    if(x == 2){
        return true;
    }

    // 0, 1，偶数は素数じゃない
    if (x < 2 || x%2 == 0){
        return false;
    }

    // 判定
    int i = 3;
    while (i <= sqrt(x)){
        if(x%i == 0){
            return false;
        }
        i += 2;
    }

    return true;
}

// main function
int main(){
    // input
    int n;
    cin >> n;
    vector<int> v(n, 0);
    REP(i, n){
        scanf("%d", &v[i]);
        }
    int count = 0;
    REP(i, n){
        if(isprime(v[i])==true){
            ++count;
            }
    }

    cout << count << "\n";
}


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

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

const int max_v = 1e+5;
vector<bool> visited(2*max_v+1, false);

void dfs(int pos, vector<long long>& num_v, vector<vector<int>>& G){
    if(visited[pos]) return;
    visited[pos] = true;
    ++num_v[(pos-1)/max_v];
    for(int v: G[pos]) dfs(v, num_v, G);
}

int main()
{
    int N;
    cin >> N;
    vector<vector<int>> G(2*max_v+1);  // y は +max_v して頂点にする
    REP(i, N){
        int x, y;
        cin >> x >> y;
        y += max_v;
        G[x].push_back(y);
        G[y].push_back(x);
    }

    long long ans = 0;
    // 答えはグラフを連結成分ごとに完全二部グラフにするのに必要な本数の和
    // つまり、連結成分ごとの x, y の頂点数が必要
    REP(i, 2*max_v+1){
        vector<long long> num_v(2);
        dfs(i, num_v, G);
        ans += num_v[0]*num_v[1];
    }
    cout << ans-N << endl;
    
    return 0;
}

Measured memory_bytes: 11008
#include <bits/stdc++.h>
using namespace std;
int main(){
  int H,N; cin>>H>>N;
  vector<int> A(N);
  for (int i=0; i<N; i++) cin>>A[i]; 
  int sum=0;
  for (int i=0; i<N; i++){
    sum += A[i];
  }
    cout << (sum>=H?"Yes":"No") << endl;
}

Measured memory_bytes: 640
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

N = ii()
A = li()
max_num = 10**5+1
num_list = [0] * (max_num)

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

for num in A:
    num_list[num] += 1

if num_list[0] > 1:
    print(0)
    exit()

ans = 1
for i in range(2, max_num):
    if num_list[i] != 0:
        ans *= pow(num_list[i-1], num_list[i], 998244353)

else:
    print(ans%998244353)

Measured memory_bytes: 13884
import java.util.Scanner;

public class Main 
{
	static int n;
	static int[] tar;
	static int[] a;
	static int an = 999999999;
	
	static int go(int cs)
	{
		int cur = 0;
		int[] init = new int[4];
		for(int i = 0; i < n; i++)
		{ //find out where each bamboo belongs
			int d0 = (mask[i*2+1] & cs)>0?1:0;
			int d1 = (mask[i*2] & cs)>0?1:0;
			int bel = d0*2+d1;
			if(init[bel] > 0 && bel < 3)cur += 10; //pay to merge
			init[bel] += a[i];
		}
		
		for(int i = 0; i < 3; i++)
		{ //make this bamboo
			if(init[i] == 0)return 99999999;
			int mk = tar[i] - init[i];
			if(mk < 0)mk*=-1;
			cur += mk;
		}
		return cur;
		
	}

	static int[] mask = new int[16];
	
	public static void main(String[] args) 
	{
		int curm = 1;
		for(int i = 0; i < 16; i++)
		{
			mask[i] = curm;
			curm*=2;
		}
		
		tar = new int[3];
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		a = new int[n];
		for(int i = 0; i < 3; i++)
			tar[i] = sc.nextInt();
		
		for(int i = 0; i < n; i++)
		{
			a[i] = sc.nextInt();
		}
		
		int cases = 1;
		for(int i = 0; i < n; i++)
		{
			cases *= 4;
		}
		
		for(int i = 0; i < cases; i++)
		{
			an = Math.min(an, go(i));
		}
		System.out.println(an);
	}

}


Measured memory_bytes: 25428
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final int c = scanner.nextInt();

        final long[][] colorTable = new long[c][c];
        for (int i = 0; i < c; i++) {
            for (int j = 0; j < c; j++) {
                colorTable[i][j] = scanner.nextLong();
            }
        }

        final long[][] modTable = new long[3][c];

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                final int tmp = scanner.nextInt() - 1;
                modTable[(i + j) % 3][tmp]++;
            }
        }

        long answer = Long.MAX_VALUE;
        for (int i = 0; i < c; i++) {
            for (int j = 0; j < c; j++) {
                if (i == j) {
                    continue;
                }
                for (int k = 0; k < c; k++) {
                    if (i == k || j == k) {
                        continue;
                    }

                    int tmp = 0;
                    for (int l = 0; l < c; l++) {
                        tmp += modTable[0][l] * colorTable[l][i];
                        tmp += modTable[1][l] * colorTable[l][j];
                        tmp += modTable[2][l] * colorTable[l][k];
                    }
                    answer = Math.min(answer, tmp);
                }
            }
        }

        System.out.println(answer);
    }
}


Measured memory_bytes: 80432
line = []
for i in range(5):
    line.append(int(input()))
line10 = list(map(lambda x: x % 10, line))
pittari = []
for i in range(5):
    if line10[i] == 0:
        pittari.append(i)
if len(pittari) == 5:
    print(sum(line))
else:
    imy = []
    for i in range(5):
        if not(i in pittari):
            imy.append(i)
    imylist = []
    for i in imy:
        imylist.append(line10[i])
    last = line10.index(min(imylist))
    sum = 0
    for i in range(5):
        if i != last and not(i in pittari):
            line[i] = line[i] - line10[i] + 10
            sum += line[i]
    for i in pittari:
        sum += line[i]
    print(line[last] +  sum)

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

using namespace std;

typedef long long int64;

int main()
{
  int64 H, W;
  cin >> H >> W;

  int64 ret = 1LL << 58;

  ret = min(ret, (H + 2) / 3 * W - H / 3 * W);
  ret = min(ret, (W + 2) / 3 * H - W / 3 * H);
  for(int i = 1; i < H; i++) {
    int64 zan = H - i;
    int64 ss = i * W;
    int64 aa = W / 2 * zan;
    int64 bb = (W + 1) / 2 * zan;
    ret = min(ret, max({ss, aa, bb}) - min({ss, aa, bb}));
  }
  for(int i = 1; i < W; i++) {
    int64 zan = W - i;
    int64 ss = i * H;
    int64 aa = H / 2 * zan;
    int64 bb = (H + 1) / 2 * zan;
    ret = min(ret, max({ss, aa, bb}) - min({ss, aa, bb}));
  }
  cout << ret << endl;
}

Measured memory_bytes: 256
def main():
    N, K = map(int, input().split())
    V = list(map(int, input().split()))
    ans = 0

    for left in range(K+1):
        for right in range(K+1):
            if left + right > K:
                continue
            tmp = []
            for i in range(min(N, left)):
                tmp.append(V[i])

            for j in range(max(left,N-right),N,1):
                tmp.append(V[j])

            nokori = K - left - right
            tmp.sort()
            tmp_sum = sum(tmp)
            for k in range(min(nokori, len(tmp))):
                if tmp[k] < 0:
                    tmp_sum -= tmp[k]

            ans = max(ans, tmp_sum)

    print(ans)





if __name__ == "__main__":
    main()

Measured memory_bytes: 43740
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 5;
const int INF = 0x3f3f3f3f;
const ll p = 998244353;
#define DEBUG(x) cout << x << '\n'


void run(){
    int x, y, a, b;
    cin >> x >> y;
    int f = 2 * x <= y;
    f &= (y - x - x) % 2 == 0;
    f &= (y - x - x) / 2 <= x;
    cout << (f ? "Yes" : "No");
}
int main(){
#ifdef Irene
    freopen("in.txt", "r", stdin);
#endif // Irene
    ios::sync_with_stdio(false);

    run();
}


Measured memory_bytes: 3648
#include<stdio.h>
 
int main(void)
{
  long A,B,C,axb,axc,bxc;
  scanf("%ld %ld %ld",&A,&B,&C);
  axb = A * B;
  axc = A * C;
  bxc = B * C;
  if (2 <= A && A <= 1000000000 && 2 <= B && B <= 1000000000 && 2 <= C && C <= 1000000000) {
  if (A % 2 == 0 || B % 2 == 0 || C % 2 == 0) {
    printf("0\n");
  } else {
    if (axb <= axc && axb <=  bxc) {
      printf("%ld\n",axb);
    } else if (axc < axb && axc <= bxc) {
      printf("%ld\n",axc);
    } else {
      printf("%ld\n",bxc);
    }
  }
  }
  return 0;
}

Measured memory_bytes: 128
n,d = gets.split.map(&:to_f)
x=[]
for i in 0..n-1
  x[i]=gets.split.map(&:to_f)
end

cnt=0
for i in 0..n-1
  for j in i+1..n-1
    cntd=0
    for k in 0..d-1
      cntd += (x[i][k] - x[j][k])**2
    end
    cntd = cntd**(1/2.0)
    cnt += 1 if (cntd % 1) == 0
  end
end
puts cnt


Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,nn) for(int i=0;i<nn;i++)
#define MOD 1000000007
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}


int main(){
  int n;
  cin >> n;
  int l;
  cin >> l;
  int a[1000];
    int sum=0;
  FOR(i,n){
    a[i]=l+i;
    sum+=a[i];
  }
  int mini=100000,ans;
  FOR(i,n){
    if(mini>abs(a[i]-0)){
      mini=abs(a[i]-0);
      ans=i;
    }
  }
  cout << sum-a[ans] << endl;

  
}

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

typedef long long LL;
const int Mod = 998244353, Inv2 = (Mod + 1) / 2;
const int MN = 1000005;

inline int qPow(int b, int e) {
	int a = 1;
	for (; e; e >>= 1, b = (LL)b * b % Mod)
		if (e & 1) a = (LL)a * b % Mod;
	return a;
}
inline int gInv(int b) { return qPow(b, Mod - 2); }

int Fac[MN], iFac[MN];
inline void Init(int N) {
	Fac[0] = 1;
	for (int i = 1; i <= N; ++i) Fac[i] = (LL)Fac[i - 1] * i % Mod;
	iFac[N] = gInv(Fac[N]);
	for (int i = N; i >= 1; --i) iFac[i - 1] = (LL)iFac[i] * i % Mod;
}
inline int Binom(int N, int M) {
	if (M < 0 || M > N) return 0;
	return (LL)Fac[N] * iFac[M] % Mod * iFac[N - M] % Mod;
}
inline int Calc(int N, int M) {
	return Binom(N + M, N);
}

int N, M;

int main() {
	scanf("%d%d", &N, &M);
	if (N < M) std::swap(N, M);
	Init(N + M);
	int Ans = 0;
	for (int i = 1; i <= M; ++i) Ans = (Ans + (LL)Calc(i, i) * Calc(N - i, M - i)) % Mod;
	Ans = (LL)Ans * gInv(Calc(N, M)) % Mod;
	printf("%lld\n", (N + (LL)Ans * Inv2) % Mod);
	return 0;
}

Measured memory_bytes: 9544
from itertools import *

while True:
    n, x = map(int, input().split())
    if n == x == 0:
        break
    else:
        l = list(combinations(list(range(1, n + 1)), 3))
        count = [1 for s in l if sum(s) == x]
        print(f"{len(count)}")


Measured memory_bytes: 31308
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
typedef struct pair<ll,int> P;

int main() {
	int a,b;
	cin>>a>>b;
	if(a==1)a+=13;
	if(b==1)b+=13;;
	if(a>b){
		cout<<"Alice"<<endl;
	}else if(b>a){
		cout<<"Bob"<<endl;
	}else{
		cout<<"Draw"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


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

	vector<ll> a(5);
	for (ll i = 0; i < n; i++)
	{
		string s;
		cin >> s;

		switch (s[0])
		{
			case 'M':
				a[0]++;
				break;
			case 'A':
				a[1]++;
				break;
			case 'R':
				a[2]++;
				break;
			case 'C':
				a[3]++;
				break;
			case 'H':
				a[4]++;
				break;
		}
	}

	ull res = 0;
	for (int i = 0; i < 5; i++)
	{
		for (int j = i + 1; j < 5; j++)
		{
			for (int k = j + 1; k < 5; k++)
			{
				res += (a[i] * a[j] * a[k]);
			}
		}
	}

	println(res);
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int n, t, i, j;
  double max = 0;
  scanf("%d%d", &n, &t);
  for(i = 0; i < n; ++i) {
    int x, h;
    scanf("%d%d", &x, &h);
    if(max < (double)h / (double)x) max = (double)h / (double)x;
  }
  printf("%f\n", max * t);
  return 0;
}


Measured memory_bytes: 2672
#include<stdio.h>
int main(void){
int a,b,c,i,j=0;
scanf("%d %d %d",&a,&b,&c);
if(1<=a&&b<=10000&&1<=c&c<=10000&&a<=b){
for(i=a;i<=b;i++){
if(c%i==0)
j++;
}}
printf("%d\n",j);
return 0;
}

Measured memory_bytes: 596