akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    ll x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    ll p[a+b], r[c];
    rep(i,a+b)cin >> p[i];
    rep(i,c)cin >> r[i];
    vector<P> v;
    rep(i,a+b){
        P pp;
        pp.first = p[i];
        if(i < a)pp.second = 0;
        else pp.second = 1;
        v.push_back(pp);
    }
    sort(v.begin(), v.end(), greater<P>());
    sort(r,r+c,greater<ll>());

    ll ans = 0;
    int i = 0, j = 0;
    int ii = 0, jj = 0;

    rep(loop, x+y){
        if(ii == x){
            while(v[i].second == 0)i++;
        }
        if(jj == y){
            while(v[i].second == 1)i++;
        }
        if(i == a + b){
            ans += r[j];
            j++;
        }else if(j == c){
            ans += v[i].first;
            if(v[i].second == 0)ii++;
            else jj++;
            i++;
        }else{
            if(v[i].first >= r[j]){
                ans += v[i].first;
                if(v[i].second == 0)ii++;
                else jj++;
                i++;
            }else{
                ans += r[j];
                j++;
            }
        }
    }

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


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

void selectionSort(int A[], int N) {
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        int minj = i;
        for (int j = N -1; j > i; j--) {
            if (A[minj] >= A[j]) {
                minj = j;
            }
        }
        
        if (A[i] > A[minj]) {
            cnt++;
            int tmp = A[minj];
            A[minj] = A[i];
            A[i] = tmp;
        }
    }
    for (int i = 0; i < N; i++) {
        printf("%d", A[i]);
        if (i != N - 1) {
            printf(" ");
        } else {
            printf("\n");
        }
    }
    printf("%d\n", cnt);
}

int main(void) {
    int N;
    cin >> N;

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

    selectionSort(A, N);
    
    return 0;
}


Measured memory_bytes: 3224
#include <stdio.h>

int leap_year(int a, int b)
{
	b = b - b % 4;
	if (a % 4 == 0) {
		a -= 4;
	}
	else {
		a = a - a % 4;
	}
	return (b - a) / 4;
}
int main(void)
{

	while (1) {
		static int first_space = 1;

		int a, b;
		scanf("%d %d", &a, &b);
		if (a == 0 && b == 0) {
			break;
		}
		if (first_space == 0) {
			printf("\n");
		}
		if (first_space == 1) {
			first_space = 0;
		}
		int n = leap_year(a, b) + 1;
		if (n == 1) {
			printf("NA\n");
		}
		if (!a == 0 || ! b == 0) {
			if (a % 4 == 0) {
				a -= 4;
			}
			int i;
			for (i = 1; i < n; i++) {
				int year = a - a % 4 + 4 * i;
				if (year % 100 == 0 && !(year % 400 == 0)) {
					continue;
				}
				printf("%d\n", year);
			}
		}
	}
	return 0;
}

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

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#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()
#define dump(x) cerr << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

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

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

const ll MOD = TEN(9) + 7;

ll powmod(ll x, ll k) {
	ll res = 1;
	for (; k; x = x * x % MOD, k /= 2) {
		if (k & 1) {
			res = res * x % MOD;
		}
	}
	return res;
}

const int MX = 60;

V<int> g[MX];
int ord[MX], low[MX];
bool vis[MX];

void dfs(int v, int p, int &k) {
	vis[v] = true;
	
	ord[v] = k++;
	low[v] = ord[v];
	
	for (int to : g[v]) {
		if (!vis[to]) {
			dfs(to, v, k);
			low[v] = min(low[v], low[to]);
		} else if (to != p) {
			low[v] = min(low[v], ord[to]);
		}
	}
}

VV<pii> bc;
V<pii> tmp;

void gen(int v, int p) {
	vis[v] = 1;
	for (int to : g[v]) if (to != p) {
		if (!vis[to] || ord[to] < ord[v]) {
			tmp.eb(min(v, to), max(v, to));
		}
		if (!vis[to]) {
			gen(to, v);
			if (low[to] >= ord[v]) {
				bc.eb();
				while (true) {
					auto e = tmp.back();
					bc.back().eb(e);
					tmp.pop_back();
					if (e.fi == min(to, v) && e.se == max(to, v)) {
						break;
					}
				}
			}
		}
	}
}

const int maxe = 200;
ll comb[maxe][maxe];
ll pw[maxe];

int main() {
	int N, M, K; cin >> N >> M >> K;
	rep(i, M) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		g[a].pb(b); g[b].pb(a);
	}

	pw[0] = 1;
	rep(i, maxe - 1) {
		pw[i+1] = pw[i] * K % MOD;
	}

	rep(i, maxe) {
		comb[i][0] = comb[i][i] = 1;
		for (int j = 1; j < i; ++j) {
			comb[i][j] = (comb[i-1][j-1] + comb[i-1][j]) % MOD;
		}
	}

	int now = 0;

	rep(i, N) {
		if (!vis[i]) {
			dfs(i, -1, now);
		}
	}

	memset(vis, 0, sizeof(vis));

	rep(i, N) {
		if (!vis[i]) {
			gen(i, -1);
		}
	}

	ll ans = 1;

	for (auto& vec : bc) {
		if (vec.size() == 1) {
			ans = ans * K % MOD;
		} else {
			set<int> st;
			for (auto e : vec) {
				st.insert(e.fi);
				st.insert(e.se);
			}
			int e = vec.size();
			if (st.size() < e) {
				ans = ans * comb[e + K - 1][K - 1] % MOD;
			} else {
				ll v = 0;
				rep(i, e) {
					v = v + pw[__gcd(e, i)];
					v %= MOD;
				}
				v = v * powmod(e, MOD - 2) % MOD;
				ans = ans * v % MOD;				
			}
		}
	}

	cout << ans << endl;

	return 0;
}

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

int main(void){
  char a;
  cin >> a;
  
  if( a == 'a' || a == 'i' || a == 'u' || a == 'e' || a == 'o')
    cout << "vowel" << endl;
  else
    cout << "consonant" << endl;
  
  return 0;
}

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

#ifndef MAX
#define MAX 400000
#endif

//Range Add Query+Range Sum Query
template<class T>
class RAQ_RSQ {
public:
	int n;
	T dat[MAX], lazy[MAX], ZERO;
	void init(int n_) {
		ZERO = T();
		n = 1; while (n < n_)n <<= 1;
		for (int i = 0; i < 2 * n - 1; i++) {
			dat[i] = lazy[i] = ZERO;
		}
	}
	inline void push(int k, int s) {
		dat[k] = dat[k] + lazy[k] * s;
		if (k < n - 1) {
			lazy[k * 2 + 1] = lazy[k * 2 + 1] + lazy[k];
			lazy[k * 2 + 2] = lazy[k * 2 + 2] + lazy[k];
		}
		lazy[k] = ZERO;
	}
	inline void update_node(int k) {
		dat[k] = dat[k * 2 + 1] + dat[k * 2 + 2];
	}
	inline void update(int a, int b, T x, int k, int l, int r) {
		push(k, r - l);
		if (r <= a || b <= l)return;
		if (a <= l&&r <= b) {
			lazy[k] = lazy[k] + x; push(k, r - l); return;
		}
		update(a, b, x, k * 2 + 1, l, (l + r) / 2);
		update(a, b, x, k * 2 + 2, (l + r) / 2, r);
		update_node(k);
	}
	inline T query(int a, int b, int k, int l, int r) {
		push(k, r - l);
		if (r <= a || b <= l)return ZERO;
		if (a <= l&&r <= b)return dat[k];
		T lb = query(a, b, k * 2 + 1, l, (l + r) / 2);
		T rb = query(a, b, k * 2 + 2, (l + r) / 2, r);
		update_node(k);
		return lb + rb;
	}
	inline void update(int a, int b, T x) {
		update(a, b, x, 0, 0, n);
	}
	inline void update(int a, T x) {
		update(a, a + 1, x);
	}
	inline T query(int a, int b) {
		return query(a, b, 0, 0, n);
	}
	inline T query(int a) {
		return query(a, a + 1);
	}
};

vector<int>E[200000];
int par[200000],d[200000],sub[200000];
int chain[200000],vid[200000];
int node_num;

void dfs(int v,int p,int dep){
	par[v]=p;d[v]=dep;
	sub[v]=1;
	for(int u:E[v]){
		if(u==p)continue;
		dfs(u,v,dep+1);
		sub[v]+=sub[u];
	}
}
void hld(int v,int k){
	chain[v]=k;
	vid[v]=node_num++;
	int Max=0,id=-1;
	for(int u:E[v]){
		if(u==par[v])continue;
		if(Max<sub[u]){
			Max=sub[u];
			id=u;
		}
	}
	if(id==-1)return;
	hld(id,chain[v]);
	for(int u:E[v]){
		if(u==id||u==par[v])continue;
		hld(u,u);
	}
}
void query(int u,int v,function<void(int,int)>f){
	while(1){
		if(d[chain[u]]>d[chain[v]])swap(u,v);
		if(chain[u]==chain[v]){
			f(min(vid[u],vid[v])+1,max(vid[u],vid[v])+1);
			break;
		}
		else{
			f(vid[chain[v]],vid[v]+1);
			v=par[chain[v]];
		}
	}
}

RAQ_RSQ<ll>seg;
int main(){
	int n;scanf("%d",&n);
	rep(i,n){
		int k;scanf("%d",&k);
		rep(j,k){
			int c;scanf("%d",&c);
			E[i].push_back(c);
		}
	}
	dfs(0,-1,0);
	hld(0,0);
	seg.init(n);
	int q;scanf("%d",&q);
	rep(i,q){
		int t;scanf("%d",&t);
		if(t==0){
			int v,w;scanf("%d%d",&v,&w);
			query(0,v,[&](int l,int r){seg.update(l,r,w);});
		}
		else{
			int u;scanf("%d",&u);
			ll res=0;
			query(0,u,[&](int l,int r){res+=seg.query(l,r);});
			printf("%lld\n",res);
		}
	}
}


Measured memory_bytes: 24936
#include <bits/stdc++.h>
using namespace std;
#define MAX_N 100000
#define MAX_M 100000
const int INF = 1e9;

int main (){
  int n,ans=0;
  cin>>n;
  vector<int> A(n);
  for(int i=0;i<n;i++) cin>>A[i];
  for(int i=0;i<n;i++){
    int minj=i;
    for(int j=i;j<n;j++){
      if(A[j]<A[minj]){
        minj=j;
      }
    }
    if(i!=minj){
      ans++;
      swap(A[i],A[minj]);
    }
  }
  for(int i=0;i<n;i++){
    cout<<A[i];
    if(i+1<n) cout<<" ";
  }
  cout<<endl;
  cout<<ans<<endl;
}


Measured memory_bytes: 3080
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)

	var s string
	if sc.Scan() {
		s = sc.Text()
	}

	var result = strings.Replace(s, "2017", "2018", 1)

	fmt.Println(result)
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n, t;
  cin >> n >> t;
  int cnt = 0;
  int val = 0;
  int mi = 2e9;
  rep(i, n) {
    int a;
    cin >> a;
    if (mi > a) {
      mi = a;
    } else {
      if (val < a - mi) {
        cnt = 1;
        val = a - mi;
      } else if (val == a - mi) {
        cnt += 1;
      }
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  vector<vector<string>> A(3,vector<string>(3));
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin >> A[i][j];
    }
  }
  int N;
  cin >> N;
  for(int k=0;k<N;k++){
    string a;
    cin >> a;
    for(int i=0;i<3;i++){
      for(int j=0;j<3;j++){
        if(A[i][j] == a){
          A[i][j] = "**";
        }
      }
    }
  }
  bool flag = false;
  for(int i=0;i<3;i++){
    if(A[i][0] == "**" && A[i][1] == "**" && A[i][2] == "**"){
      cout << "Yes" << endl;
      flag = true;
      return 0;
    }else if(A[0][i] =="**" && A[1][i] == "**" && A[2][i] == "**"){
      cout << "Yes" << endl;
      flag = true;
      return 0;
    }else if(A[0][0] == "**" && A[1][1] == "**" && A[2][2] == "**"){
      cout << "Yes" << endl;
      flag = true;
      return 0;
    }else if(A[0][2] == "**" && A[1][1] == "**" && A[2][0] == "**"){
      cout << "Yes" << endl;
      flag = true;
      return 0;
    }      
  }
  if(flag == false){
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
n, x, y = map(int,input().split())
g = [[] for _ in range(n)]
g[0].append(1)
g[n-1].append(n-2)
g[x-1].append(y-1)
g[y-1].append(x-1)
for i in range(n-2):
    g[i+1].append(i)
    g[i+1].append(i+2)


from collections import deque
def bfs(u):
    queue = deque([u])
    d = [None] * n # uからの距離の初期化
    d[u] = 0 # 自分との距離は0
    while queue:
        v = queue.popleft()
        for i in g[v]:
            if d[i] is None:
                d[i] = d[v] + 1
                queue.append(i)
    return d

ans_dist = [0 for i in range(n)]

for i in range(n):
    D = bfs(i)
    for d in D:
        ans_dist[d] += 1

for i in range(n-1):
    print(ans_dist[i+1]//2)

Measured memory_bytes: 9876
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
 
using namespace std;
typedef long long ll;
const ll INF = 1e18;

# define rep(i, n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(ll i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(ll i=((int)(n)); i>0; --i)
# define all(x) (x).begin(), (x).end()
# define pb push_back
 
ll N, x;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> N >> x;
    vector<ll> a(N);
    
    rep(i,N) {
        cin >> a[i];
    }

    sort(all(a));
    
    ll ans = 0;
    rep(i,N) {
        x -= a[i];
        if (x >= 0) {
            ans++;
        } else {
            break;
        }
    }
    
    if (x > 0) {
        // 残念、余らせてしまいました
        cout << ans-1 << endl;
    } else {
        cout << ans << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string a,b;
  cin >> a;
  cin >> b;
  
  b.erase( --b.end() );
  
  if(string(b).compare(a)==0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
  return 0;
}

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

int main() {
	int n, t, a; cin >> n >> t >> a;
	int h[n];
	for(int i = 0; i < n; i++) cin >> h[i];

	double tmp = 1e9;
	int res = 0;
	for (int i = 0; i < n; i++)
	{
		if(tmp > abs(t - 0.006 * h[i] - a)) {
			tmp = abs(t - 0.006 * h[i] - a);
			res = i;
		}
	}
	cout << res + 1 << endl;
	return 0;
}


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

using namespace std;

typedef pair<int, int> P_ii;
typedef pair<string, int> P_si;
typedef long long int ll;

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 int MOD = 1000000007;
const int MAX = 100100;

int main() {
    string S;
    cin >> S;
    S = "#" + S;
    vector<vector<ll> > dp(MAX, vector<ll>(14));
    dp[0][0] = 1;
    for (int index = 1; index < (int) S.size(); ++index) {
        for (int before = 0; before < 13; ++before) {
            for (int digit = 0; digit < 10; ++digit) {
                // '?'じゃないときはdigitのみ更新
                if (S[index] != '?' && S[index] - '0' != digit) continue;
                int after = (before * 10 + digit) % 13;
                dp[index][after] += dp[index - 1][before];
                dp[index][after] %= MOD;
            }
        }
    }
    printf("%lld\n", dp[S.size() - 1][5]);
    return 0;
}



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

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

using namespace std;

// data
int n, k;
vector<int> wsum;

bool validCap(int P);
int main(){
    // input 
    cin >> n >> k;
    int sum = 0, wi;
    r(i, n){
        cin  >> wi;
        sum += wi;
        wsum.push_back(sum);
    }

    // binary search
    int Pl = 0, Pr = wsum[wsum.size()-1];
    while(true){
        int P = (Pl+Pr)/2;
        if(validCap(P)){
            Pr = P; 
        }else{
            Pl = P;
        }

        if(Pr-Pl <= 1){
            break;
        }
    }

    cout << Pr << endl;
}

bool validCap(int P){
    int maxW = 0;
    r(i, k){
        vector<int>::iterator pos = upper_bound(wsum.begin(), wsum.end(), maxW+P)-1;
        maxW = *pos;
        if(maxW >= wsum[wsum.size()-1])
            return true;
    }
    return false;
}


Measured memory_bytes: 3544
#include <bits/stdc++.h>
using namespace std;
constexpr int64_t mod = 998244353;

template <uint32_t mod>
class modint{
    uint64_t value;
public:
    constexpr modint(const int64_t x=0) noexcept: value(x % mod + (x < 0 ? mod : 0)){ }
    constexpr explicit operator uint64_t() const noexcept{ return value; }
    constexpr modint inverse() const noexcept{ return pow(*this, mod-2); }
    constexpr bool operator==(const modint &rhs) const noexcept{ return value == rhs.value; }
    constexpr bool operator!=(const modint &rhs) const noexcept{ return value != rhs.value; }
    constexpr modint operator+() const noexcept{ return modint(*this); }
    constexpr modint operator-() const noexcept{ return modint(mod - value); }
    constexpr modint operator+(const modint &rhs) const noexcept{ return modint(*this) += rhs; }
    constexpr modint operator-(const modint &rhs) const noexcept{ return modint(*this) -= rhs; }
    constexpr modint operator*(const modint &rhs) const noexcept{ return modint(*this) *= rhs; }
    constexpr modint operator/(const modint &rhs) const noexcept{ return modint(*this) /= rhs; }
    constexpr modint &operator+=(const modint &rhs) noexcept{
        if((value += rhs.value) >= mod) value -= mod;
        return *this;
    }
    constexpr modint &operator-=(const modint &rhs) noexcept{ return *this += mod - rhs.value; }
    constexpr modint &operator*=(const modint &rhs) noexcept{
        if((value *= rhs.value) >= mod) value %= mod;
        return *this;
    }
    constexpr modint &operator/=(const modint &rhs) noexcept{ return *this *= rhs.inverse(); }
    constexpr modint operator++(int) noexcept{
        modint ret(*this);
        if((++value) >= mod) value -= mod;
        return ret;
    }
    constexpr modint operator--(int) noexcept{
        modint ret(*this);
        if((value += mod - 1) >= mod) value -= mod;
        return ret;
    }
    constexpr modint &operator++() noexcept{ return *this += 1; }
    constexpr modint &operator--() noexcept{ return *this -= 1; }
    friend std::ostream &operator<<(std::ostream &os, const modint<mod> &x){ return os << x.value; }
    friend std::istream &operator>>(std::istream &is, modint<mod> &x){
        int64_t i;
        is >> i;
        x = modint<mod>(i);
        return is;
    }
    friend constexpr modint<mod> pow(const modint<mod> &x, uint64_t y){
        modint<mod> ret{1}, m{x};
        while(y > 0){
            if(y & 1) ret *= m;
            m *= m;
            y >>= 1;
        }
        return ret;
    }
};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n, s, a[3000];
    cin >> n >> s;
    for(int i=0;i<n;++i) cin >> a[i];

    static modint<mod> dp[3000], ans = 0;
    for(int i=0;i<n;++i){
        dp[0] = i + 1;
        if(a[i] > s) continue;
        ans += dp[s - a[i]] * (n - i);
        for(int j=s-1;j-a[i]>=0;--j){
            dp[j] += dp[j-a[i]];
        }
    }
    cout << ans << endl;

    
    return 0;
}

Measured memory_bytes: 256
//shan61916
#include <bits/stdc++.h>
  using namespace std;
typedef   long long ll;
typedef   unsigned long long ull ;
typedef   double dll ;

#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 


int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  ll n; 
  cin >> n;
  vector<ll> a(n), b(n), c(n, 0);
  for(ll i = 0; i < n; i++) {
  	cin >> a[i];
  	a[i]--;
  }
  for(ll i = 0; i < n; i++) cin >> b[i] ;
  for(ll i = 0; i < n-1; i++) cin >> c[i];
  ll prev = -2, tot = 0;
  for(ll i = 0; i < n; i++) {
  	tot+= b[a[i]];
  	if(prev+1 == a[i]) tot+= c[prev]; 
  	prev = a[i];
  }
  cout << tot << endl;
  return 0;
} //good night.

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

int main()
{
	int N,A,B;
	string number;
	int sum=0;
	int ans=0;

	cin >> N >> A >> B;

	for(int i=1;i<=N;i++)
	{
		sum=0;
		number = std::to_string(i);
		for(int j=0 ; j<number.length() ; j++)
		{
			sum = sum + number[j] - '0';
//			cout << "i: " << i << "  j: " << j << "  sum: " << sum << endl;
		}
		if((sum>=A) && (sum<=B))
		{
//			cout << "good " << sum << endl;
			ans=ans+i;
		}
	}

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

Measured memory_bytes: 256
// <IN THE NAME OF GOD>
#include <bits/stdc++.h>
#define ll long long 
using namespace std;
 
const int N = 101;
char a[N][N];

void solve() {
	ll n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			cin >> a[i][j];
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (i == 1 and j == 1 and a[i][j] == '#') {
				if (a[i + 1][j] == '.' and a[i][j + 1] == '.') {
					cout << "No";
					return;
				}
			}
			else if (i == 1 and j == m and a[i][j] == '#') {
				if (a[i][j - 1] == '.' and a[i + 1][j] == '.') {
					cout << "No";
					return;
				}
			}
			else if (i == n and m == 1 and a[i][j] == '#') {
				if (a[i - 1][j] == '.' and a[i][j + 1] == '.') {
					cout << "No";
					return;
				}
			} 
			else if (i == n and j == m and a[i][j] == '#') {
				if (a[i - 1][j] == '.' and a[i][j - 1] == '.') {
					cout << "No";
					return;
				}
			}
			else if (i == 1 and a[i][j] == '#') {
				if (a[i][j - 1] == '.' and a[i][j + 1] == '.' and a[i + 1][j] == '.') {
					cout << "No";
					return;
				}
			} 
			else if (i == n and a[i][j] == '#') {
				if (a[i][j - 1] == '.' and a[i][j + 1] == '.' and a[i - 1][j] == '.') {
					cout << "No";
					return;
				}
			}
			else if (j == 1 and a[i][j] == '#') {
				if (a[i - 1][j] == '.' and a[i + 1][j] == '.' and a[i][j + 1] == '.') {
					cout << "No";
					return;
				}
			} 
			else if (j == m and a[i][j] == '#') {
				if (a[i - 1][j] == '.' and a[i + 1][j] == '.' and a[i][j - 1] == '.') {
					cout << "No";
					return;
				}
			}
			else {
				if (a[i][j] == '#' and a[i - 1][j] == '.' and a[i + 1][j] == '.' and a[i][j - 1] == '.' and a[i][j + 1] == '.') {
					cout << "No";
					return;
				}
			}
		}
	}
	cout << "Yes";
	return;
}

int main() {
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	solve();	
	return 0;
}

Measured memory_bytes: 3684
const lines=readlines(open("/dev/fd/0"))
let
    state=0
    global input
    input()=lines[state+=1]
end
int(s::String)=parse(Int32,s)
intSub(s::SubString{String})=parse(Int32,s)
intLine()=map(intSub,split(input()))
function main()
    println(*(intLine()...)%2<1 ? "No" : "Yes")
end
main()

Measured memory_bytes: 115976
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int L = sc.nextInt();
    String result = "";
    List<String> word = new ArrayList<String>();
    for(int i=0; i<N; i++){
      word.add(sc.next());
    }
    Collections.sort(word);
    for(String string : word){
    result += string;
    }
    System.out.println(result);
  }
}

Measured memory_bytes: 24276
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template<class _T> static void getint(_T& a) {
	std::cin >> a;
}
template<class _T> static void getint(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void getint(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}

static void D();

int main()
{
	D();
	fflush(stdout);
	return 0;
}

static void D()
{
	int N;
	getint(N);

	LLONG sum = 0;
	std::map<int, int> ai;
	for (int i = 0; i < N; i++) {
		int a;
		getint(a);
		ai[a]++;
		sum += a;
	}

	int Q;
	LLONG bi, ci;
	getint(Q);
	std::vector<LLONG> ans(Q, 0);
	for (int i = 0; i < Q; i++) {
		getint(bi, ci);
		LLONG biCnt = ai[bi];
		LLONG biSum = biCnt * bi;
		ai[bi] = 0;
		ai[ci] += biCnt;
		LLONG ciSum = biCnt * ci;
		ans[i] = sum = sum - biSum + ciSum;
	}
	for (int i = 0; i < Q; i++) {
		printf("%lld\n", ans[i]);
	}
}


Measured memory_bytes: 8536
#include<bits/stdc++.h>
using namespace std;
 
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n - 1; i >= (ll)(m); i--)
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
void debug(vector<vector<ll>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
void debug(vector<ll>v,ll n){cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
vector<vector<ll>>vec(ll x, ll y, ll w){
  vector<vector<ll>>v(x,vector<ll>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}
//m.emplace(x,0).fi->se++;
 
ll MAX_V = 3000; //頂点数
struct edge {
    ll to;
    ll cost;
};
vector<vector<struct edge>> G(MAX_V); //隣接リスト
vector<ll> d(MAX_V); //各頂点への最短距離
vector<ll> neg(MAX_V,0);
ll n;
bool bellmanford(ll s){
  fill(ALL(d), INF);
  d[s]=0;
  for(ll i=0;i<2*MAX_V;i++){
    for(ll j=0;j<G.size();j++){
      for(ll k=0;k<G[j].size();k++){
        struct edge e=G[j][k];
        if(d[e.to]>d[j]+e.cost){
          d[e.to]=d[j]+e.cost;
          if(i>=MAX_V-1&&e.to==n){
            return false;
          }
        }
      }
    }
  }
  return true;
}
 
 
int main(){
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  ll m,p;cin>>n>>m>>p;
  vector<ll> u(m),v(m),a(m);
  for(ll i=0;i<m;i++){
    cin>>u[i]>>v[i]>>a[i];
    struct edge e ={v[i],p-a[i]};
    G[u[i]].push_back(e);
  }
  if(bellmanford(1)){
    cout<<max(0LL,-d[n])<<endl;
  }
  else{
    cout<<-1<<endl;
  }
  return 0;
}

Measured memory_bytes: 768
#include <stdio.h>
int main(void){
	int N;
	scanf("%d",&N);
	int l[N],r[N];
	for(int i=0;i<N;i++){
		scanf("%d %d",&l[i],&r[i]);
	}
	long sum =0;
	for(int i=0;i<N;i++){
		sum += r[i]-l[i]+1;
	}
	printf("%d",sum);
}

Measured memory_bytes: 128
import java.util.Scanner;

class Main{
 public static void main(String[] args){

 Scanner sc = new Scanner(System.in);

    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();

if (a<=b && b<=c){
System.out.println(a+" "+b+" "+c);
}else if (a<=c && c<=b){
System.out.println(a+" "+c+" "+b);
}else if (b<=a && a<=c){
System.out.println(b+" "+a+" "+c);
}else if (b<=c && c<=a){
System.out.println(b+" "+c+" "+a);
}else if (c<=a && a<=b){
System.out.println(c+" "+a+" "+b);
}else if (c<=b && b<=a){
System.out.println(c+" "+b+" "+a);
}

}
}



Measured memory_bytes: 26128
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 100000000
#define INFLL 100000000000
#define MOD 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

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 N, M;
string s;
int memo[110000];

vector<int> search(int n) {
  vector<int> new_v;

  if (n <= M) {
    if (s[n] == '1') {
      return new_v;
    } else {
      new_v.push_back(n);
      return new_v;
    }
  } else {
    if (memo[n] != 0) {
      vector<int> tmp = search(n - memo[n]);
      if (tmp.empty()) {
        return new_v;
      } else {
        tmp.push_back(memo[n]);
        return tmp;
      }
    } else {
      return new_v;
    }
  }
}

int main () {
  cin >> N >> M;
  cin >> s;

  for (int i=M+1;i<=N;++i) {
    if (s[i] == '1') {
      continue;
    }

    for (int j=M;j>=1;--j) {
      if (s[i-j] == '0') {
        memo[i] = j;
        //cout << j << "\n";
        break;
      }
    }
  }

  //rep(k, N) {
  //  if (!v[k].empty()) {
  //    cout << k << "\n";
  //    Rep(i, v[k].size() - 1) {
  //      cout << v[k][i] << " ";
  //    }
  //    cout << v[k][v[k].size() - 1] << "\n";
  //  }
  //}

  vector<int> ans = search(N);

  if (ans.empty()) {
    cout << -1 << "\n";
  } else {
    Rep(i, ans.size() - 1) {
      cout << ans[i] << " ";
    }
    cout << ans[ans.size() - 1] << "\n";
  }

}

Measured memory_bytes: 12412
import java.util.*;

public class Main {
	public static int n[][] = {{1,1},{0,1},{-1,1},{1,0},{-1,0},{0,-1}};
	public static void main(String[] args) {
			Scanner scan =  new Scanner(System.in);
			for(int i=0;i<5;i++){
				if(scan.nextInt() == 0){
					System.out.println(i+1);
					break;
				}
			}
	}
}


Measured memory_bytes: 27080
def resolve():
    n = int(input())
    nums = []

    for i in range(n):
        input_num = int(input())
        nums.append(input_num)

    max_num, second_num = max(nums[0], nums[1]), min(nums[0], nums[1])

    for i in range(2, n):
        if nums[i] > max_num:
            second_num = max_num
            max_num = nums[i]
        elif nums[i] > second_num:
            second_num = nums[i]

    for i in nums:
        if i == max_num:
            print(second_num)
        else:
            print(max_num)

resolve()

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

set<string> s;
string a;

int main()
{
	int n;
	cin >> n;
	while (n--)
	{
		cin >> a;
		s.insert(a); 
	}
	cout << s.size() << endl;
	return 0;
}


Measured memory_bytes: 19184
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
int R,C;
vector<pair<int,int> > Row[111111];
vector<pair<int,int> > col[111111];
int ace[111111];
long long int dif[111111];
long long int mindif[111111];
int ancestor(int x){
	int y = ace[x];
	if(y == x)return x;
	int z = ancestor(y);
	dif[x] += dif[y];
	return ace[x] = z;
}
bool chk(vector<pair<int,int> > row[111111], int n,int todo){
	for(int i=1; i<=todo; i++){
		ace[i] = i;
		dif[i] = 0;
	}
	for(int i=1; i<=n; i++){
		sort(row[i].begin(),row[i].end());
		int l = row[i].size();
		for(int j=0; j<l-1; j++){
			int x = row[i][j].first;long long int xval = row[i][j].second;
			int y = row[i][j+1].first; long long int yval = row[i][j+1].second;
			int X = ancestor(x);
			int Y = ancestor(y);
			if(X != Y){
				ace[X] = Y;
				dif[X] = (xval - dif[x])-(yval - dif[y]);
			}else{
				if(yval - dif[y] != xval - dif[x])
					return false;
			}
		}
	}
	for(int i=1; i<=todo; i++)
		mindif[i] = dif[i];
	for(int i=1; i<=todo; i++){
		ancestor(i);
		mindif[ace[i]] = min(mindif[ace[i]], dif[i]);
	}
	for(int i=1; i<=n; i++){
		int l = row[i].size();
		for(int j=0; j<l; j++){
			int x = row[i][j].first; long long int xval = row[i][j].second;
			if(xval - dif[x] + mindif[ace[x]] < 0)
				return false;
		}
	}
	return true;
}
int main(){
	int N;
	scanf("%d%d%d",&R,&C,&N);
	while(N--){
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		Row[x].push_back(make_pair(y,z));
		col[y].push_back(make_pair(x,z));
	}
	puts(chk(Row,R,C) && chk(col, C,R) ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 13696
import math
a,b,C=map(float,input().split())

S = a*b*math.sin(C*math.pi/180)/2
c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(C*math.pi/180))
h = 2*S/a
print("{:10f}".format(S))
print("{:10f}".format(a+b+c))
print("{:10f}".format(h))



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

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

  if ((a + b) % 2 == 0){
    cout << (a + b) / 2 << endl;
  }else {
    cout << "IMPOSSIBLE" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
def is_par(s):
    l, r = 0, len(s) -1
    while l <= r:
        if s[l] != s[r]:
            return False
        l += 1
        r -= 1
    return True

S = input()
N = len(S)

if is_par(S) and is_par(S[0:(N-1)//2]) and is_par(S[(N+3)//2 - 1:]):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 38384
#include<cmath>
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cstdio>
#include<map>
#include<utility>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define fori(i,k,n) for(int i=k;i<(int)n;i++)
using namespace std;
const int dx[4] = { 0, 1, 0, -1 }, dy[4] = { 1, 0, -1, 0 };
const int dX[8] = { 0, 1, 1, 1, 0, -1, -1, -1 }, dY[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
/*
(char)'1' - (int)48 = (int)1;


*/


int main()
{
	int n;
	cin >> n;
	while (n != 0)
	{
		int a[600][600] = {};
		int w, h;
		cin >> w >> h;
		for (int i = 0; i < n; i++)
		{
			int x;
			int y;
			cin >> x >> y;
			a[y][x]++;
		}
		for (int k = 1; k <= h;k++)
			for (int i = 1; i <= w; i++)
			{
			a[k][i] += a[k][i - 1];
			}

		int x, y;
		int ans = 0;
		cin >> x >> y;
		for (int k = 1; k <= h-y+1; k++)
		{
			for (int i = 1; i <= w-x+1; i++)
			{
				int now = 0;
				for (int l = 0; l < y; l++)
				{
					now += a[k + l][i + x - 1] - a[k + l][i - 1];
				}
				ans = max(now, ans);


			}
		}
		cout << ans << endl;
		cin >> n;
	}


}

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

int main() {
	int A,B,C,D,E,F;cin>>A>>B>>C>>D>>E>>F;
	int swater,sugar;
	float p=0;
	for(int a=0;100*a<=F;a+=A){
		for(int b=0;100*a+100*b<=F;b+=B){
			for(int c=0;100*a+100*b+c<=F;c+=C){
				for(int d=0;100*a+100*b+c+d<=F;d+=D){
					if((c+d+a+b)!=0){
					if((a+b)*E>=(c+d)){
						float x=100*a+100*b;
						float y=c+d;
						if(p<=y/(x+y)){
							p=y/(x+y);
							swater=100*a+100*b+c+d;
							sugar=c+d;
						}
					}
					}

				}
			}
		}
	}
	if(sugar){
	cout<<swater<<' '<<sugar<<endl;
	}else{
		cout<<100*A<<" 0"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cmath>
#include <map>
#include <ctype.h>
using namespace std;

typedef long long ll;

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a + b >= c) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
const int N=4e5+10;
const int mod=1e9+7;
const int inv2=5e8+4;
typedef pair<int,int> pii;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int n,a[N],cnt[N];
vector<int> V[N];
int qpow(int a,int b) {
    int ret=1;
    while(b) {
        if(b&1) ret=1ll*ret*a%mod; a=1ll*a*a%mod; b>>=1;
    }
    return ret;
}
pii operator+(pii a,pii b) {
    return mp((a.fi+b.fi)%mod,a.se+b.se);
}
int tag[N<<2];
pii tr[N<<2];
#define ls (o<<1)
#define rs (o<<1|1)
void build(int o,int l,int r) {
    tag[o]=1; if(l==r) return;
    int mid=(l+r)>>1;
    build(ls,l,mid);build(rs,mid+1,r);
}
void modify(int o,int v) {
    tr[o].fi=1ll*tr[o].fi*v%mod;tag[o]=1ll*tag[o]*v%mod;
}
void down(int o) {
    if(tag[o]==1) return;
    modify(ls,tag[o]);modify(rs,tag[o]);tag[o]=1;
}
void update(int o,int l,int r,int p,int v) {
    if(l==r) { tr[o]=mp(v,1);return; }
    down(o);
    int mid=(l+r)>>1;
    if(p<=mid) update(ls,l,mid,p,v);
    else update(rs,mid+1,r,p,v);
    tr[o]=tr[ls]+tr[rs];
}
pii query(int o,int l,int r,int L,int R) {
    if(L<=l&&r<=R) return tr[o];
    down(o);
    int mid=(l+r)>>1;pii ret=mp(0,0);
    if(L<=mid) ret=ret+query(ls,l,mid,L,R);
    if(R>mid) ret=ret+query(rs,mid+1,r,L,R);
    return ret;
}
int main() {
    cin>>n;
    for(int i=1;i<=n;i++) a[i]=gi(),cnt[a[i]]++,V[a[i]].pb(i);
    for(int i=n-1;i;i--) cnt[i]+=cnt[i+1];
    int mul=1;
    for(int i=1;i<=n;i++) {
        if(cnt[i]<=n-i) return puts("0"),0;
        mul=1ll*mul*(cnt[i]-(n-i))%mod;
    }
    build(1,1,n);
    int ans=0;
    for(int j=n;j;j--) {
        for(int i:V[j]) {
            pii ret=query(1,1,n,i,n);
            ans=(ans+1ll*ret.fi*inv2%mod);
            ret=query(1,1,n,1,i);
            ans=((ans+1ll*ret.se*mul%mod)%mod-1ll*ret.fi*inv2%mod+mod)%mod;
        }
        int sz=V[j].size();
        ans=(ans+1ll*sz*(sz-1)%mod*inv2%mod*mul%mod*inv2%mod)%mod;
        for(int i:V[j]) update(1,1,n,i,mul);
        int tmp=1ll*(cnt[j]-1-(n-j))*qpow(cnt[j]-(n-j),mod-2)%mod;
        modify(1,tmp);
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 29056
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long ;
int main(){
    int n,x,t;
    cin >> n >> x >> t;
    if(n%x == 0) cout << n/x*t << endl;
    else{
        cout << (n/x+1)*t << endl;
    }
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using Tup = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<(v)<<"\n";
#define fl cout<<flush;
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl "\n"
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld pi=3.141592653589793238;

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll K;
    cin >> K;
    vector<ll> h(N,0);
    for(ll i=0;i<N;++i)cin>>h[i];
    vector<ll> dp(N,INF);
    dp[0]=0;
    for(ll i=0;i<N;++i){
        for(ll j=1;j<=K;++j)
        if(i>=j)chmin(dp[i],dp[i-j]+llabs(h[i]-h[i-j]));
    }
    prt(dp[N-1])

    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<=(b);++i)
#define DEC(i,a,b) for(int i=(a);i>=(b);--i)
#define DEBUG(x) cerr<<#x" == "<<x<<endl
using namespace std;
typedef long long ll;
inline int read(){
	int w=0,p=0;char c;
	while(!isdigit(c=getchar()))if(c=='-')p=1;
	while(isdigit(c))w=(w<<1)+(w<<3)+(c^'0'),c=getchar();
	return p?-w:w;
}
int n,a[200007],p[200007],t[200007];
inline bool cmp(int i,int j){return a[i]<a[j];}
int main(){
	n=read();
	REP(i,1,n)a[i]=read(),p[i]=i;
	sort(p+1,p+1+n,cmp);
	REP(i,1,n)t[p[i]]=i;
	REP(i,1,n)printf("%d\n",a[p[t[i]<=n/2?n/2+1:n/2]]);
	return 0;
}


Measured memory_bytes: 4480
#include <bits/stdc++.h>
#include <algorithm>  
#include <unordered_set>
#define ll long long

using namespace std;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll n;
	cin >> n;
	vector<ll> d(n);

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

		if (d[i] == 0) {
			z++;
		}

	}

	if (z > 0) {
		cout <<  0 << endl;
		return 0;
	}
	else {

		ll prod = 1;

		for (int i = 0; i < n; i++) {

			if (d[i] <= (1000000000000000000 / prod)) {
				prod *= d[i];
			}
			else {
				cout << -1 << endl;
				return 0;
			}

		}

		cout << prod << endl;
	}


	return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());

    ll ans = A[0];
    int idx = 1;
    rep(i, N-2) {
        ans += A[idx];
        if ((i + 1) % 2 == 0) idx++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4824
#include <bits/stdc++.h>
#include <string>
using namespace std;
static const int MAX = 100;

int main(){
    int n, A[MAX], ans = 0;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> A[i];

    for (int i = 0; i < n; i++){
        int minj = i;
        for (int j = i; j < n; j++){
            if( A[j] < A[minj]){
                minj = j;
            }

        }
        swap(A[i],A[minj]);
        if (i != minj){
        ans++;
        }
    }

    for (int k = 0; k < n; k++){
        cout << A[k];
        if(k < n-1){
            cout << " ";
        }else{
        cout << endl;
        }
    }
    cout << ans << endl;

}


Measured memory_bytes: 3096
/**
 *    author: apurba_debnath
**/
#include <bits/stdc++.h>


#define ll long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;


using namespace std;

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

    int n, r;
    cin >> n >> r;
    if (n < 10)
        cout << r + 100*(10-n);
    else
        cout << r;

    return 0;
}


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

int H, W, C, M, s, t, res, cap[310][310];
bool used[310];
enum { source = 300, sink, nwin, nwout, ncin, ncout, nmio };

bool dfs(int v)
{
    used[v] = true;
    for(int i = 0; i < 310; ++i)
        if(cap[v][i] > 0 && (i == sink || (!used[i] && dfs(i)))) {
            --cap[v][i]; ++cap[i][v]; return true;
        }
    return false;
}

int main()
{
    while(cin >> H >> W >> C >> M && H >= 0)
    {
        memset(cap, 0, sizeof(cap));
        cin >> cap[nwin][nwout] >> cap[ncin][ncout] >> cap[nmio][sink];

        for(int i = 0; i < H; ++i)
            cap[source][i] = cap[i][nwin] = 1;
        for(int i = 0; i < W; ++i) {
        	cin >> s;
            for(int j = 0; j < s; ++j) { cin >> t; cap[t-1][50+i] = 1; }
            cap[50+i][100+i] = cap[100+i][ncin] = 1;
        }
        for(int i = 0; i < C; ++i) {
        	cin >> s;
            for(int j = 0; j < s; ++j) { cin >> t; cap[100+t-1][150+i] = 1; }
            cap[nwout][150+i] = cap[150+i][200+i] = cap[200+i][nmio] = 1;
        }
        for(int i = 0; i < M; ++i) {
        	cin >> s;
            for(int j = 0; j < s; ++j) { cin >> t; cap[200+t-1][250+i] = 1; }
            cap[ncout][250+i] = cap[250+i][sink] = 1;
        }

        res = 0;
        do fill_n(used, 310, false); while(dfs(source) && ++res);
        cout << res << endl;
    }
}

Measured memory_bytes: 1248
import sys

A,B,C,K = map(int, input().split())

left=K
sum=0
if K<=A:
    print(K)
    sys.exit()
else:
    sum+=A
    left-=A
    if left<=B:
        print(sum)
        sys.exit()
    else:
        left-=B
        sum-=left
        print(sum)
        sys.exit()


Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200200;

long long f(long long x){
  if(x%4 == 0) return x;
  if(x%4 == 1) return 1;
  if(x%4 == 2) return x + 1;
  return 0;
}

int main(){
  long long a, b;
  cin >> a >> b;
  cout << (f(b) ^ (a == 0 ? 0 : f(a - 1))) << endl;
  return 0;
}


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

const int maxn = 100050;
int a[100050];
int dp[maxn];

int main()
{
	int n;
	cin>>n;
	for(int i = 1;i<=n;++i)
	    cin>>a[i];
	
	dp[1] = 0,dp[2] = abs(a[1]-a[2]);
	for(int i = 3;i<=n;++i)
	    dp[i] = min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
	
	cout<<dp[n]<<endl;
	return 0;
} 

Measured memory_bytes: 4408
L, R = map(int, input().split()) # 横に2個

l = L // 2019
r = R // 2019
ll = L % 2019
rr = R % 2019

if l < r:
    ans = 0
else:
    ans = 2019
    for i in range(ll, rr+1):
        for j in range(i+1, rr+1):
            k = i * j % 2019
            ans = min(ans, k)

print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int H;
		int W;
		for (int i = 0; i < 10000; i ++) {
			H = scan.nextInt();
			W = scan.nextInt();
			if (H == 0 && W == 0) {
				break;
			}
			for (int h = 0; h < H; h++) {
				for (int w = 0; w < W; w++) {
					if ((h + w) % 2 == 0) {
						System.out.print("#");
					} else {
						System.out.print(".");
					}
				}
				System.out.println();
			}
			System.out.println();
		}
	}

}

Measured memory_bytes: 37188
#include <iostream>
using namespace std;;
int main()
{   
    int a,b,c,k;
    cin>>a>>b>>c;
    if(b>c){
        k=b;
        b=c;
        c=k;
    }
    if(a>b){
        k=a;
        a=b;
        b=k;
    }
     if(b>c){
        k=b;
        b=c;
        c=k;
    }
    if(a>b){
        k=a;
        a=b;
        b=k;
    }
    cout<<a<<' '<<b<<' '<<c<<endl;
    return 0;
}


Measured memory_bytes: 3080
#include<iostream>

using namespace std;
 
int main(){
	
	long int A,B,ans = 0;
	cin >> A >> B;
	
	for( ; A%4; A++ ) ans ^= A;
	for( ; (B+1)%4; B-- ) ans ^= B;
	cout << ans << endl;
	
	return 0;
	
}

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

const int maxn = 1e6 + 10;
const int P = 998244353;


int cnt[maxn], bei[maxn], ans[maxn];

int fpw(int a, int b, int c = 1) {
    while (b) {
        if (b & 1) c = 1ll * a * c % P;
        a = 1ll * a * a % P, b >>= 1;
    } return c;
}

int main() {
    int n; cin >> n;
    for (int i = 1; i <= n; i++) {
        int x; cin >> x;
        cnt[x]++;
    }
    for (int i = 1; i < maxn; i++)
        for (int j = i; j < maxn; j += i)
            (bei[i] += 1ll * cnt[j] * j % P) %= P;
    //for (int i = 1; i < 10; i++)
    //    cout << "bei[" << i << "] = " << bei[i] << endl;
    for (int d = maxn - 1; d >= 1; d--) {
        ans[d] = 1ll * bei[d] * bei[d] % P;
        for (int dd = d + d; dd < maxn; dd += d) 
            ans[d] = (P + ans[d] - ans[dd]) % P;
    }
    //for (int i = 1; i < 10; i++)
    //    cout << "ans[" << i << "] = " << ans[i] << endl;
    int rst = 0;
    for (int i = 1; i < maxn; i++) {
        rst = (rst + fpw(i, P - 2) * 1ll * ans[i]) % P;
       // if (i < 10)
       //     cout << rst << ' ' << fpw(i, P - 2) << ' ' << ans[i] << endl;
    }
    for (int i = 1; i < maxn; i++)
        rst = (rst + P - 1ll * cnt[i] * i % P) % P;
    cout << 1ll * rst * fpw(2, P - 2) % P << endl;

}

Measured memory_bytes: 11904