akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {

    int A, B, C, K;
    cin >> A >> B >> C >> K;

    if (B < C) swap(B, C);
    if (A < B) swap(A, B);

    rep(i,K) A *= 2;
    
    cout << (A + B + C) << endl;

    
    return 0;
}

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

using namespace std;
typedef long long ll;

int main()
{
    ll A, B, C, K;
    cin >> A >> B >> C >> K;
    ll result = 0;

    if (K <= A) {
        result = K;
    } else if (K <= A + B) {
        result = A;
    } else {
        result = A - (K - A - B);
    }
    cout << result;

    return 0;
}


Measured memory_bytes: 3636
#include<algorithm>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<queue>
#include<stack>
using namespace std;
long long N,M[300000],sum=0,d=0;
stack<long long> c;
int main(void){
	
	priority_queue<long long> q;
	cin>>N;
	for(long long i=0;i<N;i++)
	{
		cin>>M[i];
		for(long long j=0;j<M[i];j++){
			cin>>d;
			c.push(d);
		}
	}
	for(long long i=N-1;i>=0;i--){
		for(long long j=0;j<M[i];j++)
		{
			q.push(c.top());
			c.pop();
		}	
		sum+=q.top();
		q.pop();
	}	
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 9268
#include <stdio.h>
#include<math.h>

int main()
{
  double N, M;
  scanf("%lf %lf", &N, &M);
  int i = 1;
  double exp = 0.0;
  while ( i*((N-M)*100.0 + 1900.0 * M) *pow(1-pow(0.50, M), i-1)*pow(0.50, M) > 0.01) {
  exp += i*((N-M)*100.0 + 1900.0 * M) *pow(1-pow(0.50, M), i-1)*pow(0.50, M) ;
  i++;
}

printf("%.0f", exp);

  return 0;
}

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

int x;

int main(void){
	scanf("%d",&x);
	int sum=0;
	int cnt=0;
	while(cnt==0 || sum%360!=0){
		sum+=x;
		cnt++;
	}
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 3712
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
ll f(ll x) {
  return x*x*x;
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, K;
  cin >> N >> K;
  if(K%2) {
    cout << f(N/K) << endl;
  } else {
    cout << f(N/K) + f(N/K+(N%K>=K/2)) << endl;
  }
}

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

void printVec(std::vector<int> &vec) {
  std::cout << "";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    std::cout << *it << " ";
  }
  std::cout << std::endl;
}

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

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

  sort(a.rbegin(), a.rend());
  int alice = 0;
  int bob = 0;
  for (int i = 0; i < n; ++i) {
    if (i % 2 == 0) {
      alice = alice + a[i];
    } else {
      bob = bob + a[i];
    }
  }
  cout << alice - bob << endl;
	return 0;
}

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

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

int main() {
    int w, h;
    while (cin >> w >> h, w) {
        vector<vector<int>> wall(h, vector<int>(w, 0));
        for (int i = 0; i < 2 * h - 1; ++i) {
            if (i % 2 == 0) {
                for (int j = 0; j < w - 1; ++j) {
                    int c;
                    cin >> c;
                    if (c) continue;
                    wall[i / 2][j] |= 1 << 0;
                    wall[i / 2][j + 1] |= 1 << 2;
                }
            } else {
                for (int j = 0; j < w; ++j) {
                    int c;
                    cin >> c;
                    if (c) continue;
                    wall[i / 2][j] |= 1 << 3;
                    wall[i / 2 + 1][j] |= 1 << 1;
                }
            }
        }
        vector<vector<int>> dis(h, vector<int>(w, 0));
        queue<pair<int, int>> que;
        dis[0][0] = 1;
        que.emplace(0, 0);
        while (!que.empty()) {
            int y, x;
            tie(y, x) = que.front(); que.pop();
            for (int i = 0; i < 4; ++i) {
                int ny = y + dy[i];
                int nx = x + dx[i];
                if (ny >= 0 && ny < h && nx >= 0 && nx < w && (wall[y][x] >> i & 1) && !dis[ny][nx]) {
                    dis[ny][nx] = dis[y][x] + 1;
                    que.emplace(ny, nx);
                }
            }
        }
        cout << dis[h - 1][w - 1] << endl;
    }
}


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

long long int a,b,c,d[20];
  cin >> a >> b>>c;
  d[0] = c;
  for(int i=0;i<10; i++){
    d[i+1] = a*d[i]-b;
     cout <<d[i+1] <<endl;
  }
}
  
  

Measured memory_bytes: 256
#include "bits/stdc++.h"
// Custom Header {{{
#define ALL(x) x.begin(), x.end()
#define endl '\n'
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}}

#define rep(i, n) for (int i = 1; i <= (n); ++i)
signed main()
{
    cin.tie(nullptr); ios::sync_with_stdio(false);

    int N, C;
    i64 D[33][33];

    cin >> N >> C;
    rep(i, C) {
        rep(j, C) {
            cin >> D[i][j];
        }
    }

    int cnt[3][33] {};
    rep(i, N) {
        rep(j, N) {
            int c; cin >> c;
            ++cnt[(i+j) % 3][c];
        }
    }

    i64 ans = LINF;
    rep(a, C) rep(b, C) if (a != b) rep(c, C) if (a != c && b != c) {
        i64 sum = 0;
        rep(i, C) {
            sum += D[i][a] * cnt[0][i];
            sum += D[i][b] * cnt[1][i];
            sum += D[i][c] * cnt[2][i];
        }
        chmin(ans, sum);
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,s,n) for(ll i = (s); i < (n); i++)
const long double EPS = 0.0000000000001;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n, k;
  cin >> n >> k;
  long double ans = 0;
  
  rep(i, 1, n+1) {
    long double a = 1.0/n;
    ll b = i;
    while(b < k) {
      b *= 2;
      a *= 0.5;
    }
    ans += a;
  }
  cout << fixed << setprecision(15) << ans -EPS << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define fi first
#define se second
#define vec vector<ll>
#define mat vector<vector<ll> >
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=998244353;
const ll mod=998244353;
vector<vector<ll> >dp(3010,vector<ll>(3010,-inf));
ll a,b,c,d;
ll cnt;
ll solve(ll i,ll j){
    if(dp[i][j]>=0)return dp[i][j];
    cnt++;
    ll res=0;
    if(i>a){
        res=(res+solve(i-1,j)*j)%mod;
    }
    if(j>b){
        res=(res+solve(i,j-1)*i)%mod;
    }
    if(i>a&&j>b){
        res=(res-(i-1)*(j-1)%mod*dp[i-1][j-1])%mod;
    }
    res%=inf;
    if(res<0)res+=inf;
    dp[i][j]=res;
    return res;
}
signed main(){
    cin>>a>>b>>c>>d;
    dp[a][b]=1;
    cnt=0;
    ll ans=solve(c,d);
    if(ans<0)ans+=mod;
    cout<<ans<<endl;
}

Measured memory_bytes: 74328
///created: 13/Jun/2019 11:54:50

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
#define db(x) cerr << "debug: " << #x << " = " << x << '\n';
template<class __Ty> bool minimize(__Ty& a, __Ty b) {
	if (a > b) { a = b; return true; }
	return false;
}
template<class __Ty> bool maximize(__Ty& a, __Ty b) {
	if (a < b) { a = b; return true; }
	return false;
}

const int N = 1e2 + 5;
ll x[N], y[N], h[N];
int n;

int main() {
	///ios::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; ++i)
		cin >> x[i] >> y[i] >> h[i];
	for (int cx = 0; cx <= 100; ++cx)
		for (int cy = 0; cy <= 100; ++cy) {
			bool testok = 1;
			ll H = -1;
			for (int k = 1; k <= n; ++k) {
				ll d = abs(cx - x[k]) + abs(cy - y[k]);
				if (h[k] == 0) {
					if (H != -1 && H > d)
						testok = 0;
				}
				else {
				if (H == -1)
						H = h[k] + d;
					else
						if (H != h[k] + d)
							testok = 0;
				}
			}
			if (testok) {
				H = max(H, 0LL);
				bool check = 1;
				for (int k = 1; k <= n; ++k)
					if (max(H - abs(x[k] - cx) - abs(y[k] - cy), 0LL) != h[k])
						check = 0;
				if (check) {					
					cout << cx << ' ' << cy << ' ' << max(H, 0LL);
					return 0;
				}
			}
		}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> A(N);
	vector<int> res;
	int mn = -10;
	int mni = -1;
	int nc = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		if (A[i] != 0 && A[i] != 1) {
			res.push_back(i);
			if (A[i] < 0) {
				nc++;
				if (mn <= A[i]) {
					mn = A[i];
					mni = (int)res.size() - 1;
				}
			}
		}
	}
	if (nc % 2 == 1) {
		res.erase(res.begin() + mni);
	}
	int h = -1;

	for (int i = (int)res.size() - 1; i >= 0; i--) {
		//cerr << i << " " << res[i] << endl;
		if (A[res[i]] == -1) {
			if (h == -1) {
				h = i;
			}
			else {
				res.erase(res.begin() + h);
				res.erase(res.begin() + i);
				h = -1;
			}
		}
	}
	cout << res.size() << endl;
	for (int i = 0; i < res.size(); i++) {
		cout << res[i] + 1 << endl;
	}
}


Measured memory_bytes: 3208
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
 
const double EPS = 1e-8, PI = acos(-1);
const int MAXN = 105;
 
struct point {
	double x, y;
	int id;
	
	point() {}
	point(double _x, double _y, int _id = -1) : x(_x), y(_y), id(_id) {}
	bool operator<(const point &another) const;
};
 
struct ans {
	double val;
	int id;
 
	ans() {}
	bool operator<(const ans &another) const
	{
		return id < another.id;
	}
};
 
int tot, n;
point p[MAXN], s[MAXN], normal[MAXN];
ans an[MAXN];
bool visited[MAXN];
 
int sgn(double x)
{
	if (fabs(x) < EPS) return 0;
	return (x > 0 ? 1 : -1);
}
 
double det(const point &a1, const point &a2, const point &b1, const point &b2)
{
	return ((a2.x - a1.x) * (b2.y - b1.y) - (a2.y - a1.y) * (b2.x - b1.x));
}
 
double dot(const point &a1, const point &a2, const point &b1, const point &b2)
{
	return ((a2.x - a1.x) * (b2.x - b1.x) + (a2.y - a1.y) * (b2.y - b1.y));
}
 
double dist(const point &p1, const point &p2)
{
	return sqrt((p2.x - p1.x) * (p2.x - p1.x) + (p2.y - p1.y) * (p2.y - p1.y));
}
 
bool point::operator<(const point &another) const
{
	if (sgn(det(p[0], *this, p[0], another)) == 0)
		return dist(p[0], *this) < dist(p[0], another);
	else
		return det(p[0], *this, p[0], another) > 0;
}
 
void graham()
{
	double min_y = p[0].y, min_x = p[0].x;
	int index = 0;
	for (int i = 1; i <= n - 1; i++) {
		if (p[i].y < min_y || (sgn(p[i].y - min_y) == 0 && p[i].x < min_x)) {
			min_y = p[i].y;
			min_x = p[i].x;
			index = i;
		}
	}
	swap(p[0], p[index]);
	sort(p + 1, p + n);
	s[0] = p[0]; s[1] = p[1];
	tot = 2;
	for (int i = 2; i <= n - 1; i++) {
		while (tot >= 2 && sgn(det(s[tot - 1], p[i], s[tot - 1], s[tot - 2]) < 0)) tot--;
		s[tot++] = p[i];
	}
}
 
int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lf %lf", &p[i].x, &p[i].y);
		p[i].id = i;
	}
	graham();
	for (int i = 0; i < tot; i++) {
		if (i == 0) {
			normal[i].y = -(s[i].x - s[tot - 1].x);
			normal[i].x = s[i].y - s[tot - 1].y;
			normal[i].id = s[i].id;
		}
		else {
			normal[i].y = -(s[i].x - s[i - 1].x);
			normal[i].x = s[i].y - s[i - 1].y;
			normal[i].id = s[i].id;
		}
	}
	point zero(0, 0);
	for (int i = 0; i < tot; i++) {
		if (i == tot - 1) {
			an[i].val = acos(dot(zero, normal[i], zero, normal[0]) / dist(zero, normal[i]) / dist(zero, normal[0])) / PI / 2;
			an[i].id = normal[i].id;
		}
		else {
			an[i].val = acos(dot(zero, normal[i], zero, normal[i + 1]) / dist(zero, normal[i]) / dist(zero, normal[i + 1])) / PI / 2;
			an[i].id = normal[i].id;
		}
	}
	memset(visited, false, sizeof(visited));
	for (int i = 0; i < tot; i++) visited[s[i].id] = true;
	for (int i = 0; i < n; i++)
		if (!visited[i]) {
			an[tot].val = 0.0000000;
			an[tot++].id = i;
		}
	sort(an, an + n);
	for (int i = 0; i < n; i++) printf("%.8f\n", an[i].val);
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)


typedef long long ll;
#define INF 1LL<<60
int N, W, w[101], v[101];
//-----------------------------------------------------------------------------------
ll po[4][101];
ll mul(ll a, ll b) {
    return a* b;
}
vector<vector<vector<vector<ll>>>> dp[2];
int N0, N1, N2, N3;
void pre() {
    rep(p, 0, 4) {
        po[p][0] = 0;
        rep(i, 1, 101) po[p][i] = mul(w[0] + p, i);
    }

    rep(i, 0, N) {
        if (w[i] == w[0]) N0++;
        else if (w[i] == w[0] + 1) N1++;
        else if (w[i] == w[0] + 2) N2++;
        else if (w[i] == w[0] + 3) N3++;
    }

    N0++; N1++; N2++; N3++;

    dp[0] = vector<vector<vector<vector<ll>>>>(N0, vector<vector<vector<ll>>>(N1, vector<vector<ll>>(N2, vector<ll>(N3, -1))));
    dp[1] = vector<vector<vector<vector<ll>>>>(N0, vector<vector<vector<ll>>>(N1, vector<vector<ll>>(N2, vector<ll>(N3, -1))));
}
//-----------------------------------------------------------------------------------
int main() {
    cin >> N >> W;
    rep(i, 0, N) scanf("%d%d", &w[i], &v[i]);

    pre();

    rep(w0, 0, N0) rep(w1, 0, N1) rep(w2, 0, N2) rep(w3, 0, N3) dp[0][w0][w1][w2][w3] = -1;
    dp[0][0][0][0][0] = 0;
    rep(i, 0, N) {
        int ii = (i + 1) % 2;
        rep(w0, 0, N0) rep(w1, 0, N1) rep(w2, 0, N2) rep(w3, 0, N3) dp[ii][w0][w1][w2][w3] = -1;
        rep(w0, 0, N0) rep(w1, 0, N1) rep(w2, 0, N2) rep(w3, 0, N3) if (0 <= dp[i % 2][w0][w1][w2][w3]) {
            dp[(i + 1) % 2][w0][w1][w2][w3] = max(dp[(i + 1) % 2][w0][w1][w2][w3], dp[i % 2][w0][w1][w2][w3]);

            int ii = (i + 1) % 2;
            int ww0 = w0;
            int ww1 = w1;
            int ww2 = w2;
            int ww3 = w3;

            if (w[i] == w[0]) ww0++;
            else if (w[i] == w[0] + 1) ww1++;
            else if (w[i] == w[0] + 2) ww2++;
            else if (w[i] == w[0] + 3) ww3++;

            ll wei = po[0][ww0] + po[1][ww1] + po[2][ww2] + po[3][ww3];
            if (W < wei) continue;

            dp[ii][ww0][ww1][ww2][ww3] = max(dp[ii][ww0][ww1][ww2][ww3], dp[i % 2][w0][w1][w2][w3] + v[i]);
        }

        //rep(w0, 0, N0) rep(w1, 0, N1) rep(w2, 0, N2) rep(w3, 0, N3) printf("dp[%d][%d][%d][%d][%d] = %lld\n", i, w0, w1, w2, w3, dp[i % 2][w0][w1][w2][w3]);
    }

    ll ans = 0;
    rep(w0, 0, N0) rep(w1, 0, N1) rep(w2, 0, N2) rep(w3, 0, N3) ans = max(ans, dp[N % 2][w0][w1][w2][w3]);
    cout << ans << endl;
}

Measured memory_bytes: 9088
// スタックサイズ: 100MB

#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
using namespace std;

typedef int64_t ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 1e18;
const double EPS = 1e-10;
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define fst first
#define snd second
ll pw(ll x, ll y) { ll r = 1;  rep(i, y) { r *= x; }; return r; }



int main() {
	fastio;

	ll a, b, c;
	cin >> a >> b >> c;
	if (a == b) cout << c << endl;
	if (b == c) cout << a << endl;
	if (a == c) cout << b << endl;

	
}

Measured memory_bytes: 256
n = int(input())
a, b = map(int, input().split())
lst = list(map(int, input().split()))
diff = [0] * 3
for i in range(n):
  if lst[i] <= a:
    diff[0] += 1
  elif lst[i] <= b:
    diff[1] += 1
  else:
    diff[2] += 1
print(min(diff))

Measured memory_bytes: 9068
#include <bits/stdc++.h>
#define REP(i,n) for(int64_t i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define VIN(n,v) for(int64_t i=0;i<(n);i++){cin >> (v).at(i);}

using namespace std;
typedef int64_t I;
typedef pair<I,I> P;
typedef vector<I> V;

I MOD = pow(10,9)+7;

// 最大公約数
I gcd(I a, I b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
I lcm(I a, I b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

int main(){
  I a,b;
  cin >> a >> b;
  I t=INT_MIN;
  t = max(a+b, a-b);
  t = max(t, a*b);
  cout << t << endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll x,y,z;
  cin >> x >> y >> z;
  swap(x,y);
  swap(x,z);
  pr(x,y,z);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
#include <iostream>
#include <vector>
#include <set>
#include <regex>
#include <boost/format.hpp>

using namespace std;

#define FOR(i, a, b) for (auto i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define DEBUG(_debuged) cerr << #_debuged << ":" << _debuged << endl;

struct L
{
    int t;
    int x;
    int y;
};

vector<int> loadn(int n)
{
    vector<int> v(n);
    REP(i, n)
    cin >> v[i];
    return v;
}

uint64_t modpower(const unsigned int N, const unsigned int K, const unsigned int MOD)
{
    uint64_t ret = 1;
    uint64_t k2 = N;
    REP(i, 31)
    {
        if ((K >> i) & 0x1)
        {
            ret *= k2;
            ret = ret % MOD;
        }
        k2 = (k2 * k2) % MOD;
    }
    return ret;
}

class ModCombinationMemo
{
  public:
    const unsigned int N;
    const unsigned int MOD;
    vector<uint64_t> memo = {1};

    ModCombinationMemo(uint32_t N, uint32_t MOD)
        : N(N), MOD(MOD)
    {
    }

    uint64_t c(uint64_t k)
    {
        if (memo.size() > k)
        {
            return memo[k];
        }

        FOR(i, memo.size(), k + 1)
        {
            const auto number = (memo[i - 1] * (N - i + 1)) % MOD;
            const auto reverceDeon = modpower(i, MOD - 2, MOD);
            memo.push_back(number * reverceDeon % MOD);
        }

        return memo[k];
    }
};

uint64_t c(const unsigned int N, const unsigned int K, const unsigned int MOD)
{
    if (K == 0)
    {
        return 1;
    }

    uint64_t n = 1, k = 1;

    REP(i, K)
    {
        n *= N - i;
        k *= i + 1;

        n = n % MOD;
        k = k % MOD;
    }

    uint64_t powerk = modpower(k, MOD - 2, MOD);

    return (n * powerk) % MOD;
}

int main(int argc, char *argv[], char *envp[])
{
    const uint32_t MOD = 998244353;
    uint64_t N, A, B, K;
    cin >> N >> A >> B >> K;

    ModCombinationMemo mcm(N, MOD);

            uint64_t ret = 0;

    REP(a, N + 1)
    {
        if (a * A > K)
        {
            break;
        }
        if ((K - a * A) % B != 0)
        {
            continue;
        }
        const uint64_t b = (K - a * A) / B;
        ret += mcm.c(a) * mcm.c(b) % MOD;
    }

    cout << ret % MOD << endl;
}


Measured memory_bytes: 18408
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Iterator;

class Graph {
	private int totalVertex;
	private LinkedList<LinkedList<Integer>> adjList;
	//adjacency list of edges
	private int[] discover; //discover time stamp, -1 for undiscovered
	private int[] finish; //finish time stamp
	public Graph() { totalVertex = 0; }
	public void loadAdjList() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjList = new LinkedList<LinkedList<Integer>>();
		for(int i = 0; i < totalVertex; i ++) {
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			int idx1 = in.nextInt() - 1; //-1, index
			int degree = in.nextInt();
			//System.out.println("mark idx1 = " + idx1 + " degree = " + degree);
			for(int j = 0; j < degree; j ++) {
				int idx2 = in.nextInt() - 1; //-1, index
				tmp.add(idx2);
			}	
			adjList.add(tmp);
		}
		in.close();
	}
	
	public int DFS(int v, int t0) {
		discover[v] = t0;
		LinkedList<Integer> nb = adjList.get(v);
		Iterator<Integer> it = nb.iterator();
		int t = t0;
		while(it.hasNext()) {
			int w = it.next();
			if(discover[w] == -1) {
				t ++; //one forward step
				t = DFS(w, t);
			}
		}
		finish[v] = t + 1; //+1 for backtrack step
		return t + 1;
	}
	
	public void timeStamp() {
		int v;
		discover = new int[totalVertex];
		finish = new int[totalVertex];
		for(v = 0; v < totalVertex; v ++) discover[v] = -1; //-1: not discovered
		int t = 0;
		for(v = 0; v < totalVertex; v ++) {
			if(discover[v] == -1) { //for disconnected graph, restart from an unvisited node
				t = DFS(v, t);
				t ++;
			}
		}
		//display the result
		for(v = 0; v < totalVertex; v ++) {
			System.out.println((v + 1) + " " + (discover[v] + 1) + " " + (finish[v] + 1));
			//+1, node 0 -> 1, 1 -> 2, etc
		}
	}
}

public class Main {
	public static void main(String argv[]) {
		Graph g = new Graph();
		g.loadAdjList();
		g.timeStamp();
	}
}


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

int solve(int x, int y){
	while(x != y){
		if(x > y)x -= y;
		else y -= x;
	}
	return y;
}

int main(){
	int w, h, c;
	scanf("%d%d%d", &w, &h, &c);
	int x = solve(w, h);
	printf("%d\n", (w/x)*(h/x)*c);
	return 0;
}


Measured memory_bytes: 3192
#include<iostream>

using namespace std;
long long int n,a,b;
int main()
{
	cin>>n>>a>>b;
	if(n==1)
	{
		if(a==b)
			cout<<1;
		else cout<<0;
	}
	else 
	{
		if(a==b)cout<<1;
		else if(a>b)cout<<0;
		else
		{
			cout<<(n-1)*b+a-(n-1)*a-b+1;
		}
	}
}

Measured memory_bytes: 256
open System

// prelude
let readStr () = stdin.ReadLine()

let read f () = readStr() |> f
let reads f () = readStr().Split() |> Array.map f

let pair = function
| [|a; b|] -> (a, b)
| _ -> failwith "owatta"

let triple = function
| [|a; b; c|] -> (a, b, c)
| _ -> failwith "owatta"

let readPair f g () =
  let (a,b) = readStr().Split() |> pair
  (f a, g b)

let readTriple f g h () =
  let (a,b,c) = readStr().Split() |> triple
  (f a, g b, h c)

let inc n = n + 1
let dec n = n - 1

let inline flip f a b = f b a
let rec fix f = fun x -> (f (fix f)) x

module Option =
  let getOr defaultValue = function
  | Some x -> x
  | None -> defaultValue

module Array =
  let modify (arr: _ []) i f =
    arr.[i] <- f arr.[i]

module Array2D =
  let modify (arr: _ [,]) i j f =
    arr.[i, j] <- f arr.[i, j]

// start
let S = (read string ()).ToCharArray()
let T = (read string ()).ToCharArray()

if T.[0..S.Length-1]=S then "Yes" else "No"
|> printfn "%s"


Measured memory_bytes: 32304
#include<bits/stdc++.h>
#define ll long long int
#define endl '\n'
#define M 1000000007
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define f first
#define s second
#define b begin
#define e end
#define pb push_back
#define mp make_pair
#define FOR(i,a,b) for(i=a;i<b;i++)
#define RFOR(i,a,b) for(i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define itfr(it,x) for(it=x.begin();it!=x.end();it++)
#define flash ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;

int main()
{
    flash;
    //sieve();
    ll T=1,t,n,m,x,y,k,i,j;
    // cin>>T;
    while(T--)
    {
        cin>>n>>k>>x>>y;
        cout<<x*min(k,n)+y*max((ll)0,n-k)<<endl;
        
    }
}

Measured memory_bytes: 3520
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
//const ll mod = 1000000007;
ll N, M, A[3];
vector<vector<int>> paths;
vector<vector<int>> inv;
vector<int> g[150][150];
int dist[150];
int reach[150];

set<int> f(set<int> from, int dist) {
    if(dist == 0) return from;
    set<int> tmp;
    for(auto u : from) {
        for(auto to : inv[u]) {
            tmp.insert(to);
        }
    }
    return f(tmp, dist - 1);
}

void bfs(int s) {
    for(int i = 0; i < N; i++) dist[i] = 1e9;
    dist[s] = 0;
    reach[s] = 7;
    queue<int> que;
    que.push(s);
    while(!que.empty()) {
        int now = que.front();
        que.pop();
        for(int i = 0; i < 3; i++) {
            for(auto to : g[now][i]) {
                reach[to] |= (1 << i);
                //cerr << now << " " << to << " " << i << endl;
                if(reach[to] == 7) {
                    if(chmin(dist[to], dist[now] + 1)) que.push(to);
                }
            }
        }
    }
}

int main() {
    cin >> N >> M;
    for(int i = 0; i < 3; i++) cin >> A[i];
    paths.resize(N);
    inv.resize(N);
    for(int i = 0; i < M; i++) {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        paths[u].push_back(v);
        inv[v].push_back(u);
    }
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < 3; j++) {
            set<int> tmp;
            tmp.insert(i);
            auto st = f(tmp, A[j]);
            for(auto c : st) {
                g[i][j].push_back(c);
                //cerr << i << " " << j << " " << c << endl;
            }
        }
    }
    bfs(N - 1);
    if(dist[0] == 1e9) cout << "IMPOSSIBLE" << endl;
    else cout << dist[0] << endl;
    return 0;
}


Measured memory_bytes: 3832
#include<iostream>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
	char n[a+b+2];
	cin>>n;
	if(n[a]!='-'){
		cout<<"No"<<endl;
		return 0;
	} 
	for(int i=0;i<a+b+1;i++){
		if(i==a)continue;
		if(n[i]<'0'||n[i]>'9'){
			cout<<"No"<<endl;
			return 0;
		} 
	}
	cout<<"Yes"<<endl;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

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

    int N;
    cin >> N;
    while (N--)
    {
        int p, q;
        cin >> p >> q;
        int cnt = 0;
        for (int i = 0; i <= p * p + q * q; i++)
        {
            for (int j = 0; i * i + j * j <= p * p + q * q; j++)
            {
                if (i == 0 && j == 0)
                    continue;
                int ni = i, nj = j;
                if ((ni * p + nj * q) % (ni * ni + nj * nj) == 0 && (ni * q - nj * p) % (ni * ni + nj * nj) == 0)
                    cnt++;
                if (i != 0)
                {
                    ni = -i;
                    if ((ni * p + nj * q) % (ni * ni + nj * nj) == 0 && (ni * q - nj * p) % (ni * ni + nj * nj) == 0)
                        cnt++;

                    if (j != 0)
                    {
                        nj = -j;
                        if ((ni * p + nj * q) % (ni * ni + nj * nj) == 0 && (ni * q - nj * p) % (ni * ni + nj * nj) == 0)
                            cnt++;
                    }
                }
                else
                {
                    nj = -j;
                    if ((ni * p + nj * q) % (ni * ni + nj * nj) == 0 && (ni * q - nj * p) % (ni * ni + nj * nj) == 0)
                        cnt++;
                }
            }
        }
        if (cnt <= 8)
        {
            cout << "P" << endl;
        }
        else
        {
            cout << "C" << endl;
        }
    }
}



Measured memory_bytes: 3216
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <bitset>
#include <map>
#include <unordered_map>
#include <ctime>

using namespace std;

#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

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

const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

const int MAX_N = 1e5 + 10;
int x[MAX_N], y[MAX_N], z[MAX_N];
const int MAX_K = 1001;
const int MAX_S = 3 * MAX_K + 5;
int s[MAX_S];
const int BASE = MAX_K + 1;
int prvX[MAX_N];
int sxs[MAX_N];

typedef bitset<MAX_N> BS;
unordered_map<BS, int> mp;

void f(int n, int k) {
    BS bs;
    rep(sx, k) {
        rep(i, n) bs[i] = (((x[i] + sx) / k) & 1);
        mp[bs] = sx;
    }
}

int main() {
    int n, k;
    cin >> n >> k;
    rep(i, n) {
        char c;
        cin >> x[i] >> y[i] >> c;
        if (c == 'W') z[i] = 1;
        else z[i] = 0;
    }
    f(n, k);
    srand((unsigned)time(NULL));
    while(mp.size() > 410) {
        int x = rand()%mp.size();
        auto it = mp.begin();
        rep(i, x) ++it;
        mp.erase(it);
    }
    int cnt = 0;    
    for (auto& p : mp) sxs[cnt++] = p.se;
    int ans = 0;
    rep(i, cnt) rep(c, 2) {
        int sx = sxs[i];
        // int idxmin = INF, idxmax = -INF;
        rep(i, n) {
            int X = (x[i] + sx) / k;
            int Y = y[i] / k;
            int ymin = Y * k - y[i];
            int ymax = ymin + k;
            if ((X + Y + c) % 2 == z[i]) {
                ymin += k;
                ymax += k;
            }
            s[ymin + BASE] += 1;
            s[ymax + BASE] -= 1;
            // idxmin = min(idxmin, ymin + BASE);
            // idxmax = max(idxmax, ymax + BASE);
        }
        // REP(i, idxmin, idxmax) s[i + 1] += s[i];
        // REP(i, idxmin, idxmax + 1) {
        //     ans = max(ans, s[i]);
        //     s[i] = 0;
        // }
        rep(i, MAX_S - 1) s[i+1] += s[i];
        rep(i, MAX_S) {
            ans = max(ans, s[i]);
            s[i] = 0;
        } 
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 15744
#include <cstdio>

const int mod = 1e9 + 7;
#define maxn 1000010
int f[maxn], g[maxn];
int n;
inline int ff(int x)
{
	if (x < 0) return 1;
	if (f[x]) return f[x];
	if (x == 0) return f[0] = n;
	int ret = ff(x - 1);
	for (int i = 2; i <= n; ++i)
		(ret += ff(x - i - 1)) %= mod;
	return f[x] = ret;
}
int main()
{
	scanf("%d", &n);
	f[0] = 1; g[0] = f[0];
	f[1] = n; g[1] = g[0] + f[1];
	f[2] = (f[1] + n - 1 + 1ll * (n - 1) * (n - 1) % mod) % mod; g[2] = (g[1] + f[2]) % mod;
	for (int i = 3; i <= n; ++i)
	{
		f[i] = ((f[i - 1] + g[i - 3]) % mod + (n - i + 1) + 1ll * (n - 1) * (n - 1)) % mod;
		g[i] = (g[i - 1] + f[i]) % mod;
	}
	printf("%d\n", f[n]);
	return 0;
}

Measured memory_bytes: 7936
n,k,c = list(map(int, input().split()))
s = input()
ls = list(s)

ortho = [0]*k
rever = [0]*k

a = 0
skip = []
for i in range(len(ls)):
    if a >= k: break
    if ls[i] == "o" and i not in skip:
        ortho[a] = i
        a += 1
        skip = [i+j for j in range(1, c+1)]

a = 0
skip = []
ls.reverse()
for i in range(len(ls)):
    if a >= k: break
    if ls[i] == "o" and i not in skip:
        rever[a] = i
        a += 1
        skip = [i+j for j in range(1, c+1)]

rever.reverse()
rever = [len(ls)-1-i for i in rever]

for i in range(k):
    if ortho[i] == rever[i]:
        print(ortho[i]+1)

Measured memory_bytes: 68056
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);    
    int N; cin >> N;
    
    int M; cin >> M;
    
    ll P; cin >> P;
    vector<vpl > graph(N);
    vector<vi > graph2(N);
    F0R(i, M) {
		int A, B, C; cin >> A >> B >> C; A--; B--; C-=P;
		graph[A].pb(mp(B, C)); 
		graph2[B].pb(A);
	}
	
	bool foundEnd[N]; F0R(i, N) foundEnd[i] = false;
	queue<int> q;
	q.push(N-1);
	foundEnd[N-1] = true;
	while (!q.empty()) {
		int cur = q.front(); q.pop();
		F0R(i, sz(graph2[cur])) {
			int nxt = graph2[cur][i];
			if (!foundEnd[nxt]) {
				foundEnd[nxt] = true;
				q.push(nxt);
			}
		}
	}
	
	ll dist[N];
	F0R(i, N) {
		dist[i] = -1000000000000;
	}
	dist[0] = 0;
	
	bool found[N]; F0R(i, N) found[i] = false;
	
	found[0] = true;
	
	F0R(i, N) {
		F0R(j, N) {
			if (dist[j] == -1000000000000) continue;
			F0R(k, sz(graph[j])) {
				int nxt = graph[j][k].f;
				found[nxt] = true;
				if (dist[nxt] < dist[j] + graph[j][k].s) {
					dist[nxt] = dist[j]+graph[j][k].s;
				}
			
			}
		}
	}
	
	/*F0R(i, N) {
		cout << dist[i] << " ";
	} cout << endl;*/
	
	F0R(i, N) {
		F0R(j, sz(graph[i])) {
		
			int k = graph[i][j].f;
			if (dist[k] == -1000000000000 || dist[i] == -1000000000000) continue;
			if (dist[k] < dist[i] + graph[i][j].s && foundEnd[k]) {
				cout << -1 << endl; return 0;
			}
		}
	}
	
	cout << max(0LL, dist[N-1]) << endl;
	
    return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MAX = 5100000;
ll gcd(ll a, ll b) {
    return (b==0) ? a : gcd(b, a%b);
}

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    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(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// 以下から
const int MAX_N = 100000;
struct Edge {
    int to;
    int id;
};

vector<vector<Edge>> g;
vector<int> ans;

void dfs(int v, int c=-1, int p=-1) {
    int k=1;
    rep(i,g[v].size()) {
        int u = g[v][i].to, ei = g[v][i].id;
        if (u==p) continue;
        if (k == c) ++k;
        ans[ei] = k; ++k;
        dfs(u,ans[ei],v);
    }
}
int main() {
    double n; cin >> n;
    const double TAX = 1.08;
    int ans = ceil(n / TAX);
    if ((int)(ans * TAX) == n) {
        cout << ans << endl;
    } else {
        cout << ":(" << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
using namespace std;

int main(){
	long long n;
	cin >> n;
	long long ans=1;
	long long m=1e9+7;
	for(long long i=1;i<=n;i++){
		ans*=i;
		ans=ans%m;
	}
	cout << ans << endl;				
	return 0;
}


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

    if (b != 1 && a > b) {
        cout << "Alice" << endl;
    } else if (a != 1 && a < b) {
        cout << "Bob" << endl;
    } else if (a == b) {
        cout << "Draw" << endl;
    } else if (a == 1 && b != 1) {
        cout << "Alice" << endl;
    } else if (a != 1 && b == 1) {
        cout << "Bob" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const string button[10] ={
  "0", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};

int main(){
  int T;
  cin >> T;
  while(T--){
    string ans = "";
    string s;
    cin >> s;
    
    int tmp;
    for(int i = 0 ; i < s.size() ;i++){
      int cnt = 0;
      tmp = s[i]-'0';
      if(tmp == 0) continue;
      while(1){
	if(s[i] != s[i+1]) break;
	cnt++, i++;
	if(button[tmp].size() == cnt) cnt = 0;
      }
      ans += button[tmp][cnt];
    }
    cout << ans << endl;
  }
  return 0;
}

	

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
	void run() {
		Scanner scan = new Scanner(System.in);
		for (int i = 1;;i++) {
			int s = scan.nextInt();
			if (s == 0) break;
			System.out.println("Case " + i + ": " + s);
		}
	}
	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}
}

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const ll INF = 10e12;

template <typename T>
class RMQ {
	T query(int l, int r, int a, int b, int k){
		if( l <= a && b <= r ){
			return seg[k];
		}else if( l < b && a < r ){
			int m = (b+a)/2;
			T vl = query(l,r, a, m, k*2);
			T vr = query(l,r, m, b, k*2+1);
			return max(vl, vr);	// merge
		}
		return 0;	// default value
	}
public:
	vector<T> seg;	// セグメントツリー (親:k/2  子:k*2,k*2+1)
	int N;
	RMQ(int size){
		N = 1;
		while( N < size ) N<<=1;
		seg.assign(N*2, 0);		// default value
	}
	void update(int pos, T v){
		for(int k=N+pos; k>0; k/=2){
			seg[k] = v;
			v = max(seg[k], seg[k^1]);	// merge
		}
	}
	// [l,r)
	T get(int l, int r){
		return query(l, r, 0, N, 1);
	}
	T get(int pos){		// =get(pos, pos+1)
		return seg[N+pos];
	}
};


ll a[200005];
vector<int> edge[200005];
map<pii,int> zip;
ll ans[200005];
RMQ<ll> seg(400005);
void dfs(int n, int b = -1){
	ll sum = 1 + seg.get(0, zip[pii(a[n], -1)]);
	seg.update(zip[pii(a[n], n)], sum);
	ans[n] = seg.get(0, 400003);
	for(auto t: edge[n]) if(t != b) {
		dfs(t, n);
	}
	seg.update(zip[pii(a[n], n)], 0);
}

int main(){
	ios_base::sync_with_stdio(false);
	int N;

	cin >> N;
	rep(i,N) cin >> a[i];
	rep(i,N-1){
		int u, v;
		cin >> u >> v;
		u--; v--;
		edge[u].push_back(v);
		edge[v].push_back(u);
	}

	rep(i,N){
		zip.emplace(pii(a[i], i), 0);
		zip.emplace(pii(a[i], -1), 0);
	}
	int cnt=0;
	for(auto &p: zip) p.Y = cnt++;

	dfs(0);

	rep(i,N) cout << ans[i] << endl;

	return 0;
}

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

int main(){
    int n,k,d,val=0,cnt=0,p;
    bool a[101];
    memset(a,false,sizeof(a));
    cin>>n>>k;
    while(k--){
        cin>>d;
        while(d--){
            cin>>p;
            a[p]=true;
        }
    }
    for(int i=1;i<=n;i++){
        if(!a[i])cnt++;
        //cout<<a[i]<<" ";
    }
    cout<<cnt<<endl;
    return 0;
}


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

int main(){
    int N;
    cin >> N;
    long takahashi = 1, aoki = 1;
    for(int i = 0; i < N; i++){
        long T, A;
        cin >> T >> A;
        long new_takahashi = max((aoki + A - 1) / A, (takahashi + T - 1) / T) * T;
        long new_aoki = max((aoki + A - 1) / A, (takahashi + T - 1) / T) * A;
        takahashi = max(takahashi, new_takahashi);
        aoki = max(aoki, new_aoki);
    }
    cout << takahashi + aoki << endl;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		ArrayList<Integer> list = new ArrayList<>();

		int i = 0;
		long sum = 0;

		// 入力された数値を配列に入れる
		for (i = 0; i < n; i++) {
			int matrix = sc.nextInt();
			list.add(matrix);
			sum += ((Integer)list.get(i)).intValue();
		}

		int min = list.get(0);
		int max = list.get(0);

		for (i = 0; i < n; i++) {
			if(min > list.get(i)){
				min = list.get(i);
			}

			//最大値を取得
			if(max < list.get(i)){
				max = list.get(i);
	    }}

		System.out.println(min + " " + max + " " + sum);
	}
}


Measured memory_bytes: 42240
#include <iostream>
#include <queue>

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

#define rep(i,n) for(int i=0;i<(n);++i)

const int INF = 1e9;
vector<vector<pii>> edge;

int dijkstra(int start, int end, int N) {
  ll cost[N];
  priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>> > q;
  fill(cost, cost + N, INF); cost[start] = 0;
  q.push(make_pair(0, start));

  while (!q.empty()) {
    pair<ll, int> p = q.top(); q.pop();
    int u = p.second;
    ll cur_cost = p.first;

    if (cost[u] < cur_cost)
      continue;
    for (const auto& v : edge[u]) {
      int to = v.first, c = v.second;
      if (cost[to] > cost[u] + c) {
        cost[to] = cost[u] + c;
        q.push(make_pair(cost[to], to));
      }
    }
  }
  return cost[end];
}

int main() {
  int N, M; cin >> N >> M;
  int S, T;

  edge.resize(3*N, vector<pii>());

  rep(i, M) {
    int u, v; cin >> u >> v;
    --u, --v;
    edge[3*u].emplace_back(3*v+1, 1);
    edge[3*u+1].emplace_back(3*v+2, 1);
    edge[3*u+2].emplace_back(3*v, 1);
  }
  cin >> S >> T;
  --S, --T;

  int ans = dijkstra(3*S, 3*T, 3*N);
  cout << (ans == INF ? -1 : ans / 3) << endl;

  return 0;
}


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

using namespace std;

int main() {
	int N; cin >> N;
	int A, B; cin >> A >> B;
	int C; cin >> C;
	vector<int> D(N);
	for (int i = 0; i < N; ++i) {
		cin >> D[i];
	}
	sort( D.begin(), D.end(), greater<int>() );
	int price = A;
	int del = C;
	int ans = del / price;
	for (int i = 0; i < D.size(); ++i) {
		price += B;
		del += D[i];
		ans = max(ans, del / price);
	}
	cout << ans << endl;
}

Measured memory_bytes: 1216
n, m, c = map(int,input().split())
blist = list(map(int,input().split()))
alist = []
for i in range(n):
  alist.append(list(map(int,input().split())))
  
ans = 0
for j in range(n):
  su = 0
  for k in range(m):
    su += alist[j][k] * blist[k]
  su += c
  if su > 0:
    ans += 1
    
print(ans)
  

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std;

map<int,int> p;

int main()
{
	int n,m,x;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",&x),p[x]++;
	scanf("%d",&m);
	bool flag=true;
	for(int i=0;i<m;i++)
	{
		scanf("%d",&x);
		if(!p[x]) flag=false;
		else p[x]--;
	}
	if(flag) printf("YES\n");
	else printf("NO\n");
}


Measured memory_bytes: 9600
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define ff               first
#define ss               second
#define pb               push_back
#define all(x)           (x).begin(), (x).end()
#define mem0(x)          memset(x, 0, sizeof (x))
#define mem1(x)          memset(x, -1, sizeof (x))

typedef long long ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector <ii> vii;
typedef vector<vii> vvii;
typedef vector <ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vi tr(n);
    for (int i = 0; i < n; ++i) {
        cin >> tr[i];
    }
    sort(all(tr));
    int ans = 0;
    for (int j = 0; j < n; ++j) {
        for (int i = j + 1; i < n; ++i) {
            for (int k = i + 1; k < n; ++k) {
                if (tr[j] + tr[i] > tr[k] && (tr[j] != tr[i] && tr[j] != tr[k] && tr[i] != tr[k])) {
                    ans++;
                }
            }
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3660
v,c,s,a;
main(){
	for(;scanf("%d%c",&v,&c),v;){
		s+=v>10?10:v;
		a|=v==1;
		if(c=='\n'){
			printf("%d\n",a&&s+10<22?s+10:s>21?0:s);
			s=a=0;
		}
	}
	exit(0);
}

Measured memory_bytes: 0
N = gets.to_i
T = []
N.times {
  T << gets.chomp.split.map(&:to_i)
}

t = 0
x = 0
y = 0

count = 0
T.each.with_index do |tr, i|
  t_change = tr[0] - t
  t = tr[0]
  x_change = tr[1] - x
  x = tr[1]
  y_change = tr[2] - y
  y = tr[2]
  if x_change + y_change > t_change || (x_change + y_change).odd? != t_change.odd?
    count = 0
    break
  end
  count += 1
end

if count == N
  puts 'Yes'
else
  puts 'No'
end

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

int main() {
    int A, B;
    cin >> A >> B;
    string tmp;
    int sum_of_palindrome = 0;
    for (int i=0; i < B-A+1; ++i){
        tmp = to_string(A+i);
        bool is_palindrome = true;
        for (int j=0; j<3; ++j){
            if(tmp[j] != tmp[4-j]){
                is_palindrome = false;
                break;
            }
        }
        sum_of_palindrome += is_palindrome;
    }
    cout << sum_of_palindrome << endl;
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1LL << 30;

int main(){
  ll K, N;
  cin >> K >> N;

  vll A(N);
  for(int i = 0; i < N; i++){
    cin >> A.at(i);
  }
  ll l = 0;
  for(int i = 0; i < N; i++){
    if(i == N-1){
      chmax(l, (K-A.at(i) + A.at(0)));
    }
    else chmax(l, A.at(i+1) - A.at(i));
  } 
  cout << K - l << endl;
}

Measured memory_bytes: 1792