akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define REP(i, a, b) for (auto i = (a); i < (b); i++)
#define REPR(i, a, b) for (auto i = (a-1); i >= (b); i--)

using namespace std;

void solve()
{
    long long int result = INT64_MIN;

    vector<long long int> v(4);
    REP(i, 0, 4)
        cin >> v[i];

    REP(i, 0, 2)
        REP(j, 2, 4)
            result = max(result, v[i] * v[j]);

    cout << result << "\n";
}

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

    int t = 1; // cin >> t;

    while (t--)
        solve();

    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define PI 3.141592653589793238;
using namespace std;

int main()
{
    long long N,M;
    cin>>N>>M;
    long long arr[M];
    for(int i=0;i<M;i++)
    {
        cin>>arr[i];
        N-=arr[i];
    }
    if(N<0)
    {
        cout<<"-1\n";
    }
    else
        cout<<N<<endl;


}


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

int main() {
    int H, W;
    cin >> H >> W;
    char A[H][W];
    for (int i=0; i<H; i++){
        for (int j=0; j<W; j++){
            cin >> A[i][j];
        }
    }
    vector <bool> row(H, false);
    vector <bool> col(W, false);
    for (int i=0; i<H; i++){
        for (int j=0; j<W; j++){
            if (A[i][j]=='#'){
                row[i]=true;
                col[j]=true;
            }
        }
    }
    for (int i=0; i<H; i++){
        if (row[i]){
            for (int j=0; j<W; j++){
                if (col[j]){
                    cout << A[i][j];
                }
            }
            cout << endl;
        }
    }
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
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;}
int const INF = 1001001001;


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

int W,H,N;
cin >> W >> H >> N;
vi L = {0}, R = {W}, D = {0}, U = {H};
rep(i,N) {
    int x,y,a;
    cin >> x >> y >> a;
    if(a == 1) L.push_back(x);
    if(a == 2) R.push_back(x);
    if(a == 3) D.push_back(y);
    if(a == 4) U.push_back(y);
}
int w = max(0,*min_element(all(R))-*max_element(all(L)));
int h = max(0,*min_element(all(U))-*max_element(all(D)));
cout << w * h << endl;
return 0;
}

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  string n; cin>>n;
  rep(i,3){
    if(n[i]=='7'){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
}

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

int main() {
  int n;
  cin >> n;
  map<char, int> mtoi;
  mtoi.insert(make_pair('S', 0));
  mtoi.insert(make_pair('H', 1));
  mtoi.insert(make_pair('C', 2));
  mtoi.insert(make_pair('D', 3));
  char itom[] = {'S', 'H', 'C', 'D'};
  vector<vector<int> > num(4, vector<int>(13, 0));

  for (int i = 0; i < n; ++i) {
    char c;
    int x;
    cin >> c >> x;
    num.at(mtoi.at(c)).at(x - 1) = 1;
  }
  for (int i = 0; i < 4; ++i) {
    for (int j = 0; j < 13; ++j) {
      if (num.at(i).at(j) == 0) cout << itom[i] << " " << j + 1 << endl;
    }
  }

  return 0;
}


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

#define INF INT_MAX/2
#define MOD 1000000007

using namespace std;

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

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

   int N;
   string S;
   cin>>N>>S;

   vector<ll>sum_w(N,0),sum_e(N,0);
   for(int i=0;i<N;i++){
      if(S[i]=='W')sum_w[i]=1;
      else if(S[i]=='E')sum_e[i]=1;
   }
   for(int i=1;i<N;i++){
      sum_w[i] += sum_w[i-1];
      sum_e[i] += sum_e[i-1];
   }

   ll ans = 10000000;
   for(int i=0;i<N;i++){
      if(i==0)ans=min(sum_e[N-1]-sum_e[1],ans);
      else if(i==N-1)ans=min(sum_w[N-2],ans);
      else ans=min(sum_w[i-1]+sum_e[N-1]-sum_e[i],ans);
   }
   cout<<ans<<endl;
   return 0; 
}


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

int main(){
    map<string,int> x;
    vector<string> q;
    string s;
    int n,ma=-1;
    cin>>n;
    for(int i=0;i<n;i++)cin>>s,x[s]++;
    for(auto z:x) ma=max(ma,z.second);
    for(auto z:x) if(z.second==ma)q.push_back(z.first);
    sort(begin(q),end(q));
    for(auto z:q) cout<<z<<"\n";
}


Measured memory_bytes: 26868
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main()
{
    string S;
    cin >> S;
    string ans = "Yes";
    if(S.length() % 2 == 0)
    {
        for(int i = 0;i < S.length();i+=2)
        {
            if(S[i]=='h' && S[i+1]=='i')
            {
            }
            else
            {
                ans = "No";
            }
        }
    }
    else
    {
        ans = "No";
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 760
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
using namespace std;
int main() {
	int a, b, c, k;
	cin >> a >> b>>c>>k;
	if (k <= a) cout << k << endl;
	else if (k <= a + b) cout << a << endl;
	else cout << a - (k - a - b) << endl;
	return 0;
}

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int x, y;
	cin >> x >> y;

	int turu = 0, kame = 0;

	while (turu <= x)
	{
		kame = x - turu;
		if (turu * 2 + kame * 4 == y) {
			cout << "Yes" << endl;
			return 0;
		}
		turu++;
	}
	cout << "No" << endl;
}


Measured memory_bytes: 3632
#include <stdio.h>

int main (void){
	long long int n, m;
	scanf("%lld %lld", &n, &m);
	if(m >= n*2){
		if(m >= 2){
			printf("%lld\n",n+(m-(n*2))/4);
		}
		else printf("0\n");
	}

	else{
		printf("%lld\n", m/2);
	}


	return 0;
}

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

int main(){
  long long N,M; cin >> N >> M;
  if(N == 1 && M == 1)
    cout << 1 << endl;
  if(N == 1 && M > 2){
    cout << M-2 << endl;
  }
  if(M == 1 && N > 2){
    cout << N-2 << endl;
  }
  if(N == 2 || M == 2)
    cout << 0 << endl;
  if(N >= 3 && M >=3){
    cout << (M-2)*(N-2) << endl;
  }
}
  


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;
int main()
{
	while(true){
		int N,M;
		int PP,QQ,RR;
		int X[5000];
		int Y[5000];
		vector<P>now;
		scanf("%d",&N);
		now.push_back(P(1,N));
		if(N==0)break;
		scanf("%d%d%d%d",&M,&PP,&QQ,&RR);
		for(int i=0;i<M;i++){
			scanf("%d%d",&X[i],&Y[i]);
		}
		for(int i=0;i<M;i++){
			int XX,YY;
			int cou=0;
			for(int j=0;j<now.size();j++){
				int cou1=cou+now[j].second;
				if(cou<=X[i]&&cou1>X[i])XX=j;
				if(cou<=Y[i]&&cou1>Y[i])YY=j;
				cou=cou1;
			}
			vector<P>now11,now12,now13;
			int cou2=0;
			if(XX!=YY){
				for(int j=0;j<XX;j++){
					now11.push_back(now[j]);
					cou2+=now[j].second;
				}
				if(X[i]!=cou2)now11.push_back(P(now[XX].first,X[i]-cou2));
				if(X[i]!=cou2+now[XX].second)now12.push_back(P(now[XX].first+(X[i]-cou2),cou2+now[XX].second-X[i]));
				cou2+=now[XX].second;
				for(int j=XX+1;j<YY;j++){
					now12.push_back(now[j]);
					cou2+=now[j].second;
				}
				if(Y[i]!=cou2)now12.push_back(P(now[YY].first,Y[i]-cou2));
				if(Y[i]!=cou2+now[YY].second)now13.push_back(P(now[YY].first+(Y[i]-cou2),cou2+now[YY].second-Y[i]));
				cou2+=now[YY].second;
				for(int j=YY+1;j<now.size();j++){
					now13.push_back(now[j]);
					cou2+=now[j].second;
				}
			}
			else{
				for(int j=0;j<XX;j++){
					now11.push_back(now[j]);
					cou2+=now[j].second;
				}
				if(X[i]!=cou2)now11.push_back(P(now[XX].first,X[i]-cou2));
				now12.push_back(P(now[XX].first+(X[i]-cou2),Y[i]-X[i]));
				if(Y[i]!=cou2+now[XX].second)now13.push_back(P(now[YY].first+(Y[i]-cou2),cou2+now[YY].second-Y[i]));
				cou2+=now[YY].second;
				for(int j=YY+1;j<now.size();j++){
					now13.push_back(now[j]);
					cou2+=now[j].second;
				}
			}
			now.clear();
			for(int i=0;i<now13.size();i++){
				now.push_back(now13[i]);
			}
			for(int i=0;i<now12.size();i++){
				now.push_back(now12[i]);
			}
			for(int i=0;i<now11.size();i++){
				now.push_back(now11[i]);
			}
		}
		//printf("%d\n",now.size());
		int ans=0;
		int cou11=1;
		for(int i=0;i<now.size();i++){
			if(PP<=cou11&&cou11+now[i].second<=QQ){
				ans+=min(now[i].second,max(0,RR-now[i].first+1));
			}
			else if(cou11+now[i].second<=QQ&&cou11+now[i].second>=PP){
				ans+=min(now[i].second-(PP-cou11),max(0,RR-now[i].first-(PP-cou11)+1));
			}
			else if(PP<=cou11&&QQ>=cou11){
				ans+=min(QQ-cou11+1,max(0,RR-now[i].first+1));
			}
			cou11+=now[i].second;
		}
		printf("%d\n",ans);
	}
}

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

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; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

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

    // input
    ll N, M;
    cin >> N >> M;

    vector<vector<ll> > A(M);
    FOR(i, 0, M){
        ll k; cin >> k;

        FOR(j, 0, k){
            ll s; cin >> s;
            s--;
            A[i].push_back(s);
        }
    }

    vector<ll> P(M);
    FOR(i, 0, M){
        cin >> P[i];
    }

    ll ans = 0;
    // スイッチの総当たり
    FOR(sw, 0, 1<<N){
        ll on = 0;
        
        // 各電球をチェック
        FOR(i, 0, M){
            ll count = 0;
            for(ll s : A[i]){
                if(sw>>s&1) count++;
            }
            if(count%2==P[i]){
                on++;
            }
        }

        if(on==M) ans++;
    }
    
    p(ans);
    
    return 0;
}

Measured memory_bytes: 256
N = int(input())
 
div_counts = []
for i in range(2, int(N**0.5)+1):
    count = 0
    while N%i == 0:
        count += 1
        N //= i
        if N == 1: break
    div_counts.append(count)
 
if N != 1: div_counts.append(1)
 
ans = 0
for count in div_counts:
    for i in range(1, count+1):
        if count >= i:
            ans += 1
            count -= i
print(ans)

Measured memory_bytes: 17200
#include <stdio.h>

int solve(int, int);

int A[100], n;

int main(){
  int q, m[200];
  int i;

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    scanf("%d", &A[i]);
  }

  scanf("%d", &q);

  for(i = 0; i < q; i++){
    scanf("%d", &m[i]);
  }

  for(i = 0; i < q; i++){
    if(solve(0, m[i]) == 1) printf("yes\n");
    else printf("no\n");
  }

  
  return 0;
}


int solve(int i, int m){
  int res;
  
  if(m == 0) return 1;

  if(i >= n) return 0;

  if(solve(i + 1, m) || solve(i + 1, m - A[i])) return 1;

  else return 0;
}



Measured memory_bytes: 2108
#include<iostream>
#include<vector>
#include<utility>
#include<queue>
#include<string>
#include<cmath>
#include<tuple>
#include <algorithm>
#define INF 1111111111
using namespace std;
typedef pair<int,int> P;
typedef tuple<int,int,int> tup;
typedef long long ll;
vector<int> vec(100100);
vector<int> passed(100100);
vector<int> dx = {-1,1};
int n,k;

int main() {
  cin >> n ;
  int  a[100100]={0};
  int  b[100100]={0};
  for(int i=0;i<n;i++){
    cin >> k;
    if(i%2==0)
    a[k]++;
    else
    b[k]++;
  }
  int amax = 0,bmax = 0,amaxsec=0,bmaxsec=0;
  int numa=0,numb=0;
  for(int i=0;i<100100;i++){
   if(a[i]>=amax){
     amaxsec = amax;
     amax = a[i];
     numa = i;
   }
   else if(a[i]>amaxsec)
     amaxsec = a[i];
   if(b[i]>=bmax){
     bmaxsec = bmax;
     bmax = b[i];
     numb = i;
   }
   else if(b[i]>bmaxsec)
     bmaxsec = b[i];
  }
  
  if(numa == numb)
  	cout << (n-bmax-amaxsec <= n-bmaxsec-amax ? (n-bmax-amaxsec) : (n-bmaxsec-amax)) << endl;
  else if(numa != numb)
  	cout << (n-amax-bmax) << endl;
}

Measured memory_bytes: 1792
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    x, t = map(int, readline().split())

    print(max(0, x - t))


if __name__ == '__main__':
    main()


Measured memory_bytes: 61840
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

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

    int n, m, T; cin >> n >> m >> T;
    vi a(n); for(auto& e : a) cin >> e;

    int cur = 0;
    int res = 0;
    for(auto t : a){
        if(cur + m <= t){
            res += (t - (cur + m));
        }
        cur = t + m;
    }
    res += max(0, T - cur);

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3176
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
#include <stack>
#include <iomanip>
#include <limits>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};


template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
using Graph =vector<vector<int>>;
//A 65
//a 97


int main(){
  ll n,k;cin>>n>>k;
  if(n>k){
    n=n%k;
  }
  ll min=n;
  ll past=0;
  ll now=n;
  for(int i=0;i<10000000;i++){
    past=now;
    now=abs(past-k);
    if(now<min){
      min=now;
    }
  }
  cout<<min<<endl;
}

Measured memory_bytes: 888
$\="\n";
use List::Util qw( min max );
($k,$n)=glob<>;
@a=glob<>;
$d[$_]=$a[$_+1]-$a[$_]for(0..$n-2);
$d[$n-1]=$a[0]+$k-$a[$n-1];
print$k- max @d;

Measured memory_bytes: 52788
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

a,b=map(int,input().split())
if a<10 and b<10:
  print(a*b)
else:
  print(-1)

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

using namespace std;

int main()
{
	string S;
	cin >> S;;

	char str[5] = { 'A' , 'B' };

	auto a = S.find("A");
	auto b = S.find("B");
	if ( a == string::npos || b == string::npos ) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll;
typedef vector<vector<long long> > vvll;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i,n) _rep2((i),0,(n))
#define _rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define fi first
#define se second
#define mkp make_pair
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	int n;
	cin>>n;
	ll W;
	cin>>W;
	vector<pll> v(n);
	rep(i,n){
		cin>>v[i].fi>>v[i].se;
	}
	ll base = v[0].fi;
	rep(i,n){
		v[i].fi -= base;
	}
	ll ans = 0;
	rep(ii,1,n+1){
		ll ww = min(W - base*ii,300LL);
		if(ww < 0) break;
		vvll dp;
		initvv(dp,ii+1,ww+1);
		dp[0][0] = 0;
		rep(i,n){
			for(int j=ww; j>=0; j--){
				for(int k=ii-1; k>=0; k--){
					if(j-v[i].fi>=0){
						maxs(dp[k+1][j], dp[k][j-v[i].fi]+v[i].se);
					}
				}
			}
		}
		rep(i,ii+1) rep(j,ww+1){
			maxs(ans, dp[i][j]);
		}
	}
	cout<<ans<<endl;
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

Measured memory_bytes: 536
import sys
input = sys.stdin.readline

N = int(input())
E = [[] for _ in range(N)]
for _ in range(N-1):
  a, b, c = list(map(int, input().split()))
  E[a-1].append((b-1,c))
  E[b-1].append((a-1,c))

Q, K = list(map(int, input().split()))

queue = [K-1]
dist = [None]*N
dist[K-1] = 0
while queue:
  queue_new = []
  for q in queue:
    for e in E[q]:
      if dist[e[0]] is not None: continue
      dist[e[0]] = dist[q] + e[1]
      queue_new.append(e[0])
  queue = queue_new

for _ in range(Q):
  x, y = list(map(int, input().split()))
  print(dist[x-1]+dist[y-1])

Measured memory_bytes: 48716
// Problem : C - Step
// Contest : AtCoder - AtCoder Beginner Contest 176
// URL : https://atcoder.jp/contests/abc176/tasks/abc176_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

const int N=200001;
double pi=acos(-1.0);
int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};

template<class T>
T abst(T a)
{return a<0?-a:a;}

void solve()
{
	int ans=0;
	int n;cin>>n;
	vi v(n);cin>>v;
	int curr_max=v[0];
	for(int i:v)
	{
		ans+=max(0LL,curr_max-i);
		curr_max=max(curr_max,i);
	}
	cout<<ans;
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
    solve();
}
return 0;
}


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

int main() {
    int n;
    cin >> n ;
    ll total = 0;
    rep2(i,1,n+1) {
        if(i % 3 == 0 && i % 5 == 0) {
        }
        else if (i % 3 == 0) {

        }
        else if(i % 5 == 0){

        }
        else total+= i;

    }
    cout << total;

    
}

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

#define clean(x,y) memset(x,y,sizeof(x));
#define pb push_back
#define F first
#define S second
#define LB lower_bound
#define UB upper_bound
#define ALL(v) v.begin(),v.end()
#define PI acos(-1.0)
#define EPS 1e-9
#define INF (1 << 30)
#define MOD 1000000007
#define MAX 100005
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define dbg(x) cout<<(#x)<<"="<<(x)<<":\n"
#define CS(i) cout<<"Case "<<i<<": "
#define tin ll T; cin>>T; while(T--)

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;


int main()
{
    //FAST

    ll l,x;
    double ans;

    cin>>l;
    ans=l/3.00;
    ans=(ans*ans*ans);
    printf("%.12f\n",ans);




    return 0;
}




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

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, a, ct=0;
	cin>>n;
	for (int i=0; i<n; i++) {
		cin>>a;
		if (i%2==0 and a%2==1) ct++;
	}
	cout<<ct<<'\n';
}


Measured memory_bytes: 3656
S_prime = input()
T = input()

def judge(A,B):
    for i in range(len(A)):
        if A[i] != B[i] and A[i] != "?" and B[i] != "?":
            return False
    return True

def dec(S_prime,T):
    S_cand = []
    for i in range(len(S_prime)-len(T)+1):
        if judge(S_prime[i:i+len(T)],T):
            S_cand.append( S_prime[:i] + T + S_prime[i+len(T):] )
    return S_cand

def S_change(S):
    S = list(S)
    for i in range(len(S)):
        if S[i] == "?":
            S[i] = "a"
    S = "".join(S)
    return S

if len(dec(S_prime,T)) == 0:
    print("UNRESTORABLE")
else:
    Ans = dec(S_prime,T)
    for i in range(len(Ans)):
        Ans[i] = S_change(Ans[i])
    Ans.sort()
    print(Ans[0])


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

int main () {
    int N, M;
    cin >> N >> M;
    vector<vector<int> > card(M + 1, vector<int>(N * 2));
    for (int i = 0; i < N * 2; i++) card[0][i] = i + 1;

    for (int t = 0; t < M; t++) {
        int q; cin >> q;
        if (q == 0) {
            for (int i = 0; i < N; i++) {
                card[t+1][i*2] = card[t][i];
                card[t+1][i*2+1] = card[t][i+N];
            }
        } else {
            for (int i = 0; i < q; i++) card[t+1][i+2*N-q] = card[t][i];
            for (int i = 0; i < 2*N-q; i++) card[t+1][i] = card[t][i+q];
        }
    }

    for (auto c : card[M]) cout << c << endl;

    return 0;
}

Measured memory_bytes: 3536
#include <iostream>

using namespace std;

int main() {
	long long int x, a, b;
	cin >> x >> a >> b;
	if (a >= b) {
		cout << "delicious" << endl;
	}
	else if (b - a <= x) {
		cout << "safe" << endl;
	}
	else {
		cout << "dangerous" << endl;
	}
	return 0;
}

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

using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr ll mod = static_cast<ll>(1e9 + 7);

long double h, w;
long double x, y;
int main() {
	std::cin >> w >> h >> x >> y;

	auto s = w * h;
	auto ww = static_cast<ll>(w), hh = static_cast<ll>(h);

	std::cout << std::fixed << std::setprecision(10) << s / 2;

	if (ww % 2 == 0 && x == w / 2 && hh % 2 == 0 && y == h / 2)
		std::cout << " " << 1 << std::endl;
	else
		std::cout << " " << 0 << std::endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <tuple>
#include <sstream>
#include <typeinfo>
#include <fstream>
#include <random>
#include <queue>
#include <deque>
#include <iterator>
#include <map>
#include <functional>
#include <numeric>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define pb(a) push_back(a)
#define llong long long
#define INF 1145141919
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
int dy[] = { 1, 0, -1, 0 };
int dx[] = { 0, 1, 0, -1 };
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

int n;
int e[100100] = { };
int o[100100] = { };

int main() {

	cin >> n;
	for (int i = 0; i < n; i++) {
		int in;
		cin >> in;
		if (i % 2 == 1) {
			o[in]++;
		} else {
			e[in]++;
		}
	}
	int om = 0, em = 0;
	for (int i = 0; i <= 100000; i++) {
		if (o[i] > o[om]) {
			om = i;
		}
		if (e[i] > e[em]) {
			em = i;
		}
	}
	sort(o, o + 100001, greater<int>());
	sort(e, e + 100001, greater<int>());
	if (om == em) {
		if (o[0] + e[1] > o[1] + e[0]) {
			cout << n - (o[0] + e[1]) << endl;
		} else {
			cout << n - (o[1] + e[0]) << endl;
		}
	} else {
		cout << n - (o[0] + e[0]) << endl;

	}

	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m;
	cin>>n>>m;
	vector<vector<int>> g(n);
	rep(i,m){
		int a,b;
		cin>>a>>b;
		a--,b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	int ans=0;
	vector<int> a(n);
	rep(i,n) a[i]=i;
	do{
		if(a[0]!=0) continue;
		bool flag=true;
		int ind=0;
		while(ind!=n-1){
			bool f=false;
			for(auto itr:g[a[ind]]){
				if(itr==a[ind+1]){
					f=true;
					break;
				}
			}
			if(!f){
				flag=false;
				break;
			}
			ind++;
		}
		if(flag) ans++;
	}while(next_permutation(begin(a),end(a)));
	cout<<ans<<endl;
}

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

int main(){
  ll x;cin >> x;
  ll ans = 0;
  ll p = 100; 
  while(1){
    if(p >= x){cout << ans << endl;return 0;}
    p = floor(p*1.01);
    ans += 1;
  }
  return 0;
}

Measured memory_bytes: 3744
#include <iostream>
#include <vector>
#define loop for(int i=0; i<N; i++)
using namespace std;

int main(){
  int N; cin >> N;
  vector<char> S; char c; int W,E; W=0; E=0;
  loop{
    cin >> c;
    if('W'==c){W++;}
    else{E++;}
    S.push_back(c);
  }
  
  int a,min,w,e; min=-1; w=0; e=0;
  loop{
    if('E'==S[i]){e++;}
    a = w + E-e;
    if(min==-1 || a < min){min = a;}
    if('W'==S[i]){w++;}
  }
  
  cout << min;
  
  return 0;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;
const int INF = 1001001001;

int main() {
  int x;
  cin >> x;
  int ans = 10 - x / 200;
  cout << ans << endl; 
}

Measured memory_bytes: 3612
N, M = map(int, input().split())
k_array = [list(map(int, input().split()))[1:] for i in range(M)]
p_array = list(map(int, input().split()))

# print(k_array)

ans = 0
for i in range(2**N):
    switch_str = bin(i)[2:].zfill(N)
    # print(switch_str)
    for m in range(M):
        count = 0
        for k in k_array[m]:
            if switch_str[k - 1] == "1":
                count += 1
        if count % 2 != p_array[m]:
            break
    else:
        ans += 1
print(ans)

Measured memory_bytes: 40816
#include <stdio.h>

int main(){
	
	int n;
	
	long d[101];
	
	long i,j;
	
	long t;
	
	int ret;
	
	ret = scanf("%d",&n);
	
	for(i=1; i<=n; i++){
		ret = scanf("%ld",&d[i]);
	}
	
	for(i=1; i<=n; i++){
		for(j=i;j<=n; j++){
			
			if (i!=j){
				t+=d[i]*d[j];
			}
		}
	}
	
	printf("%ld\n",t);
	
	return 0;
	
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;


int main() {
	long long int N; cin >> N;
		vector<long long int>as;
	long long int ans = 0;
	for (int i = 0; i < N; ++i) {
		long long int a; cin >> a;
		if (a > 10000) {
			long long int k = a / (N+1);
			if (k < 100)continue;
			else {
				ans += (k - 100)*(N + 1);
				a -= (k - 100)*(N + 1);
			}
		}
		as.push_back(a);
	}
	bool flag = true;
	while (flag) {
		flag = false;
		for (int i = 0; i < N; ++i) {
			if (as[i] >= N) {
				ans++;
				for (int j = 0; j < N; ++j) {
					as[j] += i == j ? -N : 1;
				}
				flag = true;
			}
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>
#include <iomanip>
#include <tuple>

using namespace std;


int main(){
   int r,d;
   vector<int> x(11);
   cin>>r>>d>>x[0];
   for(int i=1;i<11;i++){
       x[i]=r*x[i-1]-d;
       cout<<x[i]<<endl;
   }
}

   


Measured memory_bytes: 888
import copy

n = int(input())
A = []
for i in range(n):
    tmp = input().split()
    A.append([tmp[0], int(tmp[1])])
B = copy.deepcopy(A)

# ===========================================================================

def partition(A, p, r):
    x = A[r][1]
    i = p - 1
    for j in range(p, r):
        if A[j][1] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i + 1], A[r] = A[r], A[i + 1]
    return i + 1

def quick_sort(A, p, r):
    if p < r:
        q = partition(A, p, r)
        quick_sort(A, p, q-1)
        quick_sort(A, q+1, r)

# ============================================================================
# merge sort (for comparison)

def merge(A, left, mid, right):
    n1 = mid - left
    n2 = right - mid
    L = [0]*(n1+1)
    R = [0]*(n2+1)
    for i in range(n1):
        L[i] = A[left + i]
    for i in range(n2):
        R[i] = A[mid + i]
    L[n1] = ['nan', float("inf")]
    R[n2] = ['nan', float("inf")]
    i = 0
    j = 0
    for k in range(left, right):
        if L[i][1] <= R[j][1]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
            
def merge_sort(A, left, right):
    if left + 1 < right:
        mid = (left + right)//2
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, left, mid, right)


# ============================================================================
quick_sort(A, 0, len(A)-1)
merge_sort(B, 0, len(B))

print('Stable' if A == B else 'Not stable')
for x in A:
    print(x[0] + ' ' + str(x[1]))



Measured memory_bytes: 39268
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
    int N;
    int inN;
    vector<int> vec(10,0);
    cin>>N;
    while(N){
        for(int i=0;i<N;i++){
            cin>>inN;
            vec[inN]++;
        }
        for(int i=0;i<10;i++){
            if(!vec[i]){
                cout<<"-"<<endl;
            }else{
                for(int j=0;j<vec[i];j++){
                    cout<<"*";
                }
                cout<<endl;
            }
            vec[i]=0;
        }
        cin>>N;
    }
}

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


#define DEBUG(x) 			   cout << '>' << #x << ':' << x << endl;
#define D(x)        		   cerr << __LINE__ << ": " << #x << " = " << (x) << '\n'
#define DD(x,y)     		   cerr << __LINE__ << ": " << #x << " = " << x << "   " << #y << " = " << y << '\n'
#define DDD(x,y,z)  		   cerr << __LINE__ << ": " << #x << " = " << x << "   " << #y << " = " << y << "   " << #z << " = " << z << '\n'
#define DBG         		   cerr << __LINE__ << ": Hi" << '\n'
#define fresh                  {ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}
#define read                   freopen("in.txt","rt",stdin)
#define write                  freopen("out.txt","wt",stdout)
#define PI                     3.1415926535897932384626433832795
#define mems(ds_name,val)      memset(ds_name,val,sizeof(ds_name))


int main()
{
//    fresh;
//    read;
//	write;

  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int x=c-a;
  int y=d-b;

  cout<<c-y;puts("");
  cout<<d+x;puts("");
  cout<<a-y;puts("");
  cout<<b+x;puts("");



}


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

using namespace std;

constexpr int MAX_N = 100;

int v[2 * MAX_N];

int main() {
  int n; cin >> n;
  for (int i = 0; i < 2 * n; i += 1) {
    cin >> v[i];
  }

  sort(v, v + 2 * n);
  
  int ret = 0;
  for (int i = 0; i < n; i += 1) {
    ret += v[i + i];
  }

  cout << ret << '\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;
typedef long long ll;

int main() {
    int n, m;
    int i, s, c;
    int num[3];
    bool flag[3];
    int ans=0;
    
    for(i=0; i<3; i++){
        flag[i] = false;
    }
    
    cin >> n >> m;
    
    if(n==1) num[0] = 0;
    else if(n==2){
        num[0] = 1;
        num[1] = 0;
    } else if(n==3){
        num[0] = 1;
        num[1] = 0;
        num[2] = 0;
    }
    
    for(i=0; i<m; i++){
        cin >> s >> c;
        s--;
        if(n==1){
            if(!flag[s]){
                flag[s] = true;
                num[0] = c;
            } else{
                if(num[0] != c){
                    ans = -1;
                    break;
                }
            }
        } else if(n==2){
            if(s==0 && c==0){
                ans = -1;
                break;
            }
            if(!flag[s]){
                flag[s] = true;
                num[s] = c;
            } else{
                if(num[s] != c){
                    ans = -1;
                    break;
                }
            }
        } else if(n==3){
            if(s==0 && c==0){
                ans = -1;
                break;
            }
            if(!flag[s]){
                flag[s] = true;
                num[s] = c;
                
                
            } else{
                if(num[s] != c){
                    ans = -1;
                    break;
                }
            }
        }
        //cout << num[0] << " : " << num[1] << " : " << num[2] << endl;
    }
    
    if(ans == -1) cout << -1 << endl;
    else{
        if(n==1) ans = num[0];
        else if(n==2) ans = num[0] * 10 + num[1];
        else if(n==3) ans = num[0] * 100 + num[1] * 10 + num[2];
        cout << ans << endl;
    }
    
    return 0;
}




Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
int gcd(int a,int b){
	if(b!=0)
		return gcd(b,a%b);
	return a;
}
int cmp(const void *a,const void *b)
{
	return *(long long  *)b-*(long long  *)a;
}
int main(void)
{
	long long  n,i,x,max,k,a[200500];
	x=0;max=0;
	memset(a,0,sizeof a);
	long long  sum=0;
	scanf("%lld",&n);
	scanf("%lld",&k);
	for(i=0;i<n;i++)
	{
		scanf("%lld",&x);
		a[x]++;
		if(x>max)
			max=x;
	}
	qsort(a,n+1,sizeof a[0],cmp);
	for(i=0;i<k;i++)
		n-=a[i];
	printf("%lld\n",n);
	return 0;
 } 

Measured memory_bytes: 3324
#include<bits/stdc++.h>
using namespace std;
#define MAX_L 8
#define MAX_N 100005
typedef long long ll;
ll mod=1e9+7;
ll B=5575777;
 
int N;
string S[MAX_N];
unordered_set<ll> t[MAX_L+1];
char tmp[MAX_L+5];
 
bool dfs(ll hash,int depth,int anslen){
  if(depth==anslen){
    if(t[anslen].count(hash)==1)return false;
    for(int i=0;i<depth;i++)cout<<tmp[i];
    cout<<endl;
    return true;
  }
 
  for(char ch='a';ch<='z';ch++){
    tmp[depth]=ch;
    ll nhash=(hash*B+ch)%mod;
    if( dfs(nhash,depth+1,anslen) )return true;
  }
  return false;
}
 
void solve(){
  for(int i=0;i<N;i++){
    int size=S[i].size();
     
    for(int j=1;j<=MAX_L;j++){
       
      ll key=0,nb=1;
      for(int k=0;k<size;k++){
        key=(key*B+S[i][k])%mod;
        if(k-j>=0){
          key+=(mod- (S[i][k-j]*nb)%mod );
          key%=mod;
        }else nb=(nb*B)%mod;
        if(k+1>=j)t[j].insert(key);
      }
       
    }
  }
 
  ll cnt=1;
  int anslen=1;
  for(int i=1;i<=MAX_L;i++){
    cnt*=26;
    if( (ll)t[i].size() < cnt ){
      anslen=i;
      break;
    }
  }
 
  dfs(0,0,anslen);
}
 
int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  cin>>N;
  for(int i=0;i<N;i++)
    cin>>S[i];
  solve();
  return 0;
}

Measured memory_bytes: 87612
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    if(a <= 8 && b <= 8) cout << "Yay!" << endl;
    else cout << ":(" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007

using namespace std;


int main(void){
	int n;
	cin>>n;
	int a[n];
	int max1=0,max2=0;
	rep(i,n){
		cin>>a[i];
		if(max1<a[i]){
			max2=max1;
			max1=a[i];
		}
		else if(max2<a[i])max2=a[i];
	}

	rep(i,n){
		if(a[i]!= max1)cout<<max1<<endl;
		else cout<<max2<<endl;
	}

	return 0;

}


Measured memory_bytes: 2432
import sys
import collections

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    B = [int(x) for x in input().split()]

    ac = collections.Counter(A)
    bc = collections.Counter(B)

    for i in range(1, N + 1):
        if ac[i] + bc[i] > N:
            print("No")
            return

    ma = 0
    cnta = 0
    cntb = 0
    for i in range(1, N + 1):
        cnta += ac[i]
        cntb += bc[i - 1]
        ma = max(ma, cnta - cntb)

    print("Yes")

    ans = B[N - ma:] + B[:N - ma]
    print(*ans)


if __name__ == '__main__':
    main()


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

int N;
int A[110];

int main()
{
	cin >> N;

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

	for (int  i = 1; i < N; i++) {

		if (max < A[i])
			max = A[i];

		if (min > A[i])
			min = A[i];
	}

	cout << max - min << endl;

	return 0;

}

Measured memory_bytes: 256
import Data.List
main = getLine >>= print . solve 0 0 . map (\g -> (head g, length g)) . group

solve s l [] = s + l
solve s p ((c,l):gs)
    | c == '<' = solve (s + sum [1..l-1]) l gs
    | c == '>' = solve (s + max p l + sum [1..l-1]) 0 gs

Measured memory_bytes: 32124
from collections import deque

N, M, P = map(int, input().split())

ABC = []
for _ in range(M):
    a, b, c = map(int, input().split())
    ABC.append((a - 1, b - 1, P - c))

# preprocess
to = [[] for _ in range(N)]
fr = [[] for _ in range(N)]
for a, b, c in ABC:
    to[a].append(b)
    fr[b].append(a)

visitable_s = [False] * N
q = deque()
q.append(0)
visitable_s[0] = True
while len(q):
    a = q.pop()
    for b in to[a]:
        if not visitable_s[b]:
            visitable_s[b] = True
            q.append(b)

visitable_g = [False] * N
q = deque()
q.append(N - 1)
visitable_g[N - 1] = True
while len(q):
    a = q.pop()
    for b in fr[a]:
        if not visitable_g[b]:
            visitable_g[b] = True
            q.append(b)

visitable = [visitable_s[i] and visitable_g[i] for i in range(N)]
inf = float("inf")
d = [inf] * N
d[0] = 0

# Bellman-Ford
for i in range(N):
    for a, b, c in ABC:
        if not visitable[a] or not visitable[b]:
            continue
        if d[b] <= d[a] + c:
            continue
        if i == N - 1:
            print(-1)
            exit()
        d[b] = d[a] + c
ans = d[N - 1]
print(max(0, -d[N - 1]))


Measured memory_bytes: 52184
H, W = map(int, input().split())
S = [input() for i in range(H)]
A = [[0 for j in range(W)] for i in range(H)]
pos = []
cnt = 0
for i in range(H):
  for j in range(W):
    if S[i][j] == '#':
      pos.append([i, j])
      A[i][j] = 1
      cnt += 1
ccnt = 0
pnt = 0
while pnt < cnt:
  n = cnt
  ccnt += 1
  for i in range(pnt, cnt):
    x, y = pos[i][0], pos[i][1]
    if x > 0:
      if A[x-1][y] == 0:
        A[x-1][y] = 1
        pos.append([x-1, y])
        cnt += 1
    if x < H-1:
      if A[x+1][y] == 0:
        A[x+1][y] = 1
        pos.append([x+1, y])
        cnt += 1
    if y > 0:
      if A[x][y-1] == 0:
        A[x][y-1] = 1
        pos.append([x, y-1])
        cnt += 1
    if y < W-1:
      if A[x][y+1] == 0:
        A[x][y+1] = 1
        pos.append([x, y+1])
        cnt += 1
  pnt = n
print(ccnt-1)

Measured memory_bytes: 194980
#include <iostream>
#include <vector>

using namespace std;

int main() {
	/* ----- 変数宣言 ----- */
	int n;
	cin >> n;

	vector<char> s(n);
	int i;

	/* ----- 入力 ----- */
	for (i = 0; i < n; i++) {
		cin >> s[i];
	}

	/* ----- 計算 ----- */
	for (i = 0; i < n; i++) {
		if (s[i] == 'Y') {
			cout << "Four" << endl;
			return 0;
		}
	}

	cout << "Three" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>

using ll = long long;

int main() {
    int N, K;
    std::cin >> N >> K;

    std::vector<int> h(N);
    for (int i = 0; i < N; i++) {
        std::cin >> h[i];
    }

    std::sort(h.begin(), h.end());

    std::vector<int> sub(N);
    sub[0] = 0;
    for (int i = 1; i < N; i++) {
        sub[i] = sub[i - 1] + h[i] - h[i - 1];
    }

    K--;
    int min = sub[K] - sub[0];
    for (int i = K + 1; i < N; i++) {
        min = std::min(min, sub[i] - sub[i - K]);
    }

    std::cout << min << std::endl;
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
int main(void)
{
    int x,y;
    int ans = 0;
    scanf("%d %d",&x,&y);
    if(x == 2 || y == 2){
        printf("No");
    }else if(x == 4 || x == 6 || x == 9 || x == 11){
        if(y == 4 || y == 6 || y == 9 || y == 11){
            printf("Yes");
        }else{
            printf("No");
        }
    }else if(y == 4 || y == 6 || y == 9 || y == 11){
        printf("NO");
        
        
    }else{
        printf("Yes");
    }

    }


Measured memory_bytes: 128