akhauriyash/Code-Regression huggingface dataset:
N,K,Q = map(int, input().split())
List = [int(input()) for i in range(Q)]
PList=[K-Q]*N
for i in range(0,Q):
    PList[(List[i])-1]+=1
for j in range(0,N):
    if PList[j]>0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 10472
#include<bits/stdc++.h>
#define MAX_N 100
#define MAX_V 1000
#define INF 1e9
using namespace std;
int n,W[100][100],E[100][100];
string F[100];
int N,K;

struct edge{int to, cap,cost,rev;};
int V;
vector<edge> G[MAX_V];
int dist[MAX_V];
int prevv[MAX_V],preve[MAX_V];

void add_edge(int from,int to,int cap,int cost){
  G[from].push_back((edge){to,cap,cost,G[to].size()});
  G[to].push_back((edge){from,0,-cost,G[from].size()-1});
}

int min_cost_flow(int s,int t,int f){
  int res=0;
  while(f>0){
    fill(dist,dist+V,INF);
    dist[s]=0;
    bool update = true;
    while(update){
      update = false;
      for(int v=0; v<V ;v++){
	if(dist[v]==INF) continue;
	for(int i=0; i<G[v].size(); i++){
	  edge &e = G[v][i];
	  if(e.cap > 0 && dist[e.to] > dist[v]+e.cost) {
	    dist[e.to] = dist[v] + e.cost;
	    prevv[e.to] = v;
	    preve[e.to] = i;
	    update = true;
	  }
	}
      }
    }
    if(dist[t]==INF) return -1;     
    int d = f;
    for(int v=t; v!=s; v=prevv[v])d=min(d,G[prevv[v]][preve[v]].cap);
    f -= d;
    res += d*dist[t];
    for(int v=t; v!=s; v=prevv[v]){
      edge &e = G[prevv[v]][preve[v]];
      e.cap -= d;
      G[v][e.rev].cap += d;
    }
  }
  return res;
}

int Biparite_Matching(){
  int s = N+K, t = s+1;
  for(int i=0; i<N; i++) add_edge(s,i,1,0);
  for(int i=0; i<K; i++) add_edge(N+i,t,1,0);
  int res=0;
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      if(F[i][j]=='o')res+=E[i][j],add_edge(i,N+j,1,-E[i][j]);
      else add_edge(i,N+j,1,W[i][j]);    
  return res+min_cost_flow(s,t,N);
}


int main(){
  cin>>n;
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)cin>>W[i][j];
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)cin>>E[i][j];
  for(int i=0;i<n;i++)cin>>F[i];
  N=K=n,V=2*n+2;
  cout<<Biparite_Matching()<<endl;
  int cnt=0;
  for(int i=0;i<n;i++)
    for(int j=0;j<(int)G[i].size();j++)
      if(G[i][j].cap<=0&&F[i][G[i][j].to-n]=='.')cnt++;
      else if(G[i][j].cap>0&&F[i][G[i][j].to-n]=='o')cnt++;
  cout<<cnt<<endl;
  for(int i=0;i<n;i++)
    for(int j=0;j<(int)G[i].size();j++)
      if(G[i][j].cap<=0&&F[i][G[i][j].to-n]=='.')
	cout<<i+1<<" "<<G[i][j].to-n+1<<" write"<<endl;
      else if(G[i][j].cap>0&&F[i][G[i][j].to-n]=='o')
	cout<<i+1<<" "<<G[i][j].to-n+1<<" erase"<<endl;
  return 0;
}

Measured memory_bytes: 3548
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 0x3f3f3f3f;
const double pi=acos(-1),eps=1e-8;
const int maxn = 1<<17;
const int mod = 1e9+7;
const int N = 1e6+10;
inline int read(){
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}
int main()
{
	long double a,b;
	ULL c;
	cin>>a>>b;
	c=a*b;
	cout<<c<<endl;
	return 0;
}

Measured memory_bytes: 3796
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <ctime>
using namespace std;
const long long INF = 100000000000000000;

/* マンハッタン距離の典型らしい */
void solve()
{
    int N; cin >> N;
    vector<long long > z(N),w(N);
    for (int i = 0; i < N; ++i){
        int x,y; cin >> x >> y;
        z[i] = x+y;
        w[i] = x-y;
    }
   sort(z.begin(),z.end());
   sort(w.begin(),w.end());
   cout << max(z[N-1]-z[0],w[N-1]-w[0]) << endl;
}

int main()
{
    cin.tie();
    ios::sync_with_stdio(false);
    // int ti = clock();
    // input();
    solve();
    // printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC);
    return 0;
}

Measured memory_bytes: 6408
# include <cmath>
# include <iostream>
# include <string>
# include <vector>


using namespace std;


int main() {
    long double a, b, c; cin >> a >> b >> c;

    if (2 * sqrt(a*b) < c - a - b) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 512
#include<stdio.h>
int n,a[100005];
int b[100005],c[100005];
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	int m=0;
	for (int i=1;i<=n;i++){
		for (int j=1;j<=m+1;j++){
			if (j==(m+1)){
				m++;
				b[m]=a[i];
				c[m]=1;
				break;
			}
			if (b[j]==a[i]){
				c[j]++;
				break;
			}
		}
		if (m>3) break;
	}
	if (m>3){
		printf("No");
		return 0;
	}
	if (m==1){
		if (b[1]==0) printf("Yes");else printf("No");
		return 0;
	}
	int k=0;
	int x,y,z;
	x=b[1];
	y=b[2];
	c[1]--;
	c[2]--;
	for (int i=3;i<=n;i++){
		z=x^y;
		for (int j=1;j<=m+1;j++){
			if (j==m+1){
				printf("No");
				return 0;
			}
			if (b[j]==z){
				c[j]--;
				if (c[j]<0){
					printf("No");
					return 0;
				}
				break;
			}
		}
		x=y;
		y=z;
	}
	if ((x^y)!=b[1]) printf("No");else printf("Yes");
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#define ll long long
#define endl '\n'
using namespace std;

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false); ll ret = 0;
    int N, T; cin >> N >> T;
    auto time = new int[N]();
    for(int i = 0; i < N; i++) cin >> time[i];
    
    for(int i = 0; i < N - 1; i++)
    {
        auto acc = min(T, time[i+1] - time[i]);
        ret += acc;
    }
    
    
    cout << ret + T << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

int main(){
    Stream io;
    
    int N, A;
    io.read(N, A);
    N %= 500;
    string ans = "Yes";
    if(N > A) {
        ans = "No";
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
//#define int long long
using namespace __gnu_pbds;
using namespace std;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int a[200010];

signed main()
{
	ios::sync_with_stdio(false);
	int n;cin>>n;
	int all=0;
	for(int i=1;i<=n;i++){
		cin>>a[i];all^=a[i];
	}
	for(int i=1;i<=n;i++){
		cout<<(all^a[i])<<" ";
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 4396
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;
int imap[8][8];
int H, W;
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
int gx, gy;
int d[8][8];
vector<pair<int, int> > foods;

class ant {
public:
    int px, py, life;
    ant(int px, int py, int life) : px(px), py(py), life(life) { }
};

int bfs(int sx, int sy, int tx, int ty) {
    for (int i = 0; i < 8; i++) {
        for (int j = 0; j < 8; j++) d[i][j] = 65;
    }
    int nx, ny, ans = -1;
    queue<ant> q;
    q.push(ant(sx, sy, 6));
    d[sx][sy] = 0;

    while (!q.empty()) {
        ant &a = q.front(); q.pop();
        if (a.life == 0) continue;
        if (a.px == tx && a.py == ty) {ans = d[a.px][a.py]; break; }

        for (int i = 0; i < 4; i++) {
            nx = a.px + dx[i], ny = a.py + dy[i];
            if (nx >= 0 && nx < H && ny >= 0 && ny < W && imap[nx][ny] != 0 && imap[nx][ny] != 2 && d[nx][ny] == 65) {
                q.push(ant(nx, ny, a.life-1));
                d[nx][ny] = d[a.px][a.py]+1;
            }
        }
    }
    return ans;
}

int main()
{
    int sx, sy, ans, curr, cx, cy, dist;
    for (;; ) {
        scanf("%d %d", &W, &H);
        if (W == 0 && H == 0) break;
        ans = 6000;
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                scanf("%d", &imap[i][j]);
                if (imap[i][j] == 2) sx = i, sy = j;
                if (imap[i][j] == 3) { gx = i, gy = j; foods.push_back({i, j}); }
                if (imap[i][j] == 4) foods.push_back({i, j});
            }
        }
        if (foods.size() == 1) printf("%d\n", bfs(sx, sy, gx, gy));
        else {
            foods.push_back({gx, gy});
            do {
                curr = 0;
                cx = sx, cy = sy;
                for (unsigned long i = 0; i < foods.size(); i++) {
                    if (abs(cx - foods[i].first) + abs(cy - foods[i].second) >= 6) { curr = 0; break; }
                    else {
                        dist = bfs(cx, cy, foods[i].first, foods[i].second);
                        if (dist == -1) { curr = 0; break; }
                        else curr += dist;
                        if (foods[i].first == gx && foods[i].second == gy) break;
                        cx = foods[i].first, cy = foods[i].second;
                    }
                }
                if (curr > 0) ans = min(ans, curr);
            }  while (next_permutation(foods.begin(), foods.end()));
            (ans == 6000) ? printf("-1\n") : printf("%d\n", ans);
            foods.clear();
        }
    }
    return 0;
}



Measured memory_bytes: 2608
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
const long long MOD = 1000000007;

signed main(){
    string S;
    cin >> S;
    ll s = 10 * (S[0] - '0') + (S[1] - '0');
    ll t = 10 * (S[2] - '0') + (S[3] - '0');
    bool M1 = (1 <= s && s <= 12);
    bool M2 = (1 <= t && t <= 12);
    if(M1 && M2) PRINT("AMBIGUOUS");
    else if(M1) PRINT("MMYY");
    else if(M2) PRINT("YYMM");
    else PRINT("NA");
    return 0;
}

Measured memory_bytes: 3544
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
#include <climits>
#include <chrono>
#include <fstream>
using namespace std;

#pragma region

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

const double PI = acos(-1.0);

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

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter = " ") { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

#pragma endregion


int main() {
    string s;
    cin >> s;
    s.insert(4, " ");
    cout << s << endl;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
string s,a;
int main() {
	ios::sync_with_stdio(false);
	cin >> s;
	while(s.size()) {
		int len = s.size();
		a = s.substr(len - 5,5);
		if(a == "dream" || a == "erase") {
			s.erase(len - 5,5);
			continue;
		}
		a = s.substr(len - 6,6);
		if(a == "eraser") {
			s.erase(len - 6,6);
			continue;
		}
		a = s.substr(len - 7,7);
		if(a == "dreamer")
			s.erase(len - 7,7);
		else {
			cout << "NO\n";
			return 0;
		}
	}
	cout << "YES\n";
	return 0;
}

Measured memory_bytes: 512
#include <iostream>//cout<<right で右揃え
#include <iomanip>//cout<<setw(数字) で空白による桁揃え
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値
#include <functional>//sort第三引数greater<型名>()で降順
#include <map>

using namespace std;
using ll = long long int;

int main(){
    int n;cin>>n;
    int ans = 0;
    vector<int> p(n);
    for(int i=0;i<n;i++) cin >> p[i];
    for(int i=1;i<n-1;i++) if((p[i-1]<p[i]&&p[i]<p[i+1])||(p[i-1]>p[i]&&p[i]>p[i+1])) ans++;    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define MSET(x,y) memset(x,y,sizeof(x))
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 100005
#define ll long long
#define ld long double
#define INF 1e18
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
ll MOD = 1000000007;
string yes = "Yes\n";
string no = "No\n";

int32_t main() {
  fastio;
  #ifndef ONLINE_JUDGE
  freopen("i.txt", "r", stdin);
  freopen("o.txt", "w", stdout);
  #endif
  ll n;
  cin>>n;
  string s;
  cin>>s;
  ll r=0,w=0;
  for(auto itr : s) 
    if(itr == 'R') r++; 
    else w++;
  if(r==0 or w==0) {
    cout<<0<<endl;
    return 0;
  }
  ll ans = 0;
  for(ll i=0;i<r;i++) {
    if(s[i] != 'R') ans++;
  }
  cout<<ans<<endl;
}

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

int main() {
    string s;
    cin >> s;
    int n = stoi(s);
    int sum = 0;
    for(char c : s){
        sum += c - '0';
    }
    if(n%sum == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
// Author: HarshKumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 4e3, M = 1e9 + 7;
ll f[N][3];
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    string s;
    ll n;
    cin >> n >> s;
    vector<ll> t(n);
    for (ll i = 0; i < n; i++)
    {
        if (s[i] == 'R')
            t[i] = 0;
        if (s[i] == 'G')
            t[i] = 1;
        if (s[i] == 'B')
            t[i] = 2;
        f[i][t[i]]++;
        for (ll j = 0; j < 3; j++)
            if (i)
                f[i][j] += f[i - 1][j];
    }
    ll ans = 0;
    for (ll i = 0; i < n; i++)
    {
        if (!t[i])
            ans += f[i][1] * (f[n - 1][2] - f[i][2]) + f[i][2] * (f[n - 1][1] - f[i][1]);
        else if (t[i] == 1)
            ans += f[i][0] * (f[n - 1][2] - f[i][2]) + f[i][2] * (f[n - 1][0] - f[i][0]);
        else
            ans += f[i][1] * (f[n - 1][0] - f[i][0]) + f[i][0] * (f[n - 1][1] - f[i][1]);
        for (ll j = 1; i - j >= 0 && i + j < n; j++)
            ans -= (t[i - j] != t[i] && t[i + j] != t[i] && t[i - j] != t[i + j]);
    }
    cout << ans;
}

Measured memory_bytes: 3792
// Copyright 2020 yaito3014
#include <bits/stdc++.h>
using namespace std;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int K, A, B;
  cin >> K >> A >> B;
  for (int i = A; i <= B; ++i) {
    if (i % K)continue;
    cout << "OK" << endl;
    return 0;
  }
  cout << "NG" << endl;
}


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

using namespace std;

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

	--x;
	--y;

	vector<int> ans;
	ans.resize(n);

	for(int i = 0; i < n; ++i) {
		for(int j = i + 1; j < n; ++j) {
			int d = j - i;

			d = min(d, abs(i - x) + abs(j - y) + 1);

			d = min(d, abs(i - y) + abs(j - x) + 1);

			++ans[d];
		}
	}
	
	for(int i = 1; i < ans.size(); ++i) {
		cout << ans[i] << '\n';
	}

	return 0;
}

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

#define P 200003
#define N (P * 4 + 400)
#define M 998244353
#define ROOT 3
#define ll long long

int power(int x, int y, int m) {
	int ans = 1;
	for (; y; y >>= 1, x = (ll)x * x % m)
		if (y & 1)
			ans = (ll)ans * x % m;
	return ans;
}
int power(int x, int y) {
	int ans = 1;
	for (; y; y >>= 1, x = (ll)x * x % M)
		if (y & 1)
			ans = (ll)ans * x % M;
	return ans;
}
int limit(int n) {
	int ans = 0;
	for (int i = 1; i < n; i <<= 1)
		ans++;
	return ans;
}
int inv_buf[N << 1], *inv[30], *ptr = inv_buf;
void ntt(int *a, int lim, int flag) {
	int n = 1 << lim;
	if (!inv[lim]) {
		inv[lim] = ptr, ptr += n;
		for (int i = 0; i < n; i++)
			inv[lim][i] = inv[lim][i >> 1] >> 1 | (i & 1 ? n >> 1 : 0);
	}
	for (int i = 0; i < n; i++)
		if (i < inv[lim][i])
			swap(a[i], a[inv[lim][i]]);
	for (int m = 1, k = 2; m < n; m <<= 1, k <<= 1) {
		ll omega = power(ROOT, (M - 1) + flag * (M - 1) / k);
		for (int j = 0; j < n; j += k)
			for (int i = j, omg = 1; i < (j | m); i++, omg = omg * omega % M) {
				int tmp = (ll)omg * a[i | m] % M;
				a[i | m] = (M + a[i] - tmp) % M;
				a[i] = (a[i] + tmp) % M;
			}
	}
	if (flag == -1) {
		ll inv = power(n, M - 2);
		for (int i = 0; i < n; i++)
			a[i] = inv * a[i] % M;
	}
}

int buc[N], lg[N];
int a[N], b[N], q = sqrt(P);
int c[N], d[N], e[N];
ll f[N];

int main() {
	//freopen("ntt.in", "r", stdin);
	lg[1] = 0;
	for (int i = 2, j = 1; i != 1; i = i * 2 % P, j++)
		lg[i] = j;
	int n;
	scanf("%d", &n);
	ll ans = 0;
	for (int i = 1, a; i <= n; i++) {
		scanf("%d", &a);
		if (!a)
			continue;
		ans -= (ll)a * a % P;
		buc[lg[a]]++;
	}
	for (int i = 0; i < P; i++) {
		a[i] = buc[i] / q;
		b[i] = buc[i] % q;
	}
	int lim = limit(P * 2);
	ntt(a, lim, 1);
	ntt(b, lim, 1);
	for (int i = 0; i < (1 << lim); i++) {
		c[i] = (ll)a[i] * a[i] % M;
		d[i] = (ll)a[i] * b[i] * 2 % M;
		e[i] = (ll)b[i] * b[i] % M;
	}
	ntt(c, lim, -1);
	ntt(d, lim, -1);
	ntt(e, lim, -1);
	for (int i = 0; i < P * 2; i++)
		f[i] = e[i] + (ll)d[i] * q + (ll)c[i] * q * q;
	for (int i = 0; i < P - 1; i++)
		f[i] += f[i + P - 1];
	
	for (int i = 0; i < P - 1; i++)
		if (f[i])
			ans += (ll)f[i] * power(2, i, P);
	printf("%lld\n", ans / 2);
}


Measured memory_bytes: 20732
/*
                ******
		
        Author: Nguyen Phuc Chuong

                ******
*/

#include <bits/stdc++.h>

using namespace std;

long long a[10][2];
long long dp[200000];
const long long mod = 998244353;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < k; i++) {
		cin >> a[i][0] >> a[i][1];
	}
	dp[0] = 1;
	dp[1] = -1;
	for (int i = 0; i < n; i++) {
		if (i > 0) {
			dp[i] = (dp[i] + dp[i - 1]) % mod;
		}
		for (int j = 0; j < k; j++) {
			if (i + a[j][0] < n) {
				dp[i + a[j][0]] = (dp[i + a[j][0]] + dp[i]) % mod;
			}
			if (i + a[j][1] + 1 < n) {
				dp[i + a[j][1] + 1] = (dp[i + a[j][1] + 1] - dp[i]) % mod;
				if (dp[i + a[j][1] + 1] < 0) {
					dp[i + a[j][1] + 1] += mod;
				}
			}
		}
	}	
	cout << dp[n - 1];
	return 0;
}


Measured memory_bytes: 5048
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N, K;
    cin >> N >> K;
    int A, B, count1, count2;
    count1=0;
    count2=999999;
    vector<int> vec(105);
    for(int i=0;i<K;i++){
        cin >> A;
        for(int j=0;j<A;j++){
            cin >> B;
            vec.at(B)++;
        }
    }
    for(int i=1;i<N+1;i++){
        if(vec.at(i)==0)count1++;
    }
    cout << count1 << endl;
}

Measured memory_bytes: 3604
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cctype>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<cstring>
//#include<windows.h>
//#include<time.h>
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mer make_pair
#define mme memset
using namespace std;

const double pie1=3.1415926;//π1
const double pie2=3.14159265358979;//π2
const double pie3=3.14159265358979323846;//π3
const int vbi=999999999;
const int vli=-vbi;
const long long vbl=999999999999999999;
const long long vll=-vbl;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<pii,int> piii;
typedef pair<pii,pii> pi4;
typedef pair<pll,ll> plll;
typedef pair<int,pii> ipii;
typedef pair<ll,pll> lpll;
typedef pair<pll,pll> pl4;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef set<int> sti;
typedef set<ll> stl;
typedef set<pii> spi;
typedef set<pll> spl;
priority_queue<int> pqi;
priority_queue<ll> pql;
queue<int> qi;
queue<ll> ql;

/*void bin_v(){
	char bin[1000];
	gets(bin);
}*/

bool pss(int a){
	for(int i=2;i<=sqrt(a);i++)
		if(a%i==0)
			return false;
	return true;
}
/////////////////////////////////////////////////////////////////////////////////////////

int main(){
	//my name is Veex_WCY
	ios::sync_with_stdio(false);
	ll r,l;
	cin>>l>>r;
	ll small,large;
	if(ll(l/2019)*2019<l)
		small=(ll(l/2019)+1)*2019;
	else
		small=ll(l/2019)*2019;
	large=ll(r/2019)*2019;
	if((large-small)/2019>=1)
		cout<<(small*large)%2019;
//	cout<<large<<' '<<small;
	else{
		ll minn=vbl,a,b;
		for(ll i=l;i<r;i++)
			for(ll j=i+1;j<=r;j++)
				if((i*j)%2019<minn){
					minn=(i*j)%2019;
					a=i,b=j;
				}
		cout<<(a*b)%2019;
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
  int a,b;
  string op;
 
  while(true){
    cin >> a>>op>>b;
    if (op=="+") {
      cout << a+b << endl;
    }
    if (op=="-") {
      cout << a-b << endl;
    }
    if (op=="*") {
      cout << a*b << endl;
    }
    if (op=="/") {
      cout << a/b << endl;
    }
    if (op=="?") {
      break;
    }
  }
  return 0;
}



Measured memory_bytes: 3144
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn=200005;
int n,m,a[maxn];
LL ans,sum[maxn];
bool cmp(int A,int B) { return A>B; }
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+1+n,cmp);
	for (int i=1;i<=n;i++) sum[i]=sum[i-1]+a[i];
	m=n>>1;
	ans=sum[m];
	m=n-m-1;
	ans+=sum[m+1]-a[1];
	printf("%lld\n",ans);
	return 0;
}


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

template <typename _tp> inline void read(_tp&x){
	char ch=getchar(),ob=0;x=0;
	while(ch!='-'&&!isdigit(ch))ch=getchar();if(ch=='-')ob=1,ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();if(ob)x=-x;
}

const int N = 201000;
int p[N], n;

struct Tree {
	#define lson l,mid,x<<1
	#define rson mid+1,r,x<<1|1
	int mi[N<<2], arr[N];
	Tree() {arr[0] = 1e9;}
	void build(int l, int r, int x) {
		if(l == r) return mi[x] = l, void();
		int mid = l + r >> 1;
		build(lson), build(rson);
		mi[x] = mi[x << 1 | (arr[mi[x<<1]] > arr[mi[x<<1|1]])];
	}
	int qry(int l, int r, int x, int L, int R) {
		if(L <= l and r <= R) return mi[x];
		int mid = l + r >> 1, t1 = 0, t2 = 0;
		if(L <= mid) t1 = qry(lson, L, R);
		if(mid < R) t2 = qry(rson, L, R);
		return arr[t1] < arr[t2] ? t1 : t2;
	}
	#undef lson
	#undef rson
};

namespace odd {
	Tree T;
	int ed;
	void init(int nn) {
		ed = 0;
		for(int i=1;i<=nn;i+=2)
			T.arr[++ed] = p[i];
		T.build(1, ed, 1);
	}
	inline int f(int x) {return x + 1 >> 1;}
	inline int ff(int x) {return (x << 1) - 1;}
	int qry(int l, int r) {return ff(T.qry(1,ed,1,f(l),f(r)));}
}

namespace even {
	Tree T;
	int ed;
	void init(int nn) {
		ed = 0;
		for(int i=2;i<=nn;i+=2)
			T.arr[++ed] = p[i];
		T.build(1, ed, 1);
	}
	inline int f(int x) {return x >> 1;}
	inline int ff(int x) {return x << 1;}
	int qry(int l, int r) {return ff(T.qry(1,ed,1,f(l),f(r)));}
}

struct node {
	int v0, v1, l, r;
	friend inline bool operator < (const node&A, const node&B) {return p[A.v0] > p[B.v0];}
}h[N];

int tp;

void add(int l, int r) {
	if(l > r) return ;
	node nw;
	if(l&1) {
		nw.v0 = odd::qry(l, r);
		nw.v1 = even::qry(nw.v0+1, r);
	} else {
		nw.v0 = even::qry(l, r);
		nw.v1 = odd::qry(nw.v0+1, r);
	}
	nw.l = l, nw.r = r;
	h[++tp] = nw, push_heap(h+1, h+tp+1);
}

inline void pop() {pop_heap(h+1, h+tp+1), --tp;}

int main() {
	read(n);
	for(int i=1;i<=n;++i) read(p[i]);
	odd::init(n), even::init(n);
	add(1, n);
	for(int t=n>>1;t;--t) {
		node nw = h[1]; pop();
		printf("%d %d ", p[nw.v0], p[nw.v1]);
		add(nw.l, nw.v0-1);
		add(nw.v0+1, nw.v1-1);
		add(nw.v1+1, nw.r);
	}
	return 0;
}

Measured memory_bytes: 11520
import sys
from collections import deque

input = sys.stdin.readline


def solve(H, W, A):
    dist = [[0] + [-1] * W + [0] for _ in range(H + 2)]
    dist[0] = dist[-1] = [0] * (W + 2)

    queue = deque()
    for h in range(1, H + 1):
        for w in range(1, W + 1):
            if A[h][w] == "#":
                dist[h][w] = 0
                queue.append((h, w))

    while queue:
        h, w = queue.popleft()
        d = dist[h][w]
        for i, j in ((1, 0), (-1, 0), (0, 1), (0, -1)):
            y, x = h + i, w + j
            if dist[y][x] == -1:
                dist[y][x] = d + 1
                queue.append((y, x))

    res = max(map(max, dist))
    return res


def main():
    H, W = map(int, input().split())
    A = [None] * (H + 2)
    A[0] = A[-1] = "." * (W + 2)
    for i in range(1, H + 1):
        A[i] = "".join((".", input().rstrip(), "."))

    ans = solve(H, W, A)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 113316
n,a,b,c,*L = map(int,open(0).read().split())
L.sort(reverse = True)

from itertools import product
from copy import deepcopy
li1 = [4,1,2,3]
ans = 10**10
for v in product(li1,repeat = n):
    #print(v)
    num = 0
    A,B,C,NO = [],[],[],[]
    for i in range(n):
        if v[i] == 1:
            #if L[i] not in (a,b,c):
            A.append(L[i])
        elif v[i] == 2:
            #if L[i] not in (a,b,c):
            B.append(L[i])
        elif v[i] == 3:
            #if L[i] not in (a,b,c):
            C.append(L[i])
        elif v[i] == 4:
            NO.append(L[i])
    if A and B and C:
        num +=abs(sum(A)-a) + max(0,(len(A)-1)*10) + abs(sum(B)-b) + max(0,(len(B)-1)*10)+ abs(sum(C)-c) + max(0,(len(C)-1)*10)
        ans = min(ans,num)
    #print(num,ans,A,B,C,max(0,(len(A)-1)*10),max(0,(len(B)-1)*10))
print(ans)

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

using namespace std;

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

    int n , m;
    cin >> n >> m;

    int mx_start = -1e9 , mn_end = 1e9;
    while (m--) {
        int l , r;
        cin >> l >> r;
        mx_start = max(mx_start , l);
        mn_end = min(mn_end , r);
    }

    cout << max(0 , mn_end - mx_start + 1);
}


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

int main(){
	long long n, k, sol;
	cin >> n >> k;
	if (n % k == 0){
		cout << 0 << '\n';
	}else{
		if(n > k){
			n -= n/k * k;
		}
	sol = abs(n - k);
	while(true){
		if (abs(sol - k) < sol){
			sol = abs(sol - k);
			continue;
		}
		break;
	}
		cout << sol << '\n';
	}

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _for(i,a,b) for(int i = (a);i <= (b);++i)
#define LOCAL
typedef long long ll;
const int maxn = 24;
template<typename T>
T read()
{
    T x = 0;
    int w = 1;
    char ch = 0;
    while (ch < '0' || ch > '9')
    {
        if (ch == '-')
        w = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
    {
        x = x * 10 + (ch - '0');
        ch = getchar();
    }
    return x * w;
}
template<typename T>
inline void write(T x)
{
    static int sta[35];
    int top = 0;
    do
    {
        sta[top++] = x % 10, x /= 10;
    } while (x);
    while (top)
    putchar(sta[--top] + 48); // 48 是 '0'
    puts("");
}
int n,m;
char mp[maxn][maxn];
bool vis[maxn][maxn];
int dir[4][2]={1,0,-1,0,0,1,0,-1};
int ans;
struct node
{
    int x,y,c;
};
void bfs(int x,int y)
{
    memset(vis,0,sizeof(vis));
 	vis[x][y]=1;
  	queue<node>q;
    q.push({x,y,0});
    while(!q.empty()){
        node now = q.front();
        ans=max(ans,now.c);
        q.pop();
        for(int i = 0;i < 4;++i){
            node tmp;
            tmp.x = now.x+dir[i][0];
            tmp.y = now.y+dir[i][1];
            tmp.c = now.c+1;
            if(tmp.x<1||tmp.x>n||tmp.y<1||tmp.y>m||vis[tmp.x][tmp.y]||mp[tmp.x][tmp.y]=='#')continue;
            vis[tmp.x][tmp.y]=1;
            q.push(tmp);
        }
    }
}
int main()
{
#ifdef LOCALa
    freopen("simple.in","r",stdin);
    freopen("simple.out","w",stdout);
#endif
    scanf("%d%d",&n,&m);
    for(int i = 1;i <= n;++i)
    for(int j = 1;j <= m;++j)scanf(" %c",&mp[i][j]);
    for(int i = 1;i <= n;++i){
        for(int j = 1;j <= m;++j)
        {
            if(mp[i][j]=='.')bfs(i,j);
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(){
    string s; cin >> s;
    if(s == "SUN") cout << 7;
    else if(s == "MON") cout << 6;
    else if(s == "TUE") cout << 5;
    else if(s == "WED") cout << 4;
    else if(s == "THU") cout << 3;
    else if(s == "FRI") cout << 2;
    else cout << 1;
}

Measured memory_bytes: 256
#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>;
const int mod = 1000000007;
const ll INF = 1001001001;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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


    while(1){
        c -= b;
        if(c<=0){
            puts("Yes");
            return 0;
        }
        a -= d;
        if(a<=0){
            puts("No");
            return 0;
        }
    }
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
using ll = long long;
const ll mod = 1000000007;
const ll INF = 100000000000000000LL;
signed main(){
    int a,b,c;
    cin>>a>>b;
    cout<<(a*a-b)<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll M=1000000007;
int n,k,top,i;
ll ans=1;
char c[200005];
int main()
{
	scanf("%d",&n);
	scanf("%s",c+1);
	for(i=1;i<=n;i++)
		ans=ans*i%M;
	for(i=1;i<=n*2;i++)
	{
		if(c[i]=='B'&&top%2==0)
			top++;
		else
		if(c[i]=='B'&&top%2==1)
		{
			ans=ans*top%M;
			top--;
		}
		else
		if(c[i]=='W'&&top%2==0)
		{
			ans=ans*top%M;
			top--;
		}
		else
		if(c[i]=='W'&&top%2==1)
			top++;
		if(top<0)
		{
			printf("0");
			return 0;
		}
	}
	if(top!=0)
		printf("0");
	else
		cout<<ans;
}


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

string s;

int main(void){
	cin >> s;
	stack<int> st;
	int ans = 0;
	rep(i, s.size()){
		int c = s[i]-'0';
		int pre = -1;
		if(!st.empty()) pre = st.top();
		if(pre != -1 && pre != c){
			st.pop();
			ans++;
		}else{
			st.push(c);
		}
	}
	cout << 2*ans << endl;
	return 0;
}


Measured memory_bytes: 4056
#include<bits/stdc++.h>
using namespace std;
long long wt[200000],v[200000],n;
long long kp[100001][101];
long long knapsack(long long w,long long i)
{
	long long current_w = wt[n-i];
	if(kp[w][i]!=-1)
	{
		return kp[w][i];
	}
	if(w==0 || i==0)
	{
		kp[w][i]=0;
		return 0;
	}
	if(i==1 && w - current_w>=0)
	{
		kp[w][i]=v[n-1];
		return v[n-1];
	}
	if(w - current_w>=0)
	{
		kp[w][i]= max(knapsack(w - current_w,i-1 )+v[n-i],knapsack(w,i-1));
		return kp[w][i];
	}
	else
	{
		kp[w][i] = knapsack(w,i-1);
		return kp[w][i];
	}
	
}
int  main()
{
	long long w;
	cin>>n>>w;
	for (int i = 0; i < 100001; ++i)
	{
		for(int j = 0; j < 101 ;j++)
		{
			kp[i][j] = -1;
		}
	}
	for (long long i = 0; i < n; ++i)
	{
		cin>>wt[i]>>v[i];
	}

	cout<<knapsack(w,n)<<endl;

	
	return 0;
}

Measured memory_bytes: 82176
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  
  int odd = 0;
  for(int i=0; i<N; i++){
    if(vec.at(i) %2 == 1){
      odd++;
    }
  }
  
  if(odd %2 == 1){
    cout << "NO" << endl;
  }
  else{
    cout << "YES" << endl;
  }
}

Measured memory_bytes: 640
#include<stdio.h>

int main(){
	
	int n;
	scanf("%d", &n);
	long long int sum=0;
	for(int i=1; i<=n; i++){
		if(i%3==0 && i%5==0){
			sum+=0;
	
		}
		else if(i%3==0){
			sum+=0;
	
		}
		else if(i%5==0){
			sum+=0;
		
		}
		else{
			sum+=i;
		}
	}
	printf("%lld\n", sum);
	return 0;
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
typedef long long int ll;
using namespace std;
using Graph = vector<vector<int>>;
const int N = 100005;
bool is_prime[N];

void Eratostenes(int X)
{
    rep(i, N)
    {
        is_prime[i] = true;
    }
    reps(i, sqrt(N), 2)
    {
        if (is_prime[i])
        {
            for (ll j = 2; i * j < N; j++)
            {
                is_prime[i * j] = false;
            }
        }
    }
    rep(i, N)
    {
        if (is_prime[i])
        {
            if (X <= i)
            {
                cout << i << endl;
                break;
            }
        }
    }
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int X;
    cin >> X;
    Eratostenes(X);

    //system("pause");
    return 0;
}

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

class Main { 
  public static void main(String[] args) throws java.lang.Exception { 
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 
    
    int[] intArray = Arrays.stream(br.readLine().split(""))
                    .mapToInt(Integer::parseInt)
                    .toArray();
    
    int s1 = intArray[0]; 
    int s2 = intArray[1];
    int s3 = intArray[2];
    
    int count = 0;
    if (s1 == 1){
      count++;
    } if(s2 == 1){
      count++;
    } if(s3 == 1){
       count++;
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 26196
n=int(input())
inf=10000
color=["white" for i in range(n)]
p=[-1 for i in range(n)]
d=[inf for i in range(n)]
M=[[] for i in range(n)]


for i in range(n):
    tmp=list(map(int,input().split()))
    for j in range(n):
        if tmp[j]==-1:
            M[i].append(inf)
        else:
            M[i].append(tmp[j])

def prim():
    d[0]=0
    while True:
        mincost=inf
        for i in range(n):
            if mincost>d[i] and color[i]!="black":
                mincost=d[i]
                u=i
        if mincost==inf:
            break
        color[u]="black"
        for j in range(n):
            if color[j]!="black" and M[u][j]!=inf:
                if M[u][j]<d[j]:
                    d[j]=M[u][j]
                    p[j]=u
                    color[j]="gray"

prim()
print(sum(d))


Measured memory_bytes: 5772
#include <iostream>
using namespace std;
int main() {
    int n,a,b;
    cin >> n >> a >> b;
    int plan1 = n * a;
    int plan2 = b;
    if(plan1 <= plan2) {
        cout << plan1 << endl;
    } else {
        cout << plan2 << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int X=0,N;
        N = input.nextInt();
        for (int i = 1; i <= N; i++) {
            X+=i;
        }
        System.out.println(X);
    }
    
}


Measured memory_bytes: 26852
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		long A = sc.nextLong();
		long B = sc.nextLong();
		long K = sc.nextLong();
		
		if(A > K) {
			A -= K;
		}else {
			B = Math.max(0, B-(K-A));
			A = 0;
		}
		
		out.println(A + " " + B);
		
		sc.close();

	}

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

	@SuppressWarnings("unused")
	private String join(String delimiter, int[] a) {
		StringBuilder sb = new StringBuilder();

		for (int i = 0; i < a.length; i++) {
			sb.append(a[i]);
			sb.append(delimiter);
		}
		return sb.substring(0, Math.max(sb.length() - delimiter.length(), 0));
	}

	@SuppressWarnings("unused")
	private String join(String delimiter, long[] a) {
		StringBuilder sb = new StringBuilder();

		for (int i = 0; i < a.length; i++) {
			sb.append(a[i]);
			sb.append(delimiter);
		}
		return sb.substring(0, Math.max(sb.length() - delimiter.length(), 0));
	}

	@SuppressWarnings("unused")
	private int max(int[] arr) {
		if(arr == null || arr.length == 0) {
			throw new IllegalArgumentException(Arrays.toString(arr));
		}

		int candidate = arr[0];
		for(int i=1;i<arr.length;i++) {
			candidate = candidate > arr[i] ? candidate : arr[i];
		}
		return candidate;
	}

	@SuppressWarnings("unused")
	private long max(long[] arr) {
		if(arr == null || arr.length == 0) {
			throw new IllegalArgumentException(Arrays.toString(arr));
		}

		long candidate = arr[0];
		for(int i=1;i<arr.length;i++) {
			candidate = candidate > arr[i] ? candidate : arr[i];
		}
		return candidate;
	}

	@SuppressWarnings("unused")
	private int min(int[] arr) {
		if(arr == null || arr.length == 0) {
			throw new IllegalArgumentException(Arrays.toString(arr));
		}

		int candidate = arr[0];
		for(int i=1;i<arr.length;i++) {
			candidate = candidate < arr[i] ? candidate : arr[i];
		}
		return candidate;
	}

	@SuppressWarnings("unused")
	private long min(long[] arr) {
		if(arr == null || arr.length == 0) {
			throw new IllegalArgumentException(Arrays.toString(arr));
		}

		long candidate = arr[0];
		for(int i=1;i<arr.length;i++) {
			candidate = candidate < arr[i] ? candidate : arr[i];
		}
		return candidate;
	}

	@SuppressWarnings("unused")
	private int[] nextIntArray(Scanner sc, int n) {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}

	@SuppressWarnings("unused")
	private long[] nextLongArray(Scanner sc, int n) {
		long[] result = new long[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextLong();
		}
		return result;
	}

	@SuppressWarnings("unused")
	private int[] nextIntArray1origin(Scanner sc, int n) {
		int[] result = new int[n + 1];
		for (int i = 1; i <= n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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;
}

const int mod = 1000000007;
const int max_n = 200005;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  bool operator==(const mint &p) const { return x == p.x; }
  bool operator!=(const mint &p) const { return x != p.x; }
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
  mint P(int n, int k){
    return fact[n]*ifact[n-k];
  }
}comb(max_n);

int main(){
    ll n;cin >> n;
    mint a,b,c;cin >> a >> b >> c;
    mint ans=0,s=100;
    rep(i,n){
        ll m=i+n;
        mint ret=comb(m-1,n-1)*m*(a.pow(n)*b.pow(m-n)+a.pow(m-n)*b.pow(n));
        ret/=(a+b).pow(m);
        ans+=ret;
    }
    ans*=s/(s-c);
    cout << ans <<endl;
}


Measured memory_bytes: 6212
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FScanner sc = new FScanner();
		int N = sc.nextInt();
		int[] ary = new int[N];
		int[] sorted = new int[N];
		for (int i = 0; i < N; i++) {
			ary[i] = sc.nextInt();
			sorted[i] = ary[i];
		}
		Arrays.sort(sorted);
		for (int i = 0; i < N; i++) {
			if (sorted[N - 1] == ary[i]) {
				System.out.println(sorted[N - 2]);
			} else {
				System.out.println(sorted[N - 1]);
			}

		}
	}

}

class FScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 71016
#include <iostream>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <vector>
#include <map>
#include <stdio.h>
using namespace std;
int partition(int A[], int P, int R) {
	int X = A[R], i = P - 1;
	for (int j = P; j < R; j++) {
		if (A[j] <= X) {
			i++;
			int t = A[i]; A[i] = A[j]; A[j] = t;
		}
	}
	int t = A[i + 1]; A[i + 1] = A[R]; A[R] = t;
	return i + 1;
}

int main() {
	int N; cin >> N;
	int A[100000];
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	int Q = partition(A, 0, N - 1);
	for (int i = 0; i < N; i++) {
		if (i) cout << ' ';
		if (i == Q) cout << '[';
		cout << A[i];
		if (i == Q) cout << ']';
	}
	cout << endl;
}


Measured memory_bytes: 3476
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i,m,n) for(int i = m - 1; i >= n; i--)
#define ALL(v) v.begin(), v.end()
#define itn int
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define YES() cout << "YES" << endl
#define NO() cout << "NO" << endl
#define println(x) cout << x << endl
#define print(x) cout << x << " "
template<typename T, typename U>
inline bool CMAX(T &m, U x) { if (m < x) { m = x; return true; } return false; }
template<typename T, typename U>
inline bool CMIN(T &m, U x) { if (m > x) { m = x; return true; } return false; }

typedef long long lint;
typedef long double ldouble;
const int INF = 1e9;
const lint LINF = 1e18;
const int MOD = 1e9+7;
int main(){
    int n,x,t;
    cin >> n >> x >> t;
    if(n % x == 0){
        println(t * (n / x));
    }else{
        println(t * ((n / x) + 1));
    }
    return 0;
}

Measured memory_bytes: 3548
#include <iostream>
#include <cmath>
using namespace std;
typedef long long LL;
const int N = 2000 + 10;
const LL INF = 2e9 + 7;
int n;  LL z, w;
LL a[N], dp[N][2];
int main() {
    scanf("%d %lld %lld", &n, &z, &w);
    a[0] = w;
    for (int i = 1; i <= n; i ++) 
        scanf("%lld", &a[i]);
    
    dp[n][0] = dp[n][1] = abs(a[n] - a[n-1]);
    for (int i = n-1; i >= 0; i --) {
        dp[i][0] = dp[i][1] = abs(a[i] - a[n]);
        for (int j = i + 1; j <= n; j ++) {
            dp[i][0] = max(dp[i][0], dp[j][1]);
            dp[i][1] = min(dp[i][1], dp[j][0]);
        }
    }

    printf("%lld\n", dp[0][0]);
}







Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int k = scan.nextInt();
		int b;
		int c;
		boolean[] a = new boolean[n];
		int ans = 0;

		for(int i = 0;i < k;i++) {
			b = scan.nextInt();
			for(int j = 0;j < b;j++) {
				c = scan.nextInt();
				a[c - 1] = true;
			}
		}

		for(int i = 0;i < n;i++) {
			if(!a[i]) {
				ans ++;
			}
		}

		System.out.println(ans);

	}
}

Measured memory_bytes: 37244
N,K = map(int,input().split())
P = list(map(int,input().split()))
ans = 0
E = [p*(p+1)//2/p for p in P]
cE = [E[0]]
for i in range(1,N): cE.append(cE[-1]+E[i])
cE = [0]+cE
sE = []
i = 0
while i+K < len(cE):
    sE.append(cE[i+K]-cE[i])
    i += 1
print(max(sE))

Measured memory_bytes: 30448
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>

using namespace std;

typedef long long ll;

inline ll read()
{
	ll x=0;char ch=getchar();
	while(ch<'0' || '9'<ch)ch=getchar();
	while('0'<=ch && ch<='9')x=x*10+(ch^48),ch=getchar();
	return x;
}

const int N=2009;

ll n,x,ans;
ll a[N],b[N];

inline void chkmin(ll &a,ll b){if(a>b)a=b;}

int main()
{
	n=read();
	x=read();
	for(int i=1;i<=n;i++)
		ans+=(a[i]=b[i]=read());

	ll sum=0;
	for(int i=1;i<=n;i++)
	{
		sum+=x;
		ll tot=0;
		for(int j=1;j<=n;j++)
		{
			chkmin(a[j],b[(j-i>=1)?(j-i):(j-i+n)]);
			tot+=a[j];
		}
		chkmin(ans,tot+sum);
	}

	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 256