akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int X, Y;
	cin >> X >> Y;
	if (X%Y == 0) {
		cout << -1 << endl;
	}
	else {
		cout << X << endl;
	}
	//cout << res << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    if(a * b * c == 5 * 5 * 7){
        printf("YES\n");
    }else{
        printf("NO\n");
    }
    return 0;
} 


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


int main() {
    int N;
    cin >> N;
    int64_t count=0;
    for(int i=0;i<N+1;i++){
        if(i%3!=0&&i%5!=0) count+=i;
    }
    cout << count << endl;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    int ans = 0;
    rep(i,n) {
        int a;
        cin >> a;
        if((i+1)%2==1 && a%2==1) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3616
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}

int v[100][100];

int f(int a, int b, int c, int d){
    int ret = v[c][d];
    if(a)ret -= v[a-1][d];
    if(b)ret -= v[c][b-1];
    if(a&&b)ret += v[a-1][b-1];
    return ret;
}

signed main(void) {
    int n;
    cin >> n;
    rep(i,n)rep(j,n)cin >> v[i][j];
    rep(i,n)rep(j,n-1)v[i][j+1] += v[i][j];
    rep(j,n)rep(i,n-1)v[i+1][j] += v[i][j];
    int ans = -LINF;
    rep(i,n)rep(j,n)loop(k,i,n)loop(l,j,n){
        ans = max(ans, f(i,j,k,l));
    }
    cout << ans << endl;
}



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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) (int)a.size()

typedef long long lint;
typedef pair<int, int> pii;

int N, A[330];

int dp[330][330];

int cost(int a, int b) {
	int res = 0;
	int C = 0;
	
	while (a != 0 || b != 0 || C != 0) {
		int ai = a % 10, bi = b % 10;
		
		int ci = (C > 0) ? 1 : 0;
		res += ai * bi + ci;
		
		int sumi = ai + bi + C;
		C = sumi / 10;
		
		a /= 10; b /= 10;
	};
	
	return res;
}

int calc_cost(int i1, int j1, int i2, int j2) {
	int sum1 = 0, sum2 = 0;
	for_(i,i1,j1 + 1) sum1 += A[i];
	for_(i,i2,j2 + 1) sum2 += A[i];
	return cost(sum1, sum2);
}

void solve() {
	for_(i,0,330) fill(dp[i], dp[i] + 330, (int)1e9);
	for_(i,0,N) dp[i][i] = 0;
	
	for_(k,1,N) {
		for_(i,0,N - k) {
			// calculate dp[i][i + k]
			for_(j,0,k) {
				// (i, i + j) + (i + j + 1, i + k)
				dp[i][i + k] = min(dp[i][i + k], dp[i][i + j] + dp[i + j + 1][i + k] + calc_cost(i, i + j, i + j + 1, i + k));
			}
		}
	}
	
	cout << dp[0][N - 1] << endl;
}

int main() {
	cin >> N;
	for_(i,0,N) cin >> A[i];
	solve();
	return 0;
}

Measured memory_bytes: 1588
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
using ull=unsigned long long;
constexpr auto inf=static_cast<ll>(1e18);
template<typename T=ll>inline T in(){T ret;cin>>ret;return ret;}
template<typename T=ll>inline auto vec2(size_t h,size_t w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}
inline void setp(int n){cout<<fixed<<setprecision(n);}
inline void delnl(){cin.ignore(numeric_limits<streamsize>::max(),'\n');}

int main()
{
    ll n=in();
    vector<ll>d(n);for(auto&i:d)i=in();
    ll sum=0;
    for(ll i=0;i<n;++i){
        for(ll j=0;j<n;++j){
            if(i<j){
                sum+=d[i]*d[j];
            }
        }
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <complex>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <iomanip>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define putsp(x) cout << x << ' ';
#define putbd cout << "---------------------------------------------" << endl;
#define putln(x) cout << x << endl;
#define debug(x) cerr << #x << "=" << x << endl;
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef complex<double> comp;
typedef vector <int> vec;
typedef vector <ll> vecll;
typedef vector <double> vecd;
typedef vector <vec> mat;
typedef vector <vecll> matll;
typedef vector <vecd> matd;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const int MAX = 200020;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const ll INFL = 1e18;
const ll MOD = 1000000007;

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

//********************************template END****************************************//

void solve(void)
{
	string S;
	cin >> S;
	int l = S.size();
	int ans = 753;
	rep(l-2, i)
	{
		string subs = S.substr(i, 3);
		ans = min(ans, abs(stoi(subs)-753));
	}
	cout << ans << endl;
}

int main(void)
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> point(N);
  
  for (int i = 0; i < N; i++) {
    cin >> point.at(i);
  }
  int temp;
  for (int i = 0; i < (N - 1); i++) {
    for (int j = (N - 1); j > i; j--) {
      
      if (point.at(j - 1) < point.at(j)) {
        temp = point.at(j - 1);
        point.at(j - 1) = point.at(j);
        point.at(j) = temp;
      }
      
    }
  }
  
  int Alice = 0, Bob = 0;
  
  for (int i = 0; i < N; i++) {
     if (i % 2 == 0) {
       Alice += point.at(i); 
     } else {
       Bob += point.at(i); 
     }
  }
  
  cout << Alice - Bob << endl;
}

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

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,l;
	cin>>n>>l;
	vl a(n);
	iota(all(a),l);
	ll p=INF,v=0;
	rep(i,n){
		if(chmin(p,abs(a[i])))v=a[i];
	}
	puta(sum(a)-v);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef pair<int, bool> Submit;
const int BUF = 100005;


int nProb, nSubmit;
Submit submit[BUF]; // (id, isAC)

void read() {
    cin >> nProb >> nSubmit;
    for (int i = 0; i < nSubmit; ++i) {
        int id;
        string result;
        cin >> id >> result;
        submit[i] = make_pair(id, result == "AC");
    }
}


void work() {
    // cntWA[i] >= 0 : # of WA
    // cntWA[i] == 1 : ACed
    int cntWA[BUF] = {};
    int nAC = 0, nPenalty = 0;

    for (int i = 0; i < nSubmit; ++i) {
        if (cntWA[submit[i].first] == -1) continue;
        if (submit[i].second) {
            ++nAC;
            nPenalty += cntWA[submit[i].first];
            cntWA[submit[i].first] = -1;
        } else {
            ++cntWA[submit[i].first];
        }
    }

    cout << nAC << ' ' << nPenalty << endl;
}


int main() {
    read();
    work();
    return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
    typedef long long ll;
    using namespace std;
    const int maxn=2e5+10;
    const int mod=1e9+7;
    ll f[maxn];
    ll p[maxn];
    ll pows(ll a,ll b)
    {
         ll re=1;
         while(b)
         {
            if(b&1)
            re=re*a%mod;
                a=a*a%mod;
                b/=2;
         }
         return re%mod;
    }
    void inint()
    {
        f[0]=p[0]=1;
        for(int i=1;i<=maxn;i++)
            f[i]=f[i-1]*i%mod,p[i]=pows(f[i],mod-2)%mod;
    }
    ll C(ll n,ll m)
    {
        ll ans=(ll)f[n]*p[n-m]%mod*p[m]%mod;
     //   cout<<f[n]<<' '<<p[n-m]<<' '<<p[m]<<' '<<ans<<endl;
     //cout<<ans<<endl;
         return ans;
    }
    ll solve(ll n,ll m,ll k)
    {
           ll ans=0;
           for(int i=1;i<n  ;i++)
           {
               ans=(ans+C(n*m-2,k-2)*(n-i)%mod*m%mod*m%mod*i%mod)%mod;
              // cout<<ans<<endl;
           }

           return ans%mod;
    }
    int main()
    {
        ll n,m,k;
         cin>>n>>m>>k;
         inint();
         ll ans=(solve(n,m,k)+solve(m,n,k))%mod;
         printf("%lld\n",ans);
        return 0;
    }


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

#define MOD 10000007
#define f first
#define s second
#define pb push_back
#define es " "
#define endl "\n"
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define ll long long int
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)

int main(){
    fastio;
    int n, k, v[200005];
    cin >> n >> k;
    for(int i=0; i<n; i++){
        cin >> v[i];
    }
    sort(v, v+n);
    ll resp=0;
    for(int i=n-1-k; i>=0; i--){
        resp+=v[i];
    }
    cout << resp << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,d,a[101],b[101],c[101],t[101][100001];
main(){
  while(cin>>n>>d,n){
    memset(a,0,sizeof(a)); 
    memset(b,0,sizeof(b));
    r(i,n){
      cin>>c[i];
      r(j,c[i])cin>>t[i][c[i]-1-j];
    }
    r(i,n)r(j,c[i])a[i]+=t[i][j];
    while(1){
      int ma=0,id,mb=0,ib,q[n],f=0;
      r(i,n)q[i]=a[i];
      r(i,n)if(a[i]>ma)ma=a[i],id=i;
      r(i,n)if(b[i]!=c[i]&&i!=id&&abs(ma-(a[i]-t[i][b[i]]))<=d)a[i]-=t[i][b[i]],b[i]++;
      r(i,n)if(a[i]>mb&&i!=id)mb=a[i],ib=i;
      while(abs(mb-(a[id]-t[id][b[id]]))<=d&&b[id]!=c[id])a[id]-=t[id][b[id]],b[id]++;
      r(i,n)if(q[i]!=a[i])f++;
      if(!f)break;
    }
    int f=0;
    r(i,n)if(a[i])f++;
    cout<<(f?"No":"Yes")<<endl;
  }
}

Measured memory_bytes: 3564
/*
#include<bits/stdc++.h>
#define nil -1
using namespace std;

struct node{int p,l,r;};

void print(int u,vector<node>&t,vector<int>&dp){
	cin.tie(0),ios::sync_with_stdio(false);
	cout<<"node "s<<u<<": "s;
	cout<<"parent = "s<<t.at(u).p<<", "s;
	cout<<"depth = "s<<dp.at(u)<<", "s;
	if(t.at(u).p==nil)cout<<"root, "s;
	else if(t.at(u).l==nil)cout<<"leaf, "s;
	else cout<<"internal node, "s;
	cout<<"["s;
	for(int i=0,c=t.at(u).l;c!=nil;++i,c=t.at(c).r){
		if(i)cout<<", "s;
		cout<<c;
	}
	cout<<"]\n"s;
}

void rec(int u,int p,vector<node>&t,vector<int>&dp){
	dp.at(u)=p;
	if(t.at(u).r!=nil)rec(t.at(u).r,p,t,dp);
	if(t.at(u).l!=nil)rec(t.at(u).l,p+1,t,dp);
}

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<int>dp(n);
	vector<node>t(n);
	for(auto&i:t)i.p=i.l=i.r=nil;
	for(int i=0,id,d,c,l;i<n;++i){
		cin>>id>>d;
		for(int j=0;j<d;++j){
			cin>>c;
			if(j==0)t.at(id).l=c;
			else t.at(l).r=c;
			l=c;
			t.at(c).p=id;
		}
	}
	int r;
	for(int i=0;i<n;++i){
		if(t.at(i).p==nil)r=i;
	}
	rec(r,0,t,dp);
	for(int i=0;i<n;++i)print(i,t,dp);
}
*/

#include<bits/stdc++.h>
using namespace std;
using pr=pair<int,int>;

void print(int root,int id,vector<pr>&v,vector<vector<int>>&dg){
	int p=v.at(id).first,d=v.at(id).second;
	cout<<"node "s<<id<<": parent = "s<<p<<", depth = "<<d<<", "s;
	if(id==root)cout<<"root"s;
	else if(!dg.at(id).size())cout<<"leaf"s;
	else cout<<"internal node"s;
	cout<<", ["s;
	for(int j=0;j<dg.at(id).size();++j){
		if(j!=0)cout<<", "s;
		cout<<dg.at(id).at(j);
	}
	cout<<"]\n"s;
}

void depth(int p,int d,vector<pr>&v,vector<vector<int>>&dg){
	for(int i=0;i<dg.at(p).size();++i){
		v.at(dg.at(p).at(i)).second=d;
		depth(dg.at(p).at(i),d+1,v,dg);
	}
}

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<pr>v(n,pr(-1,0));
	vector<vector<int>>dg(n);
	for(int i=0,k,id,c;i<n;++i){
		cin>>id>>k;
		for(int j=0;j<k;++j){
			cin>>c;
			dg.at(id).push_back(c);
			v.at(c)=pr(id,0);
		}
	}
	int P=0;
	while(v.at(P).first!=-1)++P;
	depth(P,1,v,dg);
	for(int i=0,p,d;i<n;++i)print(P,i,v,dg);
}


Measured memory_bytes: 6756
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define MOD7 1000000007
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> K(M);
    vector<vector<int>> S(M);
    for(int i = 0; i < M; i++){
        cin >> K[i];
        for(int j = 0; j < K[i]; j++){
            int s;
            cin >> s;
            S[i].push_back(s);
        }
    }
    vector<int> P(M);
    for(int i = 0; i < M; i++) cin >> P[i];
    int ans = 0;
    for(int bit = 0; bit < (1<<N); bit++){
        bool ok = true;
        for(int i = 0; i < M; i++){
            int count = 0;
            for(int j = 0; j < K[i]; j++){
                if(bit & (1 << S[i][j] - 1)) count++;
            }
            if(count % 2 != P[i]) ok = false;
        }
        if(ok) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int a[20000], b[20000];

void div(int n, int *d, int m) {
    int a = 1;
    rep (i, n) { d[i] = a / m; a = a % m * 10; }
}

void add(int n, int *a, int *b) {
    int c = 0;
    for (int i = n-1; i >= 0; i--) {
        a[i] += b[i] + c;
        c = 0;
        if (a[i] >= 10) a[i] -= 10, c = 1;
    }
}

int main() {
    int n, k, m, r;
    for (;;) {
        scanf("%d%d%d%d", &n, &k, &m, &r);
        if (n == 0) return 0;
        div(r+10, a, n);
        if (m) rep (i, n-1) {
            div(r+10, b, n*(i+1));
            add(r+10, a, b);
        }
        printf("%d.", a[0]);
        rep (i, r) printf("%d", a[i+1]);
        printf("\n");
    }
}

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

typedef long long int ll;
typedef long double ld;

#define Pb push_back
#define Mp make_pair

#define ff first
#define ss second

#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))

#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN

#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define db1(x) cout<<#x<<" : "<<x<<endl;
#define db2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define db3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;

const int  N = 1e5+5;
const int inf = INT_MAX;
const int MOD = 1e9+7;


void solve()
{
   int x,y;
   cin >> x >> y;
   if(y%2)
   {
      cout << "No";
      return;
   }
   y/=2;
   if(y < x || y > 2*x)
   {
      cout << "No";
      return;
   }
   if(y == x)
   {
      cout << "Yes";
      return;
   }
   int j = y-x;
   y-=2*(j);
   x-=(j);
   if(x!=y)
   {
      cout << "No";
   }
   else
   {
      cout << "Yes";
   }
}

signed main()
{
  IOS;
  //freopen("input.txt", "rt", stdin);
  //freopen("output.txt", "wt", stdout);
  int t=1;
  //cin >> t;
  while(t--)
  {
    solve();
  }
  return 0;
}
/*==============================================================================================================================================================*/


Measured memory_bytes: 3640
import collections
import heapq
n=int(input())
A=[int(i) for i in input().split()]
Ans=[0]*n
M=[0]
for i in range(n):
  M.append(max(M[-1],A[i]))
D=collections.defaultdict(int)
H=[]
for i in range(n):
  j=n-1-i
  if A[j]<=M[j]:
    heapq.heappush(H,-A[j])
  else:
    Ans[j]=(A[j]-M[j])*(D[A[j]]+1)
    D[M[j]]+=D[A[j]]+1
    ct=0
    while H:
      a=heapq.heappop(H)
      a=-a
      if a<=M[j]:
        heapq.heappush(H,-a)
        break
      else:
        Ans[j]+=a-M[j]
        D[M[j]]+=1

for a in Ans:
  print(a)


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


int main()
{
    int n;
    cin>>n;
    int arr[n];
    for(int i = 0;i < n;i++)
    {
        cin>>arr[i];
    }

    int cnt = 0;
    for(int i = 0;i < n;i++)
    {
        for(int j = n-1;j >= i+1;j--)
        {
            if(arr[j] < arr[j-1])
            {
                cnt++;
                swap(arr[j], arr[j-1]);
            }
        }
    }
    
    for(int i = 0;i < n;i++)
    {
        if(i == n-1)
            cout<<arr[i];
        else
            cout<<arr[i]<<" ";
    }
    cout<<endl;
    cout<<cnt<<endl;
}

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

int main(){
  int i, j, x, y;

  while(1){
    cin >> x >> y;
    if(x == 0 || y == 0) break;

    for(i = 0; i < x; i++){
      for(j = 0; j < y; j++){
        if(i == 0 || i == x-1 || j == 0 || j == y-1 )  cout << '#';
        else                                           cout << '.';
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define rep(i,s,t) for(register int i=s;i<=t;++i)
using namespace std;
const int N=1e6+11,mod=1e9+7;
int n,ans,a[N],inv[N];
int main(){
	cin>>n;
	rep(i,1,n)
		cin>>a[i];
	inv[1]=1;
	rep(i,2,n)
		inv[i]=mod-1ll*mod/i*inv[mod%i]%mod;
	rep(i,2,n)
		inv[i]=(inv[i]+inv[i-1])%mod;
	rep(i,1,n)
		ans=(ans+1ll*(inv[i]+inv[n-i+1]-1)*a[i])%mod;
	rep(i,1,n)
		ans=1ll*ans*i%mod;
	ans=(ans+mod)%mod;
	cout<<ans;}

Measured memory_bytes: 4736
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import qualified Data.Map.Strict             as Map
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

main = do
  [n, m] <- getIntList
  as <- VB.replicateM n $ do
    l <- getIntList
    return $ Seq.fromList l

  let findDelete x seq = let i = fromJust (Seq.findIndexL (== x) seq)
                             seq' = deleteAt i seq
                         in seq'

      deleteAt i seq = let s1 = Seq.take i seq
                           s2 = Seq.drop (i+1) seq
                       in s1 Seq.>< s2

      mostPopular :: [Int] -> IO (Int, Int)
      mostPopular xs = do
        d <- VM.new (m+1)
        VM.set d (0::Int)
        forM_ xs $ \x -> do
          t <- VM.read d x
          VM.write d x (t+1)
        let loop i j ct | i > m = return (j, ct)
                        | otherwise = do
                            t <- VM.read d i
                            if t > ct
                              then loop (i+1) i t
                              else loop (i+1) j ct
        loop 1 0 0

      extrHeads as
        | Seq.null (as VB.! 0) = []
        | otherwise = map
                      (\i ->
                          let x Seq.:< _ = Seq.viewl $ as VB.! i
                          in x)
                      [0..(n-1)]

      solve as res = do
        let pops = extrHeads as
        if null pops
          then return res
          else do (j, ct) <- mostPopular pops
                  let as' = VB.map (findDelete j) as
                  solve as' (min res ct)

  ans <- solve as inf
  print ans

Measured memory_bytes: 14716
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
        ifstream in("input.txt");
        //ofstream out("output.txt");
        #define cin in
        //#define cout out
#endif
int const MAXN=22, M=1000000007, MAXV=3000000;
int n, t[MAXN][MAXN], memo[MAXN][MAXV];
int dp(int row, bitset<MAXN> b){
	if(row==n) return 1;
	int col=b.to_ulong();
	if(memo[row][col]!=-1) return memo[row][col];
	int res=0;
	for(int i=0;i<n;i++) 
		if(t[row][i]==1 && b[i]==false){
			b[i]=true;
			res+=dp(row+1,b);
			res%=M;
			b[i]=false;
		}
	return memo[row][col]=res;
}
int main(){
	cin>>n;
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			cin>>t[i][j];
	for(int i=0;i<=n;i++)
		for(int j=0;j<MAXV;j++)
			memo[i][j]=-1;
	bitset<MAXN> b;
	b.reset();
	cout<<dp(0,b);
}

Measured memory_bytes: 258048
#include <bits/stdc++.h>
#define range(i, l, r) for(int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

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

    int H, W, N;
    cin >> H >> W >> N;
    int sr, sc;
    cin >> sr >> sc;
    sr--; sc--;
    string S, T;
    cin >> S >> T;

    int bound_l = 0, bound_r = W - 1;
    int bound_u = 0, bound_d = H - 1;
    reversed_range(i, 0, N) {
        char move_aoki = T.at(i);
        if (move_aoki == 'L') bound_r = min(W - 1, bound_r + 1);
        else if (move_aoki == 'R') bound_l = max(0, bound_l - 1);
        else if (move_aoki == 'U') bound_d = min(H - 1, bound_d + 1);
        else bound_u = max(0, bound_u - 1);

        char move_takahashi = S.at(i);
        if (move_takahashi == 'L') bound_l++;
        else if (move_takahashi == 'R') bound_r--;
        else if (move_takahashi == 'U') bound_u++;
        else bound_d--;
        if (bound_l > bound_r || bound_u > bound_d) {
            cout << "NO" << "\n";
            return 0;
        }
    }
    string answer = (bound_l <= sc && sc <= bound_r && bound_u <= sr && sr <= bound_d) ? "YES" : "NO";
    cout << answer << "\n";
    return 0;
}

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

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

    std::vector<long long> A(N + 1), B(N);
    for (int i = 0; i < N + 1; i++)
        std::cin >> A[i];
    for (int i = 0; i < N; i++)
        std::cin >> B[i];

    long long ans = 0;
    for (int i = 0; i < N; i++) {
        long long x = std::min(A[i + 1], std::max(0LL, B[i] - A[i]));
        A[i + 1] -= x;
        ans += std::min(A[i], B[i]) + x;
    }

    std::cout << ans << "\n";
}

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

int main(void) {
    string s;
    string check1;
    string check2;

    cin >> s;

    check1 = s;check2 = s;
    reverse(check2.begin(), check2.end());

//    cout << check1 << endl;
//    cout << check2 << endl;
    if(check1 != check2) goto ng;
    

    check1 = s;
    check1 = s.substr(0, s.size() / 2);
    check2 = check1;
    reverse(check2.begin(), check2.end());

    if(check1 != check2) goto ng;
//    cout << check1 << endl;
//    cout << check2 << endl;

    check1 = s.substr(s.size()/2 + 1, s.size() / 2);
    check2 = check1;
    reverse(check2.begin(), check2.end());
    if(check1 != check2) goto ng;

//    cout << check1 << endl;
//    cout << check2 << endl;

    cout << "Yes\n";
    return 0;

ng:
    cout << "No\n";
    return 0;
}


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

int dp[2][9][9][2];
char s[200000];
int main(){
	while(1){
		scanf("%s",s);
		if(s[0]=='#')break;
		int n=strlen(s);
		rep(i,n){
			s[i]-='1';
		}
		rep(i,9)rep(j,9)rep(k,2){
			if(j==4||k==4)dp[0][i][j][k]=INF;
			else dp[0][i][j][k]=0;
		}
		rep(l,n){
			int i=l%2;
			rep(j,9)rep(k,9)rep(t,2)dp[!i][j][k][t]=INF;
			rep(j,9)rep(k,9)rep(t,2){
				if(s[l]%3<=k%3){
					dp[!i][s[l]][k][0]=min(dp[!i][s[l]][k][0],dp[i][j][k][t]+(t==0));
				}
				if(j%3<=s[l]%3){
					dp[!i][j][s[l]][1]=min(dp[!i][j][s[l]][1],dp[i][j][k][t]+(t==1));
				}
			}
		}
		int Min=INF;
		rep(i,9)rep(j,9)rep(k,2)Min=min(Min,dp[n%2][i][j][k]);
		printf("%d\n",Min);
	}
}

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

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	long long sum = 0;
	int mod = 1000000007;

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

	//大きい正方形の面積を求める
	long long ans = sum * sum % mod;
	//中央の正方形を取り除く
	for (int i = 0; i < N; i++)
	{
		ans -= (long long)A[i] * A[i] % mod;
		if (ans < 0) ans += mod;
	}

	//2で割る (逆元を用いる)
	//ans /= 2 を mod 1000000007で行うとこうなる
	ans *= (mod + 1) / 2;
	ans %= mod;

	cout << ans << endl;
}



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

using namespace std;

enum d753_t { d3, d5, d7 };

int decimal(const d753_t digits[], int n) {
  int ret = 0;
  int adder = 1;
  for (int d = 0; d < n; ++d) {
    switch (digits[d]) {
      case d3:
        ret += 3 * adder;
        break;
      case d5:
        ret += 5 * adder;
        break;
      case d7:
        ret += 7 * adder;
        break;
    }
    adder *= 10;
  }
  return ret;
}

int calc(int n) {
  int ret = 0;
  if (n < 357) {
    return ret;
  }
  d753_t digits[9];
  for (int maxDigits = 3; maxDigits < 10; ++maxDigits) {
    for (int d = 0; d < maxDigits; ++d) {
      digits[d] = d3;
    }
    while (true) {
      if (decimal(digits, maxDigits) > n) {
        return ret;
      }
      bool exists[3] = {false};
      for (int d = 0; d < maxDigits; ++d) {
        exists[int(digits[d])] = true;
      }
      if (exists[0] && exists[1] && exists[2]) {
        ++ret;
      }
      bool overflowed = true;
      for (int d = 0; d < maxDigits; ++d) {
        digits[d] = d753_t((int(digits[d]) + 1) % 3);
        if (digits[d] != d3) {
          overflowed = false;
          break;
        }
      }
      if (overflowed) {
        break;
      }
    }
  }
  return ret;
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int n;
  std::cin >> n;
  std::cout << calc(n) << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main()
{
	int status = 1;
	int max_num;
	int x;
	int a;
	int b;
	int ret;

	max_num = (int)pow(10, 9);

	ret = scanf("%d %d %d", &x, &a, &b);
	if (ret == -1) {
		goto end;
	}

	if (x > max_num) {
		goto end;
	}
	if (a > max_num) {
		goto end;
	}
	if (b > max_num) {
		goto end;
	}

	if (b <= a) {
		printf("delicious\n");
	} else if (b <= a + x) {
		printf("safe\n");
	} else {
		printf("dangerous\n");
	}

	status = 0;

end:
	if (status != 0) {
		fprintf(stderr, "Parameter error.\n");
	}

	return 0;
}



Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
ll mod=1000000007;

int main() {
  ll a,b,c;cin >> a >> b >> c;
  if(a%2 == 0 || b%2 == 0 ||c%2 == 0){
    cout << 0 << endl;
  } else {
    vector<ll> v(3);
    v[0]= a;
    v[1]= b;
    v[2]= c;
    sort(all(v));
    cout << v[0] * v[1] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    a62(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}

fun a62(args: Array<String>) {
    if (args.size != 1) {
        throw IllegalArgumentException()
    }
    val numList = args[0].split(" ").map { it.toInt() }
    val groupList =
            listOf(setOf(1, 3, 5, 7, 8, 10, 12)
                    , setOf(4, 6, 9, 11)
                    , setOf(2))
    println(if (groupList.any { it.containsAll(numList) }) "Yes" else "No")
}

Measured memory_bytes: 38080
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <cstdlib>

int main()
{
  std::vector<int> a(3);
  scanf("%d %d %d", &a[0], &a[1], &a[2]);
  std::sort(a.begin(), a.end());
  std::cout << std::abs(a[0] - a[1]) + std::abs(a[1] - a[2]) << std::endl;
}


Measured memory_bytes: 256
import sys
import itertools
sys.setrecursionlimit(10000)
def resolve():
    C = [list(map(int, input().split(" "))) for i in range(3)]
    #minimum = min(list(itertools.chain.from_iterable(C)))

    for a1 in range(101):
        b1 = C[0][0] - a1
        for a2 in range(101):
            b2 = C[1][1] - a2
            for a3 in range(101):
                b3 = C[2][2] - a3
                if check(C, [a1, a2, a3], [b1, b2, b3]):
                    print("Yes")
                    return
    print("No")

def check(C, A, B):
    for i in range(len(C)):
        for j in range(len(C[i])):
            if C[i][j] != A[i] + B[j]:
                return False
    return True

if '__main__' == __name__:
    resolve()

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

using namespace std;

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

  int v = 0;

  for(int i = 0;
      i < s.length();
      ++i)
    {
      if(s[i] == 'o')
        {
          ++v;
        }
    }

  if(15 - s.length() + v >= 8)
    {
      cout << "YES" << endl;
    }
  else
    {
      cout << "NO" << endl;
    }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,-1,sizeof(x))
const int INF = 1000000001;

int main(){
  int n;
  cin >> n;
  int p[10];
  rep(i, n) cin >> p[i];
  sort(p, p + n);
  int ans = 0;
  rep(i, n-1) ans += p[i];
  ans += p[n-1]/2;
  cout << ans << endl;
}

Measured memory_bytes: 3588
# include<iostream>
# include<cstring>
using namespace std;
int main()
{
	string s;
	cin>>s;
	bool ok = false;
	for(int i=0;i<s.length();i++)
	{
		if(s[i]=='7')
		{
			ok = true;
			break;
		}
	}
	if(ok)
	{
		 cout<<"Yes"<<endl;
	}
	else
	{
		 cout<<"No"<<endl;
	}
}

Measured memory_bytes: 3592
// Author - Sumit 

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

#define ll long long
#define int ll
#define ps push
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
#define mp make_pair
#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 all(v) v.begin(),v.end()
#define pii pair<int,int>
#define F first
#define S second
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pair<int,int>>
#define itr :: iterator it
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define debug(x) cout << x << "\n";
#define debug2(x,y) cout << x << " " << y << "\n";
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;
template<typename T, typename U> inline void remin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void remax(T &x, U y) { if(x < y) x = y; }
 


void solve(){
    int n;
    cin>>n;
    double ans=(n*1.000)/(1.08);
    // debug(ans);
    int res = ceil(1.00*ans);
    int res1=floor(1.00*ans);
    if(n == (int)(res*1.08)){
        debug(res);
    }else if(n == (int)(res1*1.08)){
        debug(res1);
    }
    else{
        debug(":(");
    }

}

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

    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
}


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

// int ans(int n){
    
// }

int main() {
    int l,r,d,cnt=0;
    cin>>l>>r>>d;
    for(int i=l;i<=r;i++){
        if(i%d==0)cnt++;
    }
    cout<<cnt;
}

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

using namespace std;
const int IINF = INT_MAX;
using ll = long long;
using P = pair<int,int>;
#define INF 1000000000000
int main(){
    int n,r; cin >> n >> r;
    
    if(n < 10) cout << r + 100*(10 - n) << endl;
    else cout << r << endl;
    
    return 0;	
}

Measured memory_bytes: 3640
#define _USE_MATH_DEFINES
#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
#define rep(i,a,b) for(int i = (a); i < (b); i++)
#define repd(i,a,b) for(int i = (a); i >= (b); i--)
using namespace std;
typedef long long int ll;
typedef complex<double> com;
typedef pair<int, int> P;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 4e18;



int main() {
	int n; cin >> n;
	vector<int> a(n);
	rep(i, 0, n) cin >> a[i];
	ll ans = 0, sub = 0;
	ll sum=0, presum=-1;
	rep(i, 0, n) {
		sum += a[i];
		if (sum * presum >= 0) {
			ans += abs(sum) + 1;
			if (presum > 0) sum = -1;
			else sum = 1;
		}
		presum = sum;
	}
	sum = 0, presum = 1;
	rep(i, 0, n) {
		sum += a[i];
		if (sum * presum >= 0) {
			sub += abs(sum) + 1;
			if (presum > 0) sum = -1;
			else sum = 1;
		}
		presum = sum;
	}
	printf("%lld", min(ans, sub));
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <sstream>
#include <utility>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <cmath>
#include <functional>
#include <chrono>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<lint> vl;
typedef pair<lint,lint> pll;
#define mpr make_pair

int res(int t1, int t2, int t3){
    int l = (t1 + t2 +t3)/2;
    int x1 = l - t3;
    int x2 = l - t2;
    int x3 = l - t1;
    if (x1==x2 || x2==x3){
        if (x1==x2 && x2==x3) return 1;
        else return 3;
    } else {
        return 6;
    }
}

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

    int n; cin>>n;

    string s; cin>>s;
    int cnt1 = 0;
    for (int i=0; i<n; ++i){
        if (s[i] == '1') cnt1++;
    }

    if (cnt1 == 0){
        for (int i=0; i<n; ++i){
            cout<<1<<"\n";
            return 0;
        }
    }

    if (cnt1 == 1){
        for (int i=0; i<n; ++i){
            if (s[i] == '1'){
                cout<<0<<"\n";
            } else {// mod 2
                if (s[n-1] == '1' || i == n-1)
                {
                    cout<< 2<<"\n";
                }else {
                    cout<<1<<"\n";
                }
            }
        }
        return 0;
    }

    vi rem_p(n, 1),rem_m(n, 1);
    rem_m[0] = 1 % (cnt1 - 1);
    int base = 1;
    for (int i = 1; i<n; ++i){
        rem_p[i] = rem_p[i-1] * 2 %(cnt1+1);
        rem_m[i] = rem_m[i-1] * 2 %(cnt1-1);

    }


    int tot_p = 0;
    int tot_m = 0;
    for (int i = 0; i<n; ++i){
        if (s[i] == '1'){
            tot_p = (tot_p + rem_p[n-1-i])%(cnt1 +1);
            tot_m = (tot_m + rem_m[n-1-i])%(cnt1 -1);
        }

    }

    for (int bit = n-1; bit >=0; bit--){
        int rem;
        if (s[n-1-bit]=='1'){//-
            rem = (tot_m - rem_m[bit] + (cnt1-1))%(cnt1-1);
        } else {
            rem = (tot_p + rem_p[bit]) % (cnt1 + 1);
        }
        int cnt = 1;
        while(rem){
            cnt++;
            rem = rem % __builtin_popcount(rem);
        }
        cout<<cnt<<"\n";
    }

}


Measured memory_bytes: 5172
def calc_matrix_prod(m_a, m_b):

    r_a = len(m_a)
    c_a = len(m_a[0])

    r_b = len(m_b)
    c_b = len(m_b[0])

    res = list()

    for i in range(r_a):
        line = list()
        for j in range(c_b):
            s = 0
            for k in range(c_a):
                s += m_a[i][k] * m_b[k][j]
            
            line.append(s)
        res.append(line)    
    
    for i in range(r_a):
        for j in range(c_b):
            print(str(res[i][j]), end="")

            if j != c_b - 1:
                print(" ", end="")

        print("\n", end="")

if __name__ == "__main__":
    
    param = input().split(" ")
    n = int(param[0])
    m = int(param[1])
    l = int(param[2])

    i = n

    m_a = list()
    m_b = list()

    while(i):

        l = input().split(" ")
        m_a.append([int(n) for n in l])

        i -= 1

    j = m

    while(j):

        l = input().split(" ")
        m_b.append([int(n) for n in l])

        j -= 1

    calc_matrix_prod(m_a, m_b)


Measured memory_bytes: 7152
# -*- coding: utf-8 -*-

import heapq

n, m = map(int, input().split())

work = [[] for _ in range(10**5+1)]
for i in range(n):
    ta, tb = map(int, input().split())
    work[ta].append(tb)

total = 0
cand = []

for d in range(1, m+1):
    for w in work[d]:
        #後で最大値を取り出したいので-1倍して追加
        #（複数の要素も一気にpush）
        heapq.heappush(cand, -w) 
        
    if len(cand) > 0:
        #-1倍して最大値として取得
        total += heapq.heappop(cand)*(-1) 
        
print(total)


Measured memory_bytes: 72608
import java.util.*;
public class Main {
    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
        int a[] = new int[n];
        long sum=0;
        
        for(int i=0; i<n; i++){
            a[i] = sc.nextInt();
            sum = sum + a[i];
        }
        
        if(sum == x){
            System.out.println(n);
        }else if(sum < x){
            System.out.println(n-1);
        }else{
            Arrays.sort(a);

            for(int i=0; i<n; i++){
                if(a[i]<=x){
                    x = x-a[i];
                }else{
                    System.out.println(i);
                    break;
                }
            }
        }
    }
}

Measured memory_bytes: 36024
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i=0; i<(long long)(n); i++)
#define REP(i, k, n) for(long long i=(long long)(k); i<(long long)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define PQ(T) priority_queue<T>
#define PQS(T) priority_queue<T, vector<T>, greater<T> >
#define deci cout << fixed << setprecision(15);
typedef long long ll;
const ll inf = 1020304050607080910;
const int INF = 1073741823;
const ll mod = 1000000007;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T> bool chmin(T&x,T y){if(x>y){x=y;return true;}return false;}
template<class T> bool chmax(T&x,T y){if(x<y){x=y;return true;}return false;}
ll gcd(ll x,ll y){if(x>y)swap(x, y);while(x!=0){y%=x;swap(x, y);}return y;}
ll mpow(ll x,ll r){if(r==0)return 1;if(r%2==1){return x*mpow(x,r-1)%mod;}else{ll aa=mpow(x,r/2);return aa*aa%mod;}}

int main(){
	ll N, M, K; cin >> N >> M >> K;
	vector<ll> suma(N), sumb(M);
	rep(i, N){
		ll a; cin >> a;
		if(i==0) suma[0] = a;
		else suma[i] = suma[i-1] + a;
	}
	rep(i, M){
		ll a; cin >> a;
		if(i==0) sumb[0] = a;
		else sumb[i] = sumb[i-1] + a;
	}
	ll ans = 0;
	rep(i, N+1){
		if(i==0){
			ll cnt = upper_bound(all(sumb), K) - sumb.begin();
			if(ans < cnt) ans = cnt;
		}else{
			if(K < suma[i-1]) break;
			ll s = K - suma[i-1];
			ll cnt = upper_bound(all(sumb), s) - sumb.begin();
			if(ans < cnt + i) ans = cnt + i;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 6424
import itertools
k = list(map(int, input().split()))
l = [list(map(int, input().split())) for i in range(k[2])]
m = [i+1 for i in range(k[1])]
n= list(itertools.combinations_with_replacement(m, k[0]))
now = 0
re = 0
for i in n:
  for x in l:
    if i[x[1] -1] - i[x[0] -1] == x[2]:
      re += x[3]
  now = max([now, re])
  re = 0

print(now)

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

#define REP( i, n )     for( int (i) = 0; (i) < (n); (i)++ )
#define ALL( a )        (a).begin(), (a).end()

using namespace std;
using ll = long long;
using P = pair<int, int>;

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( a > b ) { a = b; return 1; } return 0; }

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7;

ll d1[310][310];
int d2[310][310];

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

    fill( d1[0], d1[310], LINF );
    REP( i, N ) d1[i][i] = 0;

    REP( i, M ){
        int a, b, c; cin >> a >> b >> c;
        a--, b--;
        d1[a][b] = c;
        d1[b][a] = c;
    }


    REP( k, N ){
        REP( i, N ){
            REP( j, N ){
                chmin( d1[i][j], d1[i][k] + d1[k][j] );
            }
        }
    }

    fill( d2[0], d2[310], INF );
    REP( i, N ) d2[i][i] = 0;
    REP( i, N ){
        REP( j, N ){
            if( d1[i][j] <= L ) d2[i][j] = 1;
        }
    }

    REP( k, N ){
        REP( i, N ){
            REP( j, N ){
                chmin( d2[i][j], d2[i][k] + d2[k][j] );
            }
        }
    }

    int Q; cin >> Q;
    REP( i, Q ){
        int s, t; cin >> s >> t;
        s--, t--;
        if( d2[s][t] != INF ) cout << d2[s][t] - 1 << endl;
        else cout << -1 << endl;
    }

}


Measured memory_bytes: 1664
#include<iostream>
#include<cstdio>
#include<string>
#include<ctime>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<stack>
#include<climits>
#include<queue>
#include<map>
#include<set>
#include<sstream>
using namespace std;
typedef long long ll;   
typedef unsigned long long ull;
const int MAXN=5e5+5;
const ll p=1e9+7;
inline long long read()//inline 加速读入
{
	long long x=0;char c=getchar();//x代表返回值，c代表读取的字符
	while (c<'0'||c>'9') c=getchar();//读取所有非数部分
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();//如果读取的字符为数，加入返回值
	return x;
}
 inline void write(ll x)
 {
     char F[200];
      int tmp=x>0?x:-x ;
    if(x<0)putchar('-') ;
    int cnt=0 ;
       while(tmp>0)
       {
            F[cnt++]=tmp%10+'0';
            tmp/=10;
       }
       while(cnt>0)putchar(F[--cnt]) ;
 }
int NOf1(int n) 
{

	int c=0;
	for(int i = 0; i < 32; ++i){
		if(n & 1)
			++c;
		n >>= 1;
	}
	return c;
}
int gcd(int x, int y)
 {
     int MAX = max(x, y);
     int MIN = min(x, y);
     return MAX % MIN == 0? MIN : gcd(MIN, MAX % MIN);
 }
ll fac[MAXN]={1};
 // 快速幂求逆元
long long power_mod(long long a, long long b, long long c) {
    long long ans = 1;
    a %= c;
    while (b) {
        if (b & 1) {
            ans = ans * a % c;
        }
        b >>= 1;
        a = a * a % c;
    }
    return ans;
}
ll a[MAXN],k=0,n;
void dfs(long long x){
	if(x>1e10)return;
	a[++k]=x;
	for(ll i=max(ll(0),x%10-1);i<=min(ll(9),x%10+1);i++)
	dfs(x*10+i);
}
int main(){
	cin>>n;
	for(ll i=1;i<=9;i++)dfs(i);
	sort(a+1,a+k+1);
	cout<<a[n]<<endl;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  string ans="Yes";
  long long H, temp=0;
  for(int i=0; i<N; i++){
    cin >> H;
    temp=max(temp,H); 
//    cout<<"i:"<<i<<" H:"<<H<<" temp:"<<temp<<endl;
    if(H<temp-1){
      ans="No";
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
a=list(input())
b=list(input())
c=list(input())
d = {"a":a, "b":b, "c":c}
t=a[0]
for i in range(len(a+b+c)):
    if len(d[t])>0:
        t=d[t].pop(0)
    else:
        print(t.upper())
        break

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int prime(int x) {
	if (x < 2)return 0;
	else if (x == 2) return 1;
	if (x % 2 == 0) return 0;
	for (int i = 3; i*i <= x; i += 2) {
		if (x%i == 0) return 0;
	}
	return 1;
}
int main() {
	int a, d, n;
	while (scanf("%d %d %d",&a,&d,&n),a,d,n) {
		vector<int>v;
		for (int i = a; i <= 1000000; i+=d) {
			if (prime(i)) v.push_back(i);
		}
		 printf("%d\n",v[n-1]);
	}
}



Measured memory_bytes: 3644
attrs = Array.new
while line = $stdin.gets
    attrs << line.chomp.split.map{|v| v.to_i }
end

tmp = attrs.shift
N = tmp.shift
K = tmp.shift
Q = tmp.shift
A = attrs.flatten

# N は 1 から始まるが配列は 1 はじまりである点に注意
h = Hash.new
A.each do |i|
  if h[i] == nil then
    h[i] = 1
  else
    h[i] += 1
  end
end

for i in 0..(N - 1) do
    if h[i + 1] != nil then
        if (K - Q + h[i + 1]) > 0 then
            puts "Yes"
        else
            puts "No"
        end
    else
        if (K - Q) > 0 then
            puts "Yes"
        else
            puts "No"
        end
    end
end


Measured memory_bytes: 14844