akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>

ll i,o,t,j,l,s,z,ans;

int main() {
    scanf("%lld%lld%lld%lld%lld%lld%lld",&i,&o,&t,&j,&l,&s,&z);
    ans=0;
    ans+=o*2;
    ans+=(j/2)*4;
    ans+=(l/2)*4;
    ans+=(i/2)*4;
    int tmp=(i&1)+(j&1)+(l&1);
    if (tmp==3) {
        ans+=6;
    } else if (tmp==2) {
        if ((i&1)==0) {
            if (i>0) ans+=2;
        } else if ((j&1)==0) {
            if (j>0) ans+=2;
        } else {
            if (l>0) ans+=2;
        }
    }
    printf("%lld\n",ans/2);
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

int main(){
    int a,b,c; cin >> a >> b >> c;
    cout << ((a <= c && c <= b)?"Yes":"No") <<endl; return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
    int a,b,c,d,e,f;
    cin>>a>>b>>c>>d>>e>>f;
    int g=a,h=e;
    if(g>b){
        g=b;
    }
    if(g>c){
        g=c;
    }
    if(g>d){
        g=d;
    }
    if(h>f){
        h=f;
    }
    cout<<a+b+c+d+e+f-g-h<<endl;
}



Measured memory_bytes: 3108
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
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;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
ll a[maxn];
ll sum[maxn];
int n;
ll ans=1e18;
int main()
{
    //freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
    //freopen("D:\\common_text\\code_stream\\out.txt","w",stdout);
    gbtb;
    cin>>n;
    repd(i,1,n)
    {
        cin>>a[i];
        sum[i]=sum[i-1]+a[i];
    }
    repd(i,1,n-1)
    {
        ans=min(ans,abs(sum[i]-(sum[n]-sum[i])));
    }
    cout<<ans<<endl;
    
    
    
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}



Measured memory_bytes: 5888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }

int main() {
  for (int i = 0; i < (int)9; ++i) for (int j = 0; j < (int)9; ++j) printf("%dx%d=%d\n", i + 1, j + 1, (i + 1) * (j + 1));
  return 0;
}



Measured memory_bytes: 3080
#include<cstdio>

int main( ) {
    int a,b;
    scanf("%d %d", &a, &b);   
    int d = a / b; 
    int r = a % b; 
    double f=(double) a / b;
    printf("%d %d %.5f\n", d, r, f);
    return 0;
}


Measured memory_bytes: 2728
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 152076289;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int gcd(int a, int b) {
	if (a < b)swap(a, b);
	while (b) {
		int r = a % b; a = b; b = r;
	}
	return a;
}
int main(){
	int n, m; cin >> n >> m;
	string s, t; cin >> s >> t;
	int d = gcd(n, m);
	ll dd = (ll)n / d * ((ll)m / d)*d;
	string u, v;
	rep(i, d) {
		u.push_back(s[i*n/d]);
	}
	rep(i, d) {
		v.push_back(t[i*m/d]);
	}
	if (u != v)cout << -1 << endl;
	else cout << dd << endl;
	return 0;
}

Measured memory_bytes: 512
#include<math.h>
#include<time.h>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
int main()
{
	int a,b;
	double c,d;
	scanf("%d %d",&a,&b);
	c=a;
	d=b;
	printf("%d %d %.5f\n",a/b,a%b,c/d);
	return 0;
}


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

int main(){
    string s;
    cin >> s;
    int l = s.length();
    LL ans = 0;
    LL dig = 1;
    for(int i = 0;i < l-1;i++)  dig *= 10;
    ans += (LL)(stoi(s.substr(0, 1)))*dig;
    if(l > 1)   ans += stoi(s.substr(1, l-1));
    for(int i = 1;i < 1<<(l-1);i++){
        int id = 0;
        for(int j = 0;j < l-1;j++){
            if(i>>j&1){
                ans += stoi(s.substr(id, j+1-id));
                id = j+1;
            }
        }
        ans += stoi(s.substr(id, l-id));
    }
    cout << ans << endl;
}

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

set<string> ss;
string a[200048],s;
int tot=0,k;

int main ()
{
    cin>>s>>k;
    int i,j,n=int(s.size());
    for (i=0;i<=n-1;i++)
        for (j=1;j<=5;j++)
        {
            if (i+j-1>=n) continue;
            ss.insert(s.substr(i,j));
        }
    for (i=1;i<=k-1;i++) ss.erase(ss.begin());
    cout<<(*(ss.begin()))<<endl;
    return 0;
}


Measured memory_bytes: 11072
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5 + 5;

int n, m;
int a[N];
vector<int> g[N];

int32_t main()
{
	IOS;
	cin >> n >> m;
	for(int i = 1; i <= n; i++)
		cin >> a[i];
	for(int i = 1; i <= m; i++)
	{
		int u, v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	int ans = 0;
	for(int i = 1; i <= n; i++)
	{
		int ct = 0;
		for(auto &it:g[i])
			if(a[i] <= a[it])
				ct++;
		ans += (ct == 0);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 10276
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  string sa,sb,sc;
  cin >> sa >> sb >> sc;
  ll i=1,j=0,k=0;
  ll a=sa.size(),b=sb.size(),c=sc.size();
  char C=sa[0];
  while(i<=a&&j<=b&&k<=c){
    if(C=='a'){
      C=sa[i-1];
    }
    else if(C=='b'){
      C=sb[j-1];
    }
    else{
      C=sc[k-1];
    }
    if(C=='a'){
      i++;
    }
    else if(C=='b'){
      j++;
    }
    else{
      k++;
    }
  }
  if(i==a+1){
    cout << "A" << endl;
  }
  else if(j==b+1){
    cout << "B" << endl;
  }
  else{
    cout << "C" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
namespace mint {
  constexpr int md = 1e9 + 7;
  inline void add (int &a, int b) {
    a += b; if (a >= md) a -= md;
  }
  inline void sub (int &a, int b) {
    a -= b; if (a < 0) a += md;
  }
  inline int sum (int a, int b) {
    add(a, b); return a;
  }
  inline int dif (int a, int b) {
    sub(a, b); return a;
  }
  template<class... A>
  inline int prod (A... args) {
    long long ret = 1;
    for (int a : initializer_list<int>{args...}) {
      assert(a >= 0);
      ret *= a;
      ret %= md;
    }
    return (int)(ret % md);
  }
  inline void mul (int &a, int b) {
    a = prod(a, b);
  }
  inline int inv (int a) {
    a %= md;
    if(a < 0) a += md;
    int b = md, u = 0, v = 1;
    while (a) {
      int t = b / a;
      b -= a * t; swap(a, b);
      u -= v * t; swap(u, v);
    }
    assert(b == 1);
    if(u < 0) u += md;
    return u;
  }
  inline int quot (int a, int b) {
    return prod(a, inv(b));
  }
  inline void div (int& a, int b) {
    a = quot(a, b);
  }
  inline int pow (int a, long long b) {
    int res = 1;
    for (; b; b >>= 1) {
      if (b & 1) mul(res, a);
      mul(a, a);
    }
    return res;
  }
  namespace factorials {
    int sz;
    vector<int> fact, finv;
    void init (int n) {
      sz = n;
      fact.resize(n); finv.resize(n);
      fact[0] = 1;
      for (int i = 1; i < n; i++) fact[i] = prod(fact[i - 1], i);
      finv[n - 1] = inv(fact[n - 1]);
      for (int i = n - 2; i >= 0; i--) finv[i] = prod(finv[i + 1], i + 1);
    }
  }
  inline int fct (int i) {
    using namespace factorials;
    assert(0 <= i && i < sz);
    return fact[i];
  }
  inline int fnv (int i) {
    using namespace factorials;
    assert(0 <= i && i < sz);
    return finv[i];
  }
  inline int binom (int n, int k) {
    using namespace factorials;
    assert(0 <= n && n < sz);
    if (0 < k || n < k) return 0;
    return prod(fact[n], finv[k], finv[n - k]);
  }
}
int main() {
  cin.tie(0); cin.sync_with_stdio(false);
  string s;
  cin >> s;
  int coeff = 1;
  int ret = 1;
  for (char c : string(s.rbegin(), s.rend())) {
    if (c == '1') {
      mint::mul(ret, 2);
      mint::add(ret, coeff);
    }
    mint::mul(coeff, 3);
  }
  cout << ret << endl;
  return 0;
}

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

typedef long long  ll;

ll MOD = 1000000007;
ll INF = 100000000000;
double PI = 3.1415926535;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

ll GCD(ll a,ll b){
    if(a < b)return GCD(b,a);
    ll r = INF;
    while(r){
        r = a % b;
        a = b;
        b = r;
    }
    return a;
}

int main(){
   int N;cin >> N;
   vector<ll> A(N);
   for(int i = 0;i < N;i++)cin >> A[i];
   sort(A.begin(),A.end());
   ll X = 0,Y = A[N-1];
   for(int i = 0;i < N-1;i++){
       if(abs(Y-X*2) > abs(Y-A[i]*2)){
           X = A[i];
       }
   }
   cout << Y << ' '<< X <<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>

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

	std::vector<int> v( M );
	for ( int i = 0; i < M; i++ )
	{
		std::cin >> v[i];
	}
	std::sort( v.begin(), v.end() );

	std::vector<int> vv( M - 1 );
	for ( int i = 0; i < M - 1; i++ )
	{
		vv[i] = v[i + 1] - v[i];
	}
	std::sort( vv.begin(), vv.end() );

	// 両端を除いて（M-2）、N-1個のコマを配置する？
	long long dist = 0;
	for ( int i = 0; i <= M - 2 - ( N - 1 ); i++ )
	{
		dist += vv[i];
	}

	std::cout << dist << std::endl;

	return ( 0 );
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main(){
  int x, a, b;
  cin >> x >> a >> b;
  x-=a;
  cout << x % b;
}

Measured memory_bytes: 256
/* ----------------------------
 * ABC 91 D カンニングして解答
 * カンニングしたのにWA食らうんですけど... .
 * ---------------------------- */
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

// digit は0始まり.
bool isBitOn(int target, int digit);
// digit 以下のビットを取得する
int getUnderBits(int target, int digit);
// digit だけ bit が立ったマスクを取得する
int getOnMask(int digit);
int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> b(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	for(int i = 0; i < n; i++){
		cin >> b[i];
	}
	// ソート
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	// 回答編
	int ans = 0;
	
	// c を n の4倍の大きさで用意する
	vector<int> c(4*n);
	// 0 <= (a, b) < pow(2, 28)
	for(int i = 0; i < 29; i++){
		for(int j = 0; j < n; j++){
			c[j] = getUnderBits(b[j], i);
		}
		sort(c.begin(), c.begin() + n);
		for(int j = 0; j < 2*n; j++){
			c[n+j] = c[j] + getOnMask(i + 1);
		}
		long long total = 0;
		for(int j = 0; j < n; j++){
			int y = getUnderBits(a[j], i);
			total += lower_bound(c.begin(), c.begin() + 3 * n, (4<<i)-y)
					- lower_bound(c.begin(), c.begin() + 3 * n, (3<<i)-y);
		}
		if(total%2) ans += getOnMask(i);
	}
	
	cout << ans << endl;
	return 0;
}
// digit は0始まり.
bool isBitOn(int target, int digit){
	return target & (1 << digit);
}
// digit 以下のビットを取得する
int getUnderBits(int target, int digit){
	// i.e.
	// getUnderBits(0b11111111, 3)
	// returns     0b00001111
	return target & ((1 << (digit + 1)) - 1);
}
// digit だけ bit が立ったマスクを取得する
int getOnMask(int digit){
	return 1 << digit;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pll = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) ((x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,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;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(ll a, ll b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmax(T &a, const T &b){ if(a < b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(a > b){ a=b; return 1; } return 0; }


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

  ll n;
  cin >> n;
  cout << (n/1000+(n%1000!=0))*1000 - n << endl;
  return 0;
}

Measured memory_bytes: 3632
#include  <iostream>
#include  <vector>
#include  <string>
#include  <queue>
using namespace std;

typedef pair<int, int> the;
#define rep(i, n) for(int i = 0; i < n; i++)

int main()
{
	int h, w;
	cin >> h >> w;
	vector<string> field(h);
	rep(i, h) cin >> field[i];

	vector<the> st;
	int cnt = 0;
	rep(i, h) {
		rep(j, w) {
			if (field[i][j] == '#') {
				st.push_back(the(i, j));
				cnt++;
			}
		}
	}

	int dy[4] = { -1,0,1,0 };
	int dx[4] = { 0,1,0,-1 };
	//bfs
	queue<the> Q;
	for (the v : st)  Q.push(v); 
	int ans = 0;
	while (!Q.empty()) {
		bool flag = true;
		int s = Q.size();
		rep(k, s) {
			the v = Q.front();
			Q.pop();
			rep(i, 4) {
				the nv = the(v.first + dy[i], v.second + dx[i]);
				if (nv.first < 0 || nv.first >= h || nv.second < 0 || nv.second >= w)  continue;
				if (field[nv.first][nv.second] == '#')  continue;
				field[nv.first][nv.second] = '#';
				Q.push(nv);
				flag = false;
			}
		}
		//rep(i, h) { rep(j, w) { cout << field[i][j]; }cout << endl; }
		if (flag)  break;
		ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 17256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

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

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

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

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

	int ans = INF;
	for (int i = -100; i < 101; i++) {
		int tmp = 0;
		for (int j = 0; j < n; j++) {
			tmp+=(i - a[j])*(i - a[j]);
		}
		ans = min(ans, tmp);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
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; }
const int INF = 1e9;
const ll MOD = 1000000007;

int main() {
    int time; cin >> time;
    int hour = time/3600;
    double time2  = time/3600.0;
    int minu = (time2-hour)*60;
    int second = time%60;
    cout << hour << ":" << minu << ":" << second << "\n";
}



Measured memory_bytes: 3116
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi >
#define vvvi vector<vvi >
#define pii pair<int,int>
#define INF 1e9
#define MOD 1e9+7
typedef long long llong;
using namespace std;

int main(){
	int n,m;
	cin>>n>>m;
	
	vi a(n);
	REP(i,n) scanf("%d",&a[i]);
	sort(ALL(a));
	
	vector<pii > cb(m);
	REP(i,m){
		int b,c;
		scanf("%d%d",&b,&c);
		
		cb[i]=make_pair(c,b);
	}
	sort(ALL(cb),greater<pii >());
	
	llong ans=0;
	int cnt=0;
	int i,j=0;
	for(i=0;i<n;++i){
		if(j>=m) break;
		if(a[i]<cb[j].first){
			ans+=cb[j].first;
			cnt++;
			if(cnt>=cb[j].second){
				j++;
				cnt=0;
			}
		}else break;
	}

	while(i<n){
		ans+=a[i];
		i++;
	}
	
	cout<<ans<<endl;
}

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

int partition(int A[], int p, int r) {
    int i = p;
    for (int j = p; j < r; j++) {
        if (A[j] <= A[r]) {
            swap(A[i++], A[j]);
        }
    }
    swap(A[i], A[r]);
    return i;
}

int main(){
    int n;
    cin >> n;
    int A[n];
    for (int i = 0; i < n; i++) {
        int tmp;
        cin >> tmp;
        A[i] = tmp;
    }
    int q = partition(A, 0, n - 1);

    for (int i = 0; i < n; i++) {
        if (i > 0) cout << " ";
        if (i == q) cout << "[";
        cout << A[i];
        if (i == q) cout << "]";
    }
    cout << endl;
    return 0;
}

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

int main(){
	ll H,W;
	cin>>H>>W;
	if(H==1||W==1){
		cout<<1<<endl;
	}else if(H*W%2==0){
		cout<<H*W/2<<endl;
	}else if(H*W%2==1){
		cout<<1+H*W/2<<endl;
	}
return 0;}

/*compile
g++ code.cpp
./a.out
run*/

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  char str[1001];
  int i = 0;

  scanf("%s", str);

  while (str[i] != '\0'){
    if (str[i] == 'A'){
      str[i] = 'X';
    }
    else if(str[i] == 'B'){
      str[i] = 'Y';
    }
    else if(str[i] == 'C'){
      str[i] = 'Z';
    }
    else{
      str[i] -= 3;
    }
    i++;
  }

  printf("%s\n", str);

  return (0);
}

Measured memory_bytes: 524
#include<iostream>
using namespace std;
int main(){
	long long sum=0,max=-1000000,min=1000000,n,a[10000],i,j,k,l;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>a[i];
	}
	for(j=1;j<=n;j++)
		sum+=a[j];
	for(k=1;k<=n;k++)
		if(a[k]>max){
		max=a[k];
		}
	for(l=1;l<=n;l++)
		if(a[l]<min){
		min=a[l];
		}
	cout<<min<<" "<<max<<" "<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3152
#include<iostream>
#include<cstdio>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<list>
#include<vector>
#include<functional>
#include<string.h>
#include<limits.h>
#include<queue>
#include<deque>
#include<stack>
#include<stdlib.h>
#include<algorithm>
#include<cmath>
#define P pair<int,int>
using namespace std;

int main() {
	int i, j;
	int x, a, b;
	cin >> x >> a >> b;
	if (a >= b)cout << "delicious" << endl;
	else if (a + x >= b)cout << "safe" << endl;
	else cout << "dangerous" << endl;
}

Measured memory_bytes: 256
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
import sys
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import lru_cache, reduce
from math import gcd
from operator import add, itemgetter, mul, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


D = int(sys.stdin.buffer.readline())
C = list(map(int, sys.stdin.buffer.readline().split()))
S = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(D)]
T = [int(sys.stdin.buffer.readline()) for _ in range(D)]

S = [0] + S
T = [0] + T

lasts = [0] * 26
score = 0
for d in range(1, D + 1):
    t = T[d] - 1
    score += S[d][t]

    lasts[t] = d
    for j, c in enumerate(C):
        score -= (d - lasts[j]) * c
    print(score)


Measured memory_bytes: 27352
//includes
#include<iostream>
#include<vector>
#include<set>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<map>
#include<queue>
#include<iomanip>
#include<numeric>
#include<assert.h>
#include<cstring>
#include<unordered_map>
#include<bitset>

//macros and consts
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define FORE(i,a) for(auto &i : a)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define accm accumulate
#define Fi first
#define Se second
#define INF 1e9
#define llINF (1LL<<60)
#define mINF -1e9
#define mllINF -(1LL<<60)
#define endl "\n"
#define CONT continue
#define BRK break
#define modulo(n, m) (((n)%(m)+(m))%m)

//shorter types
using namespace std;
using ll = long long;
using vi = std::vector<int>;
using vc = std::vector<char>;
using vll = std::vector<long long>;
using vs = std::vector<string>;
using Mi = map<int,int>;
using Mll = map<ll,ll>;
using UMi = unordered_map<int,int>;
using UMll = unordered_map<ll,ll>;
using Pi = pair<int,int>;
using Pll = pair<ll,ll>;
using vPi = vector<Pi>;
using vPll = vector<Pll>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<ll>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
using pqgi = priority_queue<int,vector<int>,greater<int>>;
using pqsi = priority_queue<int,vector<int>,less<int>>;
using pqgll = priority_queue<int,vector<int>,greater<int>>;
using pssll = priority_queue<int,vector<int>,less<int>>;
template<class T>
using vec = vector<T>;
#define int long long

int N;
//here begins your code
vector<vector<pair<int,int>>> D;
bool judge(int bit){
	for(int i = 0 ; i < N ; i++){
		if(!(bit & (1 << i)))continue;
		for(auto xy : D[i]){
			int x = xy.first;
			int y = xy.second;

			if(y == 1 && !(bit & (1 << x))) return false;
			if(y == 0 && (bit & (1 << x))) return false;
		}
	}
	return true;
}

signed main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  cin >> N;
  D.resize(N);
  for(int i = 0 ; i < N ; i++){
  	int A;
  	cin >> A;
  	D[i].resize(A);
  	for(int j = 0 ; j < A ; j++){
  		cin >> D[i][j].first >> D[i][j].second;
  		D[i][j].first--;
  	}
  }

  int res = 0;
  for(int bit = 0 ; bit < (1 << N) ; bit++){
  	if(judge(bit)){
  		int count = 0;
  		for(int i = 0; i < N ; i++){
  			if(bit & (1 << i)) count++;
  		}
  		res = max(res,count);
  	}
  }
  cout << res << endl;
  //check types
  //do not eb if you resize
  //resize before you access by idx
  return 0;
} 

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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define FORD(i,b,a) for (int i = (int)(b) - 1; i >= a; --i)
#define REP(i,N) FOR(i,0,N)
#define st first
#define nd second
#define pb push_back

typedef pair<int, int> PII;
typedef long long LL;

int main() {
  LL N, A, B;
  scanf("%lld%lld%lld", &N, &A, &B);

  if ((N == 1 && A != B) || B < A) {
    printf("0\n");
    return 0;
  }

  printf("%lld\n", (N-1) * B + A - (N-1) * A - B + 1);
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	int cnt;
	void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = scan.nextInt();
		shellSort(a, n);
	}

	void insertSort(int[] a, int n, int g) {
		for (int i = g; i < n; i++) {
			int v = a[i];
			int j = i - g;
			while (j >= 0 && a[j] > v) {
				a[j + g] = a[j];
				j -= g;
				cnt++;
			}
			a[j + g] = v;
		}
	}

	void shellSort(int[] a, int n) {
		cnt = 0;
		int m = 0;
		if (a.length == 1) {
			m = a.length;
		} else {
			for (int i = a.length; i > 1; i /= 2)
				m++;
		}
		int[] g = new int[m];
		if (m == 1) {
			g[0] = 1;
		} else {
			for (int i = 0, len = a.length / 2; i < m; i++, len /= 2)
				g[i] = len;
		}

		System.out.println(m);
		for (int i = 0; i < m; i++)
			System.out.print(g[i] + (i != m - 1 ? " ":"\n"));

		for (int i = 0; i < m; i++)
			insertSort(a, n, g[i]);

		System.out.println(cnt);
		for (int i = 0; i < n; i++)
			System.out.println(a[i]);
	}

	public static void main(String[] args) {
		new Main().run();
	}
}



Measured memory_bytes: 299288
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9+7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
if n == 3:
    print(max(a))
    quit()
dp1 = [-inf]*(n+1) 
dp2 = [-inf]*(n+1)
dp3 = [-inf]*(n+1)
dp1[0] = 0
dp2[0] = 0
dp3[0] = 0
dp1[1] = a[0]
dp2[2] = a[1]
for i in range(3,n+1):
    dp1[i] = dp1[i-2] + a[i-1]
    dp2[i] = max(dp2[i-2],dp1[i-3]) + a[i-1]
    dp3[i] = max(dp3[i-2],dp2[i-3],dp1[i-4]) + a[i-1]
if n % 2:
    print(max(dp1[n-2], dp2[n], dp3[n]))
else:
    print(max(dp1[n-1],dp2[n]))



Measured memory_bytes: 120084
import sys

def main():
    n = input()
    tree = MyBinaryTree(n)
    for i in range(n):
        cmd = map(str,raw_input().split())
        if cmd[0] == "insert":
            insert(tree,MyNode(int(cmd[1])))
        elif cmd[0] == "print":
            tree.inorder(tree.root)
            print ""
            tree.preorder(tree.root)
            print ""
    
    
class MyBinaryTree():
    def __init__(self,num_nodes):
        self.root = None

    def preorder(self,node):
        sys.stdout.write(" {}".format(node.key))
        l = node.left
        r = node.right
        if l is not None:
            self.preorder(l)
        if r is not None:
            self.preorder(r)    

    def inorder(self,node):
        l = node.left
        r = node.right
        if l is not None:
            self.inorder(l)
        sys.stdout.write(" {}".format(node.key))
        if r is not None:
            self.inorder(r)


def insert(T,z):
    y = None
    x = T.root
    while x is not None:
        y = x
        if z.key < x.key:
            x = x.left
        else:
            x = x.right
    z.parent = y

    if y is None:
        T.root = z
    elif z.key < y.key:
        y.left = z
    else:
        y.right = z

        
class MyNode():
    def __init__(self,key):
        self.key =key
        self.parent = None
        self.left = None
        self.right = None


if __name__ == "__main__":
    main()

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

typedef long long LL;

const int N=3000,mod=998244353;

int add(int a,int b,int p=mod){return a+b>=p?a+b-p:a+b;}
int sub(int a,int b,int p=mod){return a-b<0?a-b+p:a-b;}
int mul(int a,int b,int p=mod){return (LL)a*b%p;}
void sadd(int &a,int b,int p=mod){a=add(a,b,p);}
void ssub(int &a,int b,int p=mod){a=sub(a,b,p);}
void smul(int &a,int b,int p=mod){a=mul(a,b,p);}

int n,m;

void into(){
  scanf("%d%d",&n,&m);
}

int inv[N*2+9],fac[N*2+9],ifac[N*2+9];

void Get_inv(){
  inv[1]=1;
  fac[0]=fac[1]=1;
  ifac[0]=ifac[1]=1;
  for (int i=2;i<=n<<1;++i){
	inv[i]=mul(mod-mod/i,inv[mod%i]);
	fac[i]=mul(fac[i-1],i);
	ifac[i]=mul(ifac[i-1],inv[i]);
  }
}

int Get_c(int n,int m){return n<m||m<0?0:mul(fac[n],mul(ifac[m],ifac[n-m]));}

int Get_ans(int n){
  int res=m&1||n<<1<m;
  for (int i=n;i<n<<1;++i)
	if (i<m) sadd(res,Get_c(n,i-n));
    else if (m-i&1){
	  int p=i-m+1>>1;
	  sadd(res,Get_c(n-p*2,i-p*2-n));
	}
  return res;
}

int ans;

void Get_ans(){
  for (int i=0;i<=n;++i) sadd(ans,mul(Get_c(n,i),Get_ans(i)));
}

void work(){
  Get_inv();
  Get_ans();
}

void outo(){
  printf("%d\n",ans);
}

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 3896
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n+1); i++)
const long long INF = 1LL << 60;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  cout<<(a-b+1)*(a-c+1)<<endl;
}


Measured memory_bytes: 3600
#include <iostream>
#include <sstream>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <utility>
#include <iomanip>
#include <numeric>
#include <climits>
#include <algorithm>
#include <cstdint>
using namespace std;

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

    cout << a-b+1;
}

Measured memory_bytes: 3640
import java.util.*;
import java.io.*;


public class Main{

     public static void main(String []args){
        Scanner scanner = new Scanner(System.in);
        long n1= (long)scanner.nextInt();
        long n2= (long)scanner.nextInt();
        long n3= (long)scanner.nextInt();
        long n4= (long)scanner.nextInt();
        
        long arr[] = new long[4];
        
             arr[0] = n1*n3;
             arr[1] = n1*n4;
             arr[2] = n2*n3;
             arr[3] = n2*n4;
           
           
        Arrays.sort(arr);
    
         System.out.println(arr[arr.length-1]);
        
        
        
        //for(int i=0;i<n;i++)
        //int n= scanner.nextInt();
        //System.out.println()
     }
}

Measured memory_bytes: 35704
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

string str[4] = {"dream", "dreamer", "erase", "eraser"};

int main(){
    string S;
    cin >> S;
    ll N = S.size();
    reverse(S.begin(), S.end());
    rep(i,4){
        reverse(str[i].begin(), str[i].end());
    }
    rep(i,N){
        bool flag = 0;
        rep(j,4){
            if(str[j] == S.substr(i,str[j].size())){
                i += str[j].size()-1;
                flag = 1;
                break;
            }
        }
        if(!flag){
            cout << "NO" <<endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 3760
#![allow(non_snake_case)]
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
     };
     ($next:expr, $t:ty) => {
         $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(dead_code)]
const INF: u64 = 1000000007;


fn main() {
    input!{
        N: usize, L:usize,
        S: [String; N]
    }
    let mut S = S;
    S.sort();
    for s in S {
        print!("{}", s);
    }
    println!("");
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define MAXN 100005
#define ll long long
#define pb push_back
#define sortv(v) sort(v.begin(),v.end())
#define tc(t) int t;cin>>t;while(t--)
#define copy copy_n
#define fr(i,a,b) for(long long i=a;i<b;i++)
#define frr(i,a,b) for(long long i=a;i>=b;i--)
#define frn(i,a,b,n) for(long long i=a;i<=b;i=i+n)
#define gcd(x,y) __gcd(x,y)
#define ld long double
#define um unordered_map
#define mkp make_pair
#define b_s binary_search
#define des greater<ll>()
#define fi first
#define se second
ll mul(ll a,ll b,ll p=mod){return ((a%p)*(b%p))%p;}
ll add(ll a,ll b,ll p=mod){return (a%p + b%p)%p;}
void input(ll a[],ll sz){fr(i,0,sz) cin>>a[i];}
void print(ll a[],ll sz){fr(i,0,sz){if(i==sz-1) cout<<a[i]<<"\n";else cout<<a[i]<<" ";}}
ll maxr(ll a[],ll sz){ll ma;fr(i,0,sz){if(i==0) ma=a[i];else if(a[i]>ma) ma=a[i];}return ma;}
ll minr(ll a[],ll sz){ll mi;fr(i,0,sz){if(i==0) mi=a[i];else if(a[i]<mi) mi=a[i];}return mi;}
ll isprm(ll n) {
    if (n <= 1)  return 0; 
    if (n <= 3)  return 1; 
    if (n%2 == 0 || n%3 == 0) return 0; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return 0; 
    return 1;}
/*ll spf[MAXN];
void sieve() 
{
    spf[1]=1; 
    for (ll i=2; i<MAXN; i++) 
        spf[i] = i; 
    for (ll i=4; i<MAXN; i+=2) 
        spf[i] = 2; 
  
    for(ll i=3;i*i<MAXN;i++) 
    {
        if (spf[i]==i) 
        {
            for (int j=i*i;j<MAXN;j+=i) 
                if (spf[j]==j) 
                    spf[j]=i; 
        }
    }
}*/
ll power(ll x,ll y,ll p=mod) 
{ 
    ll res = 1;
    x = x % p;
    while (y > 0) 
    {
        if (y & 1) 
            res = (res*x) % p;
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
ll modInverse(ll n,ll p=mod) 
{ 
    return power(n, p-2, p); 
} 
ll ncrMod(ll n,ll r,ll p=mod) 
{
   if (r==0) 
      return 1;
    ll fac[n+1]; 
    fac[0] = 1; 
    for (ll i=1 ; i<=n; i++) 
        fac[i] = fac[i-1]*i%p; 
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
}
//a+b=xor(a,b)+2*(a&b)//
bool comp(const pair<int,int> &a, 
              const pair<int,int> &b) 
{
    if(a.fi==b.fi)
    {
        return (a.se>b.se);//second elem in descending
    }
    return (a.first < b.first);//first elem in ascending 
}
ll n,h[100005],dp[100005];











int main()
{
	fio;
	cin>>n;
	input(h,n);
	fr(i,0,100005)
	dp[i]=0;
	for(ll i=n-2;i>=0;i--)
	{
	    dp[i]=abs(h[i]-h[i+1])+dp[i+1];
	    if((i+2)<=n-1)
	    dp[i]=min(dp[i],abs(h[i]-h[i+2])+dp[i+2]);
	}
	cout<<dp[0]<<"\n";
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i < n; ++i)
#define for1(i, n) for (int i = 1; i <= n; ++i)
#define fore(i, l, r) for (int i = l; i <= r; ++i)

using namespace std;

const int MAXN = 201;

int c[10][10];

int main(){
	int H, W; cin >> H >> W;
	forn(i, 10){
		forn(j, 10){
			cin >> c[i][j];
		}
	}
	
	forn(k, 10){
		forn(i, 10){
			forn(j, 10){
				c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
			}
		}
	}
	long long int ans = 0;
	int cell;
	for1(i, H){
		for1(j, W){
			cin >> cell;
			if (cell != -1){
				ans += c[cell][1];
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a,int b){
 	if(a<b||b<0)return 0;
 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
long long pw(long long a,long long b){
	if(a<0LL)return 0;
	if(b<0LL)return 0;
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
// ここから編集しろ
vector<int>g[110000];
int dp[110000];
int solve(int a){
	if(dp[a]!=-1)return dp[a];
	int ret=0;
	for(int i=0;i<g[a].size();i++){
		ret=max(ret,solve(g[a][i])+1);
	}
	return dp[a]=ret;
}
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<b;i++){
		int x,y;scanf("%d%d",&x,&y);x--;y--;
		g[x].push_back(y);
	}
	for(int i=0;i<a;i++)dp[i]=-1;
	int ret=0;
	for(int i=0;i<a;i++){
		ret=max(ret,solve(i));
	}
	printf("%d\n",ret);
}

Measured memory_bytes: 9472
class Integer
  def combination(k)
    return 1 if k.zero?

    (self - k + 1..self).inject(:*) / k.factorial
  end

  def permutation(k)
    return 1 if k.zero?

    (self - k + 1..self).inject(:*)
  end

  def factorial
    return 1 if self.zero?

    (1..self).inject(:*)
  end
end

n, k = gets.chomp.split.map &:to_i
1.upto(k) do |i|
  if i > n - k + 1
    puts 0
  else
    a = (n - k + 1).combination i
    b = (k - 1).combination i - 1
    puts a * b % (10 ** 9 + 7)
  end
end


Measured memory_bytes: 2988
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

#define mod 1000000007LL
#define eps 0.0001
#define pi acos(-1)
#define INF 10000000000000000

#define rep(i, n) for(int i = 0;i < n;++i)
#define rep1(i, n) for(int i = 1;i < n;++i)
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define chmin

#define lset(h, n) memset(h, n, sizeof(h));
    

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // ---------------------
    // コーディング開始
    // ---------------------
    string n;
    cin >> n;
    n[3] = '8';
    pri(n);
}



Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
int main(){
  char S[100005];
  scanf("%s",S);
  int l=strlen(S);
  for(int i=0;i<l;i=i+2){
    printf("%c",S[i]);
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
# define ll long long
using namespace std;
ll int check(vector<int> w, ll int k, ll int n, ll int p){
    int i = 0;

    for(int j = 0; j < k; j++) {
        long s = 0;
        while(s + w[i] <= p) {
            s += w[i];
            i++;
            if(i == n) return n;
        }
    }
    return i;
}

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

    vector<int> w(n);

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

    ll int left = 0;
    ll int right = 100000*10000;
    ll int mid;
    
    while(right - left > 1) {
        mid = (left + right) / 2;
        ll int v = check(w,k,n,mid);
        if(v >= n) right = mid;
        else left = mid;
    }

    cout << right << endl;
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
#define INF 1000007

using namespace std;

long long n, m, i, j, a[107][100007], w[107], c[107], z, res = -INF;

int main()
{
    cin >> n >> m;
    for(i = 1; i <= n; i ++){
        cin >> w[i] >> c[i];
    }
    a[0][0] = 0;
    for(i = 1; i <= m; i ++)a[0][i] = -INF;

    for(i = 1; i <= n; i ++){
        for(j = 0; j <= m; j ++){
            z = a[i - 1][j];
            if(j >= w[i]){
                z = max(z, a[i - 1][j - w[i]] + c[i]);
            }
            a[i][j] = z;
        }
    }
    for(i = 0; i <= m; i++){
        if(a[n][i] > res) res = a[n][i];
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 80128
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long int
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio();cin.tie();cout.tie();
using namespace std;
ll n,q,t,x,s1=0;
string s,a,b;
char c;
int32_t main(){
CODE_START;
cin>>s;
cin>>q;
while(q--){
    cin>>t;
    if(t==1){
            s1++;
}else {
cin>>x>>c;
if(s1%2==1){
        if(x==1){
            x=2;
        }else x=1;
}
if(x==2){
    a.pb(c);
}else {
b.pb(c);
}
}
}
reverse(b.begin(),b.end());
b=b+s;
b=b+a;
if(s1%2==1){
        reverse(b.begin(),b.end());
}
cout<<b<<endl;
}





Measured memory_bytes: 1348
import java.io.*;
import java.util.*;


public class Main{
	
	public static void main(String[] args){
	
	MyScanner sc = new MyScanner();
	out = new PrintWriter(new BufferedOutputStream(System.out));
	
	/**/

	String input = sc.next();
	int counter = 0;
		
		int temp = Integer.parseInt("5");
		
	for(int i = 0; i < input.length(); i++){
		counter += Integer.parseInt(Character.toString(input.charAt(i)));
	}
	
	if(counter % 9 == 0){
		System.out.println("Yes");
	}else{
		System.out.println("No");
	}
	/**/
	 
	 out.close();	
	}
	
	
	
	public static PrintWriter out;
	
	public static class MyScanner{
		
		BufferedReader br;
		StringTokenizer st;
		
		public MyScanner(){
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		
		String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }
 
      int nextInt() {
          return Integer.parseInt(next());
      }
 
      long nextLong() {
          return Long.parseLong(next());
      }
 
      double nextDouble() {
          return Double.parseDouble(next());
      }
 
      String nextLine(){
          String str = "";
	  try {
	     str = br.readLine();
	  } catch (IOException e) {
	     e.printStackTrace();
	  }
	  return str;
      }

   }
	
}


Measured memory_bytes: 45780
INF = 10 ** 20

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

lst = list(map(int, input().split()))

dp = [INF for _ in range(n+1)]

dp[0] = 0

for coin in lst:
    for j in range(coin, n+1):
        dp[j] = min(dp[j], dp[j-coin]+1)
print(dp[n])


Measured memory_bytes: 7636
#include <iostream>
#include <algorithm>
#define maxn 100100
using namespace std;

int main(){
	int n,a[maxn],b[maxn];
	//int k=1;
	cin >> n;
	int ans=0,num=0;
	for (int i =1;i<=n;i++) cin >> a[i];
	sort(a+1,a+n+1);
	int kk=1;
	for (int i=1;i<=n;i++){
		if (a[i] == a[i+1]) b[kk]++; else if (a[i+1] ==a[i+2]) kk++;
	}
	

	kk--;

	int l=1;int r=kk;
	if (kk==l && b[kk] == 0){} else{
		while (l<=r){
			b[l]--;b[r]--;
			if (b[l]<=0) l++;
			if (b[r]<=0)r--;
			n-=2;
		}
	}
	cout << n;
	return 0;
}




Measured memory_bytes: 640