akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<map>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
using namespace std;
long long int inf = 10000000000;

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

vector<long long int> rollinghash(string s, int a){
  int n = s.size();
  vector<long long int> rh(n+1, 0);
  for(int i=0; i<n; i++){
    rh[i+1] = rh[i] * a + s[i];
  }
  return rh;
}

int main(){
  string s, t;
  cin >> s >> t;
  int n = s.size();
  int m = t.size();
  vector<long long int> p(n+1, 0);
  p[0] = 1;
  long long int a = 1000000007;
  for(int i=0; i<n; i++){
    p[i+1] = p[i] * a;
  }

  vector<long long int> rhs = rollinghash(s, a);
  vector<long long int> rht = rollinghash(t, a);

  for(int i=0; i<n; i++){
    int l = i; int r = i + m - 1;
    if( rhs[r+1] - rhs[l] * p[r-l+1] == rht[m] ) cout << i << endl;
  }

  return 0;
}





// EOF

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

//定数
const long long MOD1=1000000007;
const long long MOD2=998244353;
const long double PI=3.1415926535897932;
const long long MAXLL=9223372036854775807;
const long long INF=2305843009213693951;
const long long dx[]={0,1,0,-1,1,-1,1,-1};
const long long dy[]={1,0,-1,0,1,1,-1,-1};

//型名省略
#define ll long long
#define ull unsigned long long
#define ld long double
#define uld unsigned long double
#define pll pair<long long,long long>
#define tll(n) array<long long,(int)(n)>
#define pcc pair<char,char>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<pair<long long,long long>>
#define vt(n) vector<array<long long,(int)(n)>>
#define umap unordered_map
#define uset unordered_set
#define Lqueue priority_queue<long long>
#define Squeue priority_queue<long long,vector<long long>,greater<long long>>
#define Fi first
#define Se second
#define mp make_pair
#define eb emplace_back

//マクロ
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rbf(a,x) for(auto& a:x)
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s);i<(long long)(n);i++)
#define bitrep(i,s,n) for(long long i=(s);i<(1LL<<(n));i++)
#define Maxe(x) *max_element((x).begin(),(x).end())
#define Mine(x) *min_element((x).begin(),(x).end())
#define Size(x) ((long long)(x).size())
#define lin(s) getline(cin,(s))

//Yes,No
void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
//YES.NO
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}

//MAX,MIN
template<class T,class U> auto max(T a,U b){return a>b?a:b;}
template<class T,class U> auto min(T a,U b){return a<b?a:b;}

//最大公約数,最小公倍数
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a,long long b){return a/gcd(a,b)*b;}

//累乗
template<typename t>
constexpr t mypow(t a,long long b){
    if(b==0)return 1;
    if(a==0)return 0;
    t x=1;
    while(b>0){
        if(b&1LL)x*=a;
        a*=a;
        b>>=1LL;
        }
    return x;
}
#define pow mypow

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

//組み合わせ O(r)
template<typename t>
constexpr t nCr(t n,long long r){
    if(r==0)return 1;
    if(n==0)return 0;
    if(n<r)return 0;
    t x=1;
    for(long long i=1;i<=r;i++){
        x*=n-i+1;
        x/=i;
    }
    return x;
}

//main関数
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    cin>>n;
    vl d(n);
    rep(i,n)cin>>d[i];
    sort(all(d));
    cout<<d[n/2]-d[n/2-1]<<endl;
}

Measured memory_bytes: 3972
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp(a, b) make_pair(a, b)
#define ls (rt << 1)
#define rs (rt << 1 | 1) 
typedef pair<int, int> pii; 
const ll mod = 1e9 + 7;
template <class T> T lowbit(T x){return ((x)&(-(x)));}
const int maxn = 2e5 + 10;
int x, y, na, nb, nc;
int a[maxn], b[maxn], c[maxn];
priority_queue<int, vector<int>, greater<int> > sa, sb;
int main()
{
	scanf("%d%d%d%d%d", &x, &y, &na, &nb, &nc);
	for(int i = 1; i <= na; ++i) 
	{
		scanf("%d", &a[i]);
		sa.push(a[i]);
		if(sa.size() > x) sa.pop();
	}
	for(int i = 1; i <= nb; ++i) 
	{
		scanf("%d", &b[i]);
		sb.push(b[i]);
		if(sb.size() > y) sb.pop();
	}
	for(int i = 1; i <= nc; ++i) 
	{
		scanf("%d", &c[i]);
		if(c[i] <= sa.top() && c[i] <= sb.top()) continue;
		else if(c[i] > sa.top() && c[i] > sb.top())
		{
			if(sa.top() <= sb.top())
			{
				sa.push(c[i]);
				sa.pop();
			}
			else
			{
				sb.push(c[i]);
				sb.pop();
			}
		}
		else if(c[i] > sa.top()) 
		{
			sa.push(c[i]);
			sa.pop();
		}
		else
		{
			sb.push(c[i]);
			sb.pop();
		}
	}
	ll ans = 0;
	while(!sa.empty())
	{
		ans += sa.top();
		sa.pop();
	}
	while(!sb.empty())
	{
		ans += sb.top();
		sb.pop();
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2296
import Data.Char

main = do
    w <- getLine
    s <- getContents
    putStrLn $ show $ (length . filter (== (toLowerAll w)))[(toLowerAll x) | x <- (concat . map words . lines) s, x /= f]
        where
            f = "END_OF_TEXT"
            toLowerAll :: String -> String
            toLowerAll s = map toLower s

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

int main(){
    int N , a , b;
    scanf( "%d%d%d" , &N , &a , &b );
    int Min = 10000 , Max = 0;
    int p , q , limit = min( a , b );

    for( int i = 0 ; i <= limit ; ++i ){
        p = a - i;
        q = b - i;

        if( p + q + i <= N ){
            Min = min( Min , i );
            Max = max( Max , i );
        }
    }

    printf( "%d %d\n" , Max , Min );
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,K;

    cin >> N >> K;
    vector<int> vec(N,0);

    int d;
    int a;
    for (int i = 0; i < K; i++)
    {
        cin >> d;
        for (int j = 0; j < d; j++)
        {
            cin >> a;
            vec.at(a-1) = 1;
        }
        
    }

    int num=0;

    for (int i = 0; i < vec.size(); i++)
    {
        if(vec.at(i)==0){
            num++;
        }
    }

    cout << num << endl;
    
    
}

Measured memory_bytes: 3580
#include<bits//stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n;i++)
ll n, m,sum = 1;
const int MAX = 510000;
const int MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];
void COMint() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll COM(ll n, ll k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    if(n > 510000) return n;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
    COMint();
    cin >> n >> m; vector<ll> a;
    if (m == 1) {
        cout << 1 << endl;
        return 0;
    }
    while (m % 2 == 0) {
        a.push_back(2);
        m /= 2;
    }
    for (ll i = 3; i <= m; i += 2) {
        if (m == 1) break;
        while (m % i == 0) {
            a.push_back(i);
            m /= i;
        }
    }
    ll fr = a[0],cnt =0;
    rep(i, a.size()) {
        if (a[i] == fr) cnt++;
        else {
            sum *= COM(n + cnt - 1, cnt);
            sum %= MOD;
            fr = a[i]; cnt = 1;
        }
    }
    sum *= COM(n + cnt - 1, cnt);
    cout << sum % MOD << endl;
}


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

int main(){
    int a, b;
    cin >> a >> b;
    if(a > 0){
        cout << "Positive";
    }else if(a == 0){
        cout << "Zero";
    }else{
        if(b < 0){
            if(abs(a-b)%2 == 0){
                cout << "Negative";
            }else{
                cout << "Positive";
            }
        }else{
            cout << "Zero";
        }
    }
    return 0;
}

Measured memory_bytes: 256
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <iostream>

class InsertionSort {
 public:
  InsertionSort();
  ~InsertionSort();
  void Main(std::istream &input_stream);

 private:
  void Sort();
  void SwapAndInsert(const int index_source);
  bool ShouldSwap(const int index_compare, const int cvalue);
  int SwapAndGetInsertPoint(const int index_compare);
  void Insert(const int index_insert_target, const int cvalue);
  void Load(std::istream &input_stream);
  void Print();

 private:
  int count_;
  int values_[100];
};

InsertionSort::InsertionSort() : count_(0), values_{-1} {}

InsertionSort::~InsertionSort() {}

void InsertionSort::Main(std::istream &input_stream) {
  Load(input_stream);
  Sort();
}

void InsertionSort::Sort() {
  for (int index_source = 1; index_source < count_; ++index_source) {
    Print();
    SwapAndInsert(index_source);
  }
  Print();
}

void InsertionSort::SwapAndInsert(const int index_source) {
  int cvalue = values_[index_source];
  int index_insert_target = index_source;
  for (int index_compare = index_source - 1; index_compare >= 0; --index_compare) {
    if (ShouldSwap(index_compare, cvalue)) {
      index_insert_target = SwapAndGetInsertPoint(index_compare);
    } else {
      break;
    }
  }
  Insert(index_insert_target, cvalue);
}

bool InsertionSort::ShouldSwap(const int index_compare, const int cvalue) {
  return (values_[index_compare] > cvalue);
}

int InsertionSort::SwapAndGetInsertPoint(const int index_compare) {
  values_[index_compare + 1] = values_[index_compare];
  const int index_insert_target = index_compare;
  return index_insert_target;
}

void InsertionSort::Insert(const int index_insert_target, const int cvalue) {
  values_[index_insert_target] = cvalue;
}

void InsertionSort::Load(std::istream &input_stream) {
  input_stream >> count_;
  for (int index = 0; index < count_; ++index) {
    input_stream >> values_[index];
  }
}

void InsertionSort::Print() {
  for (int index = 0; index < count_; ++index) {
    if (index != 0) {
      std::cout << " ";
    }
    std::cout << values_[index];
  }
  std::cout << std::endl;
}

int main(int argc, char *argv[]) {
  InsertionSort *insertion_sort_ = new InsertionSort();
  insertion_sort_->Main(std::cin);
  delete insertion_sort_;
  return 0;
}




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

int main(){
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  // 入力値の受け取り
  int dx, dy;
  dx = x2 - x1;
  dy = y2 - y1;
  cout << (x2 - dy) << " " << (y2 + dx) << " ";
  cout << (x2 - dy - dx) << " " << (y2 + dx - dy) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Graph= vector<vector<ll>>;
struct edge{ll to ; ll cost ;} ;
using graph =vector<vector<edge>> ;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second 
#define set20 cout<<fixed<<setprecision(20) ;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
double pi=acos(-1) ;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main(){
  ll h,w,k ;cin>>h>>w>>k ;
  char d[h][w] ;
  rep(i,h){
      rep(j,w) cin>> d[i][j] ;
  }
  ll ans=0 ;
  for(int temp =0 ; temp<(1<<(h+w)) ;temp++ ){
     bitset<13>  s(temp) ;
     ll res= 0;
     rep(i,h){
         rep(j,w){
          if(s[i]==0&&s[j+h]==0&&d[i][j]=='#')
          res++ ;
         }
     }
    if(res==k) ans++ ;
  }
  cout<<ans<<endl ;
 return 0 ; 
}



Measured memory_bytes: 3620
#include <iostream>
#include <map>
using namespace std;
int main() {
  map<int, int> m;
  for (int i = 2; i < 100; i++) {
    bool p = true;
    for (int j = 2; j * j <= i; j++) {
      if (i % j == 0) p = false;
    }
    if (p) m[i] = 0;
  }
  int n; cin >> n;
  for (int i = 2; i <= n; i++) {
    int ii = i;
    for (auto x: m) {
      while (ii % x.first == 0) {
        m[x.first]++;
        ii /= x.first;
      }
    }
  }
  int ans = 0;
  for (auto i: m)
  for (auto j: m)
  for (auto k: m) {
    if (i.first == j.first || j.first == k.first || k.first == i.first) continue;
    if (i.first > j.first) continue;
    if (i.second >= 4 && j.second >= 4 && k.second >= 2) ans++;
  }
  for (auto i: m)
  for (auto j: m) {
    if (i.first == j.first) continue;
    if (i.second >= 24 && j.second >= 2) ans++;
    if (i.second >= 14 && j.second >= 4) ans++;
  }
  for (auto i: m) {
    if (i.second >= 74) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;
using ll = long long int;
#define long ll

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

    string s;
    cin >> s;
    ll n = s.size();

    vector<ll> pos = {n};
    {
        set<char> st;
        for(ll i=n-1; i>=0; i--) {
            st.insert(s[i]);
            if(st.size() == 26) {
                st.clear();
                pos.push_back(i);
            }
        }
    }

    string r;
    {
        ll i = 0;
        if(pos.back() == 0) {
            r += 'a';
            while(i < n && s[i++] != 'a');
            pos.pop_back();
        }

        while(i < n) {
            set<char> st;
            while(i < pos.back()) st.insert(s[i++]);
            pos.pop_back();

            char c;
            for(c='a'; c<='z'; c++)
                if(!st.count(c)) break;

            while(i < n && s[i++] != c);
            r += c;
        }
    }
    cout << r << endl;

}


Measured memory_bytes: 720
#include <iostream>
#include<algorithm>

using namespace std;

int main()
{
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	if (a[0] + a[1] == a[2])cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
N = int(input())

w = input().strip()
d = set([w])
l = w[-1]
f = True
for _ in range(N-1):
    w = input().strip()
    if w.startswith(l) and not w in d:
        d.add(w)
        l = w[-1]
    else:
        f = False
print("Yes" if f else "No")


Measured memory_bytes: 9112
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

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

int main(){
	int n;
	ll sum = 0;
	cin>>n;
	rep(i, n){
		int x;
		cin>>x;
		sum +=x;
	}
	cout <<(sum)/n<<endl;
	return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cassert>
#include <cinttypes>

using namespace std;

typedef int64_t ll;
typedef uint64_t ull;

typedef pair<int, int> P;
inline P operator+(const P& p1, const P& p2) {
  return P(p1.first + p2.first, p1.second + p2.second);
}


int main(){
  int n;
  cin >> n;
  vector<int> a(n);

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

  int cnt = 0;
  vector<P> op;
  
  int abs_max_idx = 0;
  for (int i = 1; i < n; i++) {
    if (abs(a[abs_max_idx]) < abs(a[i])) {
      abs_max_idx = i;
    }
  }
  
  for (int i = 0; i < n; i++) {
    a[i] += a[abs_max_idx];
    cnt++;
    op.push_back(P(abs_max_idx, i));
  }

  if (a[0] >= 0) {
    for (int i = 0; i < n - 1; i++) {
      cnt++;
      a[i + 1] += a[i];
      op.push_back(P(i, i + 1));
    }
  } else {
    for (int i = n - 1; i > 0; i--) {
      cnt++;
      a[i - 1] += a[i];
      op.push_back(P(i, i - 1));
    }
  }

  cout << cnt << endl; 
  for (int i = 0; i < cnt; i++) {
    cout << op[i].first + 1 << " " << op[i].second + 1 << endl;
  }
 
  cerr << "========" << endl;
  for (int i = 0; i < n; i++) {
    cerr << a[i] << " ";
  }
  cerr << endl;


  
  return 0;
}

/* */

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

int main(){
	scanf("%lld%lld", &l, &r);
	if(r-l+1 >= 2019) return 0*puts("0");
	for(long long i = l; i < r; i++){
		for(long long j = i+1; j <= r; j++){
			ans = min(i*j%2019, ans);
		}
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long X, Y;
    cin >> X >> Y;
    int cnt = 1;
    X *= 2;
    while(X <= Y){
        cnt++;
        X *= 2;
    }
    cout << cnt << '\n';
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##_len=(int)(n);i<i##_len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define REPW(i,n) for(i=0;i<(int)(n);++i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : " "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
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;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

signed main() {
    vector<int> c(300,INF);
    int n;
    cin>>n;
    REP(i,n) {
        string s;
        cin>>s;
        vector<int> tmp(300,0);
        FORE(x,s) tmp[x]++;
        REP(j,300) chmin(c[j],tmp[j]);
    }
    string ans;
    REPF(x,'a','z'+1) {
        if(c[x]>0) REP(i,c[x]) ans+=x;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
//From Naruto to Hokage
//#include <RJ>
#include<bits/stdc++.h>
using namespace std;

#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
void solve(){
    ll n,w,ans=0;
    ll wei,val;
    cin>>n>>w;
    ll dp[n+1][w+1];
    memset(dp,0,sizeof(dp));
    rep(i,1,n){
        cin>>wei>>val;
        rep(j,0,w){
            dp[i][j]=dp[i-1][j];
            if(j-wei>=0) dp[i][j]=max(dp[i][j],val+dp[i-1][j-wei]);
            ans=max(ans,dp[i][j]);
        }
    }
    // rep(i,1,n) rep(j,1,w) cout<<dp[i][j]<<" \n"[j==w];
    cout<<ans;
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}

Measured memory_bytes: 79232
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <ctype.h>
#include <algorithm>
#include <cmath>
 
#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define square(x) (x) * (x)
 
const int INF = 1e9;
 
using namespace std;
 
int main() {
    int n;
    int s;
    stringstream result;
    result << setprecision(10);
    while(1) {
        long double total = 0;
        long double sqtotal = 0;
        long double v;
        cin >> n;
        if (!n)
            break;
        REP(i, n) { cin >> s; total += s; sqtotal += square(s); }
        v = sqtotal / n - square(total/n);
        result << sqrt(v) << endl;
    }
    cout << result.str();
 
    return 0;
}

Measured memory_bytes: 1284
#include<stdio.h>
#include<algorithm>
using namespace std;
typedef long long ll;
const int inf=2000000000;
struct edge{
	int x,y,v;
	edge(int a=0,int b=0,int c=0){x=a;y=b;v=c;}
}e[400010];
bool operator<(edge a,edge b){return a.v<b.v;}
int m[200010],fa[200010];
int get(int x){return fa[x]==x?x:(fa[x]=get(fa[x]));}
int main(){
	int n,q,M,i,a,b,c;
	ll ans;
	scanf("%d%d",&n,&q);
	for(i=0;i<n;i++)m[i]=inf;
	while(q--){
		scanf("%d%d%d",&a,&b,&c);
		M++;
		e[M]=edge(a,b,c);
		m[a]=min(m[a],c+1);
		m[b]=min(m[b],c+2);
	}
	for(i=0;i<n;i++)m[(i+1)%n]=min(m[(i+1)%n],m[i]+2);
	for(i=0;i<n;i++)m[(i+1)%n]=min(m[(i+1)%n],m[i]+2);
	for(i=0;i<n;i++){
		M++;
		e[M]=edge(i,(i+1)%n,m[i]);
	}
	for(i=0;i<n;i++)fa[i]=i;
	sort(e+1,e+M+1);
	ans=0;
	for(i=1;i<=M;i++){
		a=get(e[i].x);
		b=get(e[i].y);
		if(a!=b){
			fa[a]=b;
			ans+=e[i].v;
		}
	}
	printf("%lld",ans);
}

Measured memory_bytes: 9472
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <algorithm>
#include <cassert>

using namespace std;


int ans = 0;
void dfs(vector<vector<int> > &a, int x, int y){
	ans++;
	a[x][y] = 0;
	if(a[x-1][y]) dfs(a, x-1, y);
	if(a[x][y-1]) dfs(a, x, y-1);
	if(a[x+1][y]) dfs(a, x+1, y);
	if(a[x][y+1]) dfs(a, x, y+1);
//	return res;		//テ」ツ?ゥテ」ツ??」ツつ?」ツつ凝」ツつ禿」ツ??」ツつ催」ツ??」ツ??、ツサツ甘・ツコツヲ
}

bool solve(){

	while(1){
		ans = 0;
		
		int w,h;
		cin>> w>> h;
		if(w==0 && h==0) break;
		
		vector<vector<int> > a(h+2, vector<int> (w+2,0));
		complex<int> p;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				char in;
				cin>> in;
				if(in == '#') a[i+1][j+1] = 0;
				if(in == '.') a[i+1][j+1] = 1;
				if(in == '@'){
					a[i+1][j+1] = 2;
					p.real() = i+1;
					p.imag() = j+1;
				}
			}
		}
/*		for(int i=0;i<h+2;i++){
			for(int j=0;j<w+2;j++){
				cout<< a[i][j];
			}
			cout<< endl;
		}
*/		
		dfs(a, p.real(), p.imag());
		
		cout<< ans<< endl;
	}
	
	
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	solve();

	return 0;
}

 

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

 using namespace std;
 typedef long long ll;

 int main() {
   int sx, sy, tx, ty;

   cin >> sx >> sy >> tx >> ty;

   for (int i = 0; i < tx - sx; i++) cout << "R";
   for (int i = 0; i < ty - sy; i++) cout << "U";
   for (int i = 0; i < tx - sx; i++) cout << "L";
   for (int i = 0; i < ty - sy; i++) cout << "D";
   cout << "D";
   for (int i = 0; i < tx - sx + 1; i++) cout << "R";
   for (int i = 0; i < ty - sy + 1; i++) cout << "U";
   cout << "LU";
   for (int i = 0; i < tx - sx + 1; i++) cout << "L";
   for (int i = 0; i < ty - sy + 1; i++) cout << "D";
   cout << "R" << endl;
 }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long int Mod=1e9+7;
long long  dp[3005][3005];

int main()
{
    long long  n,i,j,gap,k,sum=0;
    cin>>n;
    long long A[n],B[n];
    for(i=0;i<n;i++)
    {
        cin>>A[i];
        sum+=A[i];
        B[i]=sum;
    }
    long long dp[n][n];
    memset(dp,0,sizeof(dp));
    for(i=0;i<n-1;i++)
    {
        dp[i][i+1]=A[i]+A[i+1];
    }
    
    for(gap=3;gap<=n;gap++)
    {
        for(i=0;i<n-gap+1;i++)
        {
            j = i+gap-1;
            dp[i][j]=1e18;
            for(k=i;k<=j-1;k++)
            {
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+B[j]-B[i]+A[i]);
            }
        }
    }
    cout<<dp[0][n-1]<<endl;
return(0);
}

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

#define ll long long int
#define db double
#define fl float
#define endl '\n'

#define mod (ll)(1000000007)
#define mod1 (ll)998242353
#define mod2 (ll)998244353
#define PI 3.1415926535897932384626433832795

#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp(x,y) make_pair(x,y)
#define pb push_back
#define pob pop_back

#define Sort(v) sort(v.begin(),v.end())
#define Sortd(v) sort(v.begin(),v.end(),greater<>())

#define f(i,n) for(int i=0;i<n;i++)
#define f1(i,n) for(int i=1;i<n;i++)
#define rf(i,n) for(int i=n-1;i>=0;--i)
#define rf1(i,n) for(int i=n-1;i>=1;--i)
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repn(i,a,b) for(int i=a;i<=b;++i)

#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<vi> vvi;
typedef priority_queue<int> pqi;
typedef priority_queue<ll> pql;

//nC2
ll C2(ll n){
    ll ans= max(((n*(n-1))/2),(ll)0);
    return ans;
}
//square
ll sq(ll n){
    return n*n;
}

//GCD
ll gcd(ll a,ll b){
    if(a<b){
        swap(a,b);
    }
    if(b==0){
        return a;
    }    
    else{
        return gcd(b,a%b);
    }
}

//LCM
ll lcm(ll a,ll b){
    if(a==0 || b==0){
        return 0;
    }
    else{
        return((ll)((a*b)/gcd(a,b)));
    }
}

//sort pair by second values
bool sortsec(const pair<ll,ll> &a, const pair<ll,ll> &b){ 
    return (a.second < b.second); 
}
//sort pair by first vals in descending
bool sortinrev(const pair<ll,ll> &a, const pair<ll,ll> &b){ 
    return (a.first > b.first); 
} 

//Binary Exponentiation
ll BinExp(ll a, ll b, ll m){
    a%=m;
    ll res =1;
    while(b>0){
        if(b&1){
            res = (res * a)%m;
        }
        a=(a*a)%m;
        b>>=1;
    }
    return res;
}


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

    int n;
    cin>>n;
    int a[n];
    f(i,n)cin>>a[i];
    sort(a,a+n);
    int cnt=0;
    f(i,n){
        rep(j,i+1,n){
            if(a[i]!=a[j]){
                rep(k,j+1,n){
                    if(a[j]!=a[k]){
                        if(a[i]+a[j]>a[k])cnt++;
                    }                    
                }
            }
        }

    }
    cout<<cnt<<endl;
    


    return 0;
}



Measured memory_bytes: 3652
//已經把每個城市彼此的最短路程給你(所以佛洛伊德的K點是不會實現的)
//佛洛伊德最短路徑變化題 
#include<iostream>
#include<vector>
using namespace std;
typedef pair<int, int> pii;//放入不會經過的路 
int road[300][300];
 
long long warshall(int n){
    long long ans;
    vector<pii> a;
    for(int k=0;k<n;k++)
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
            {
                if(road[i][j]>road[i][k]+road[k][j]){
                    return -1;//如果出現了K點，回傳-1 
                }
                else if(road[i][j]==road[i][k]+road[k][j]&&i!=k&&k!=j)
                    a.push_back(make_pair(i,j));//如果有一樣路程的路，把他放進a，等等刪掉 
            }
    ans = 0;
    for(size_t i =0;i<a.size();i++)//* vector要用size_t 因為vector的函釋回傳值是unsing int ( = size_t 
        road[a[i].first][a[i].second] = 0;//讓這個重複路段變成0 
 
    /*for(int i=0;i<n;i++){
        for(int j=0;j<n;j++)
            cout<<road[i][j]<<" ";
        cout<<endl;
    }*/
    for(int i=0;i<n;i++)
        for(int j=i+1;j<n;j++)
            ans += road[i][j];//所有路段加起來 
 
    return ans;
}
 
 
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++)
            cin>>road[i][j];
    }
    cout<<warshall(n)<<endl;
}

Measured memory_bytes: 34020
#include<bits/stdc++.h>
using namespace std;
string str;
int ans=0;
void Solve(){
    cin>>str;
    int a=0,b=0;
    for(int i=0;i<str.size();i++){
        if(str[i]=='1') a++; 
    }
    b=str.size()-a;
    ans=min(a,b)*2;
    cout<<ans<<endl;
}
int main(){
    Solve();
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define EPS 1e-8
#define DEB 0

const int dx[] = {0,1,0,-1};
const int dy[] = {-1,0,1,0};
int w,h,sx,sy,home,last;
int field[16][16];
int num[16][16];

#if DEB
stack<int> st;
#endif

class state{
public:
  char x,y;
  int s;
  state(char _x, char _y, int _s){
    x = _x;
    y = _y;
    s = _s;
  }
  
  bool operator<(const state& a)const{
    if( x==a.x ){
      if( y==a.y ) return s<a.s;
      else         return y<a.y;
    }else{
      return x<a.x;
    }
  }
  
};


map<state,int> msi;

bool ischeck(int s){
  return (((last&s)) == last) ;
}
bool inside(int x, int y){
  return (x<0 || y<0 || x>=w || y>=h);
}


int dfs(int x, int y, int s){
  if( (1<<home)-1 == s ){ // ÆÍ³ïÉßêé©Ç¤©
    /*
    rep(k,4){
      for(int i=1; i<20; i++){
	int tx = x + dx[k]*i;
	int ty = y + dy[k]*i;
	//if( inside(tx,ty) || field[ty][tx]==1 )break;
	if( inside(tx,ty) )break;

	if( field[ty][tx]==2 ){
#if DEB
	  printf("goal , (%d,%d)  s:%d\n",x,y,s);
	  stack<int> tmp = st;
	  while( !tmp.empty() ){
	    printf("%d,",tmp.top());
	    tmp.pop();
	  }
	  puts("\n");
#endif
	  return 1;
	}
      }
    }
    return 0;
    */
    return 1;
  }
  if( msi.count(state(x,y,s)) ){ //ùÉÊÁ½ê
    return msi[state(x,y,s)];
  }
  if( ischeck(s) ){
    return 0;
  }
  
  int ret = 0;
  rep(k,4){
    for(int i=1; i<20; i++){
      int tx = x + dx[k]*i;
      int ty = y + dy[k]*i;
      if( inside(tx,ty) ) break;
      if( field[ty][tx]==1 ){
	//if( s&(1<<num[ty][tx]) ) break;	
	field[ty][tx] = 0;
#if DEB
	st.push(num[ty][tx]);
#endif 
	ret += dfs(tx,ty,s|(1<<num[ty][tx]));
#if DEB
	st.pop();
#endif
	field[ty][tx] = 1;
	break;
      }
    }
  }
  msi[state(x,y,s)] = ret;
  return ret;
}

int main(){

  while(scanf("%d%d",&w,&h),w|h){
    msi.clear();
    memset(num,-1,sizeof(num));
    home = last = 0;
    rep(i,h){
      rep(j,w){
	scanf("%d",&field[i][j]);
	if( field[i][j]==2 ){
	  sx = j;
	  sy = i;
	}
	if( field[i][j]==1 ){
	  num[i][j] = home;
	  home++;
	}
      }
    }

    //last homes
    rep(k,4){
      for(int i=1; i<20; i++){
	int tx = sx + dx[k]*i;
	int ty = sy + dy[k]*i;
	if( inside(tx,ty) )break;
	if( field[ty][tx]==1 ){
	  last |= (1<<num[ty][tx]);
	}
      }
    }
#if DEB
    printf("home:%d  sx,sy = %d,%d\n",home,sx,sy);
    printf("last:%d\n",last);
    rep(i,h){
      rep(j,w){
	printf("%2d ",num[i][j]);
      }
      puts("");
    }
#endif   
    dfs(sx,sy,0);
    printf("%d\n",msi[state(sx,sy,0)]);
  }
  

  return 0;
}

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

int main()
{
    long long  n , m , x;

    cin >> n >> m >> x;

    for(int i = 0 ; i<=n ; i++)
    {
        for(int j = 0 ; j<=m ; j++)
        {
            if(x==i*(m-j)+j*(n-i))
            {
                cout << "Yes\n";
                return 0;
            }
        }
    }
    cout << "No\n";
    return 0;
}


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

typedef long long int ll ;

ll gcd(ll aaa,ll bbb) {
    if(bbb==0) {
        return aaa;
    }
    return gcd(bbb,aaa%bbb);
}

ll lcm(ll m,ll n)
{
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;

    return ((m / gcd(m, n)) * n);
}

int main() { 
	
	int A,B,C;
	cin >> A>> B >> C;

	cout << min(B/A,C) << endl;

	return 0;
}


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

int main(){
  long long int x;
  cin >> x;
  long long int y=0,z=0,ans=0;
  if(x>=500){
    y=x%500;
    z=(x-y)/500;
    ans+=1000*z;
    x=y;
    y=0;
    z=0;
  }
  if(x>=5){
    y=x%5;
    z=(x-y)/5;
    ans+=5*z;
  }
   cout << ans << endl;
}

Measured memory_bytes: 256
/*
    author: Salam_35
    Created at :

*/

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

#define ll long long int
#define pb push_back
#define sc(n) scanf("%d",&n)
#define maxs 1000005
#define scan(n) scanf("%lld",&n)
#define pi acos(-1.0)
#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ALL(x) x.begin(),x.end()
#define sci(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define load(array,size)  for(ll i=0 ; i<size ; i++) cin>>array[i] ;
#define load1(array,size)  for(ll i=1 ; i<=size ; i++) cin>>array[i] ;
#define INF	1LL<<19
#define pll pair<ll,ll>
#define mst(arr,value) memset(arr,value,sizeof(arr));
#define tst() int t;cin >> t;while(t--)
#define Mod 100000007
#define YES cout<<"Yes"<<endl;
#define NO cout<<"No"<<endl;
void inversemod(ll n, ll mod, ll invmod[],ll MOD){for(int i=2; i<=n; ++i) invmod[i]=MOD-MOD/i*invmod[MOD%i]%MOD;}
//void bigmod( ll a, ll b ,ll mod){ll r = 1;a = a%mod;while(b){if( b%2 ) r = (r*a)%mod;b = b/2;a = (a*a)%mod; }return (ll)r;}

typedef vector<ll>vec;
typedef pair<ll,ll> pii;
typedef map<ll,ll>mpll;
typedef set<ll>seet;

int l[2*maxs],r[2*maxs];
int n;

int arr[maxs];
int main()
{

    ll s;
  cin >> s;
  int a=s/500;
 	ll sum=(a*1000);
  s%=500;
  a=s/5;
  sum+=a*5;
  cout<<sum<<endl;
}




Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

int solve(int a, int b, int n) {
	int ret = 0;

	a %= b;
	rep(loop, n) {
		a *= 10;
		ret += a / b;
		a %= b;
	}
	return ret;
}

int main() {
	int a, b, n;
	while (cin >> a >> b >> n) {
		Cout(solve(a, b, n));
	}
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
int main(){
    int K;
    string S;
    cin >> K >> S;

    if(S.size()>K){
        for(int i=0;i<K;i++){
            cout << S.at(i);
        }
        cout << "...";
    } else {
        cout << S;
    }
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
#define ll          long long int
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define Max(a,b)    ((a)>(b)?(a):(b))
#define Min(a,b)    ((a)<(b)?(a):(b))
#define rep(i,a,b)  for (__typeof((b)) i=(a);i<(b);i+=1)
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define endl        '\n'
#define debug(a)    cerr<<#a<<": ";for(auto i:a)cerr<<i<<" ";cerr<<'\n';
using namespace std;

void solve(){
    ll N,L;
    cin>>N>>L;
    vector<ll>x(N);
    rep(i,0,N){
        cin>>x[i];
    }
    bool isGood=false;
    int j=-1;
    rep(i,0,N-1){
        if(x[i]+x[i+1]>=L){
            j=i;
            isGood=true;
            break;
        }
    }
    if(!isGood){
        cout<<"Impossible";
        return;
    }
    cout<<"Possible\n";
    int nobreak=j+1;
    rep(i,1,nobreak){
        cout<<i<<endl;
    }
    for(int i=N-1;i>=nobreak;i--)cout<<i<<endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t=1;
//	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 1664
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>

using std::vector;
using std::map;
using std::set;
using std::string;
using std::pair;
using std::cin;
using std::cout;
using std::min;
using std::max;

// @author: pashka

vector<int> p;
vector<vector<int>> st;

int getMin(int l, int r) {
    int d = r - l;
    if (d % 2 == 1) {
        r++;
        d++;
    }
    int k = 0;
    while ((1 << (k + 1)) <= d) k++;
    int x = st[k][l];
    int y = st[k][r - (1 << k)];
//    cout << l << " " << r << " " << k << " " << x << " " << y << "\n";
    if (p[x] < p[y]) return x;
    else return y;
}

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

    int n;
    cin >> n;

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

    int k = 0;
    while ((1 << k) <= n) k++;

    st.resize(k);

    for (int i = 0; i < k; i++) {
        st[i].resize(n);
        for (int j = 0; j < n; j++) {
            if (i <= 1) {
                st[i][j] = j;
            } else {
                st[i][j] = st[i - 1][j];
                int jj = j + (1 << (i - 1));
                if (jj < n) {
                    if (p[st[i - 1][jj]] < p[st[i - 1][j]]) {
                        st[i][j] = st[i - 1][jj];
                    }
                }
            }
        }
    }

    vector<int> res;
    set<pair<int, pair<int, int>>> ss;

    ss.insert({p[getMin(0, n)], {0, n}});

    while (ss.size() > 0) {
        pair<int, pair<int, int>> pp = *(ss.begin());
        ss.erase(ss.begin());

        int l = pp.second.first;
        int r = pp.second.second;


        int x = getMin(l, r);
        int y = getMin(x + 1, r);

//        cout << l << " " << r << " " << p[x] << " " << p[y] << "\n";

        res.push_back(p[x]);
        res.push_back(p[y]);

        if (x > l) {
            ss.insert({p[getMin(l, x)], {l, x}});
        }
        if (y > x + 1) {
            ss.insert({p[getMin(x + 1, y)], {x + 1, y}});
        }
        if (r > y + 1) {
            ss.insert({p[getMin(y + 1, r)], {y + 1, r}});
        }
    }

    for (int i = 0; i < n; i++) {
        cout << res[i] << " ";
    }
    cout << "\n";

    return 0;
}



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

struct Team
{
	vector<bool> is_solve;
	vector<int> WA;
	int team_id, time, solved;
	Team(){}
	Team(int P, int id)
	{
		is_solve = vector<bool>(P, false);
		WA = vector<int>(P, 0);
		team_id = id;
		time = 0;
		solved = 0;
	}
};
bool operator<(const Team &a, const Team &b)
{
	if (a.solved == b.solved)
	{
		if (a.time == b.time)
		{
			return a.team_id > b.team_id;
		}
		return a.time < b.time;
	}
	return a.solved > b.solved;
}
bool operator==(const Team &a, const Team &b)
{
	return a.solved == b.solved && a.time == b.time;
}

void solve()
{
	int M, T, P, R;
	while (cin >> M >> T >> P >> R, M)
	{
		vector<Team> v;
		for (int i = 0; i < T; i++)
		{
			v.push_back(Team(P, i));
		}

		for (int i = 0; i < R; i++)
		{
			int m, t, p, j;
			cin >> m >> t >> p >> j;
			t--; p--;
			if (j == 0){
				for (int k = 0; k < v.size(); k++)
				{
					if (v[k].team_id == t)
					{
						v[k].is_solve[p] = true;
						v[k].solved++;
						v[k].time += m;
						v[k].time += 20 * v[k].WA[p];
						break;
					}
				}
			}
			else
			{ 
				for (int k = 0; k < v.size(); k++)
				{
					if (v[k].team_id == t)
					{
						v[k].WA[p]++;
						break;
					}
				}
			}
		}

		sort(v.begin(), v.end());
		for (int i = 0; i < v.size(); i++)
		{
			if (i)
			{
				bool flag = (v[i - 1] == v[i]);
				cout << (flag ? "=" : ",");
			}
			cout << v[i].team_id + 1;
		}
		cout << endl;
	}
}

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

Measured memory_bytes: 1264
#include <cstdio>
#include <stack>
#include <set>
#include <cmath>
#include <map>
#include <time.h>
#include <vector>
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
//#include <memory.h>
#include <cstdlib>
#include <queue>
#include <iomanip>
#include <cassert>
#include <unordered_map>
#define P pair<int, int>
#define LL long long
#define LD long double
#define PLL pair<LL, LL>
#define mset(a, b) memset(a, b, sizeof(a))
#define rep(i, a, b) for (int i = a; i < b; i++)
#define PI acos(-1.0)
#define random(x) rand() % x
#define debug(x) cout << #x << " " << x << "\n"
using namespace std;
const int inf = 0x3f3f3f3f;
const LL __64inf = 0x3f3f3f3f3f3f3f3f;
#ifdef DEBUG
const int MAX = 2e3 + 50;
#else
const int MAX = 1e6 + 50;
#endif
const int mod = 1e9 + 9;
void file_read() {
#ifdef DEBUG
	freopen("in", "r", stdin);
	// freopen("out", "w", stdout);
#endif
}

int main() {
	file_read();
	string s, t;
	cin >> s >> t;
	int ans = inf;
	for(int i = 0; i + t.size() - 1 < s.size(); i++) {
		int cnt = 0;
		for(int j = 0; j < t.size(); j++) {
			cnt += t[j] != s[i+j];
		}
		ans = min(ans, cnt);
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 3692
import math

N, A, B = map(int, input().split())
h = [int(input()) for _ in range(N)]


def check(t):
    cnt = 0
    ab = A - B
    bt = B * t
    for i in range(N):
        r = (h[i] - bt)
        if r <= 0:
            continue
        cnt += r // ab
        if r % ab:
            cnt += 1
    return cnt <= t


left = 1
right = max(h)
while right - left > 1:
    mid = (left + right) // 2
    if check(mid):
        right = mid
    else:
        left = mid
print(right)


Measured memory_bytes: 7068
n = int(input())
list_a = [int(input()) for _ in range(n)]

count = 0
next_button = 0
while count <= 10 ** 5:
  count += 1
  next_button = list_a[next_button] - 1
  if next_button == 1:
    print(count)
    exit()
print(-1)

Measured memory_bytes: 7084
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <numeric>
#include <random>
#include <bitset>
#include <chrono>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

#ifndef ONLINE_JUDGE
// #include "debug.h"
#else
// #define debug(...) 42
#endif

const int M = 1e3+5;
const int MD= 1e9+7;

map<int,int>mp;
int main() {
	fast_cin();
	int t=1;
	// cin>>t;
	while(t--)
	{
		ll pro=1,sum=0,res=0;
		string s;
		cin>>s;
		int n=s.length();
		mp[0]++;
		for(int i=n-1;i>=0;i--){
			sum=(sum+pro*(s[i]-'0'))%2019;
			res+=mp[sum];
			mp[sum]++;
			pro=(pro*10)%2019;
		}
		cout<<res<<"\n";
	}
	return 0;
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
typedef long long ll;
int main() {
  int N , M;
  cin >> N >> M ;
  priority_queue<int> q;
  rep(i,N){
    int A ;
    cin >> A ;
    q.push(A) ;
  }
    rep(i,M){
      int a = q.top();
      q.pop();
      q.push(a/2);
    }
  ll ans = 0 ;
  rep(i,N){
    ans+= q.top();
    q.pop();
  }
  cout << ans << endl;
}


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

#define int long long

int32_t main()
{
    ios_base::sync_with_stdio(false),cin.tie(nullptr);
    int n=0;
    cin>>n;
    vector<int> v(n);
    for(int i=0;i<n;i++) cin>>v[i];

    vector<int> pre(n+1,0);
    for(int i=0;i<n;i++) pre[i+1]=pre[i]+v[i];

    vector<vector<int>> dp(n+1,vector<int> (n+1,0));
    
    for(int i=1;i<=n;i++) dp[i][i]=v[i-1];

    for(int d=1;d<n;d++)
    {
        for(int i=1;i+d<=n;i++)
        {
            int j=i+d;
            dp[i][j]=numeric_limits<int>::max();
            for(int k=i;k<j;k++)
            {
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]);
            }
            dp[i][j]+=pre[j]-pre[i-1];
        }
    }

    cout<<dp[1][n]-pre[n];
    return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <string>

struct Node {
    Node *left = nullptr, *right = nullptr;
    int value;
};

int main() {
    int n;
    std::cin >> n;
    
    Node fst, lst;
    Node *first = &fst, *last = &lst;
    first->right = last;
    last->left = first;
    
    std::string str = "";
    int q;
    for (int i=0; i<n; i++) {
        std::cin >> str;
        if ( str == "insert" ) {
            std::cin >> q;
            Node *new_node = new Node;
            new_node->value = q;
            Node *second = first->right;
            first->right = new_node;
            new_node->left = first;
            new_node->right = second;
            second->left = new_node;
        } else if ( str == "delete" ) {
            std::cin >> q;
            Node *current_node = first->right;
            while( current_node->right ) {
                if ( current_node->value == q ) {
                    current_node->left->right = current_node->right;
                    current_node->right->left = current_node->left;
                    delete current_node;
                    break;
                }
                current_node = current_node->right;
            }
        } else if ( str == "deleteFirst" ) {
            Node *to_be_deleted = first->right;
            to_be_deleted->left->right = to_be_deleted->right;
            to_be_deleted->right->left = to_be_deleted->left;
            delete to_be_deleted;
        } else if (  str == "deleteLast") {
            Node *to_be_deleted = last->left;
            to_be_deleted->left->right = to_be_deleted->right;
            to_be_deleted->right->left = to_be_deleted->left;
            delete to_be_deleted;
        }
    }
    
    Node *current_node = first->right;
    while( current_node->right != last ) {
        std::cout << current_node->value << " ";
        current_node = current_node->right;
    }
    std::cout << current_node->value <<  std::endl;
}

Measured memory_bytes: 34268
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cassert>
#include<cstring>
#define llong long long
using namespace std;

const int N = 2e5;
const int S = 26;
int cnt[N+3];
char a[N+3];
int n;

int main()
{
	scanf("%s",a+1); n = strlen(a+1);
	llong ans = 1ll+n*(n-1ll)/2ll;
	for(int i=1; i<=n; i++)
	{
		a[i] -= 96;
		ans -= cnt[a[i]];
		cnt[a[i]]++;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        int a,b,c,k,sum=0;
        Scanner scn = new Scanner(System.in);

        a = scn.nextInt();
        b = scn.nextInt();
        c = scn.nextInt();
        k = scn.nextInt();

        for(int i=0;i<k;i++){
            if(a > 0){
                sum++;
                a--;
            }else if(b > 0){
                b--;
            }else{
                sum--;
                c--;
            }
        }

        System.out.println(sum);
    }
}

Measured memory_bytes: 35832
#include <iostream>

int main()
{
  int x = 1;
  int i = 0;

  while (x != 0)
  {
    std::cin >> x;
    i++;

    if (x != 0)
    {
      std::cout << "Case " << i << ": " << x << std::endl;
    }
  }
}



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

int main() {
    int N, M;
    cin >> N >> M;
    using P = pair<int, int>;
    priority_queue<P, vector<P>, greater<P>> Q;
    rep(i, 0, N) {
        int a, b;
        cin >> a >> b;
        Q.push({a, b});
    }
    priority_queue<int> PQ;
    ll ans = 0;
    rep(i, 1, M + 1) {
        while(!Q.empty() && Q.top().first <= i) {
            P t = Q.top(); Q.pop();
            PQ.push(t.second);
        }
        if(!PQ.empty()) {
            ans += PQ.top(); PQ.pop();
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1908