akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

////////////
// ModInt //
////////////

// 四則演算の最も左に存在する値がModIntでなければキャストでバグる
// 例えばx = mint * 1000;やx = ModInt(1000) * mint;はいいがx = 1000 * mint;は駄目。
template<int64_t mod_ = 1'000'000'007>
class ModInt {
private:
	int64_t integer_;

public:
	constexpr ModInt(const int64_t initial_number = 0)
		: integer_(initial_number){}
	
	// 四則演算
	constexpr ModInt operator+(const ModInt& operand) const
	{
		ModInt ret{this->integer_ + operand.integer_};
		if (ret.integer_ >= mod_)
			ret.integer_ -= mod_;
		return ret;
	}
	constexpr ModInt operator-(const ModInt& operand) const
	{
		ModInt ret{this->integer_ - operand.integer_};
		if (ret.integer_ < 0)
			ret.integer_ += mod_;
		return ret;
	}
	constexpr ModInt operator*(const ModInt& operand) const
	{
		return {this->integer_ * operand.integer_ % mod_};
	}
	constexpr ModInt operator/(const ModInt& operand) const
	{
		return *this * (operand ^ (mod_ - 2));
	}

	// 累乗
	constexpr ModInt operator^(const int64_t operand) const
	{
		ModInt ret{1}, pow_ope{this->integer_};
		for (int64_t pow{operand}; pow > 0; pow >>= 1)
		{
			if (pow & 1) ret *= pow_ope;
			pow_ope *= pow_ope;
		}
		return ret;
	}

	// 代入
	constexpr ModInt& operator=(const ModInt& operand)
	{
		this->integer_ = operand.integer_;
		return *this;
	}
	constexpr ModInt& operator+=(const ModInt& operand)
	{
		*this = *this + operand;
		return *this;
	}
	constexpr ModInt& operator-=(const ModInt& operand)
	{
		*this = *this - operand;
		return *this;
	}
	constexpr ModInt& operator*=(const ModInt& operand)
	{
		*this = *this * operand;
		return *this;
	}
	constexpr ModInt& operator/=(const ModInt& operand)
	{
		*this = *this / operand;
		return *this;
	}

	// その他
	constexpr operator int64_t() { return integer_; }

	constexpr ModInt getOne() const
	{
		return ModInt(1ll);
	}
	constexpr ModInt getZero() const
	{
		return ModInt(0ll);
	}
};
using Mint = ModInt<>;

int main()
{
	int n;
	scanf("%d", &n);
	std::vector<char> change;
	for (int i{}; i < n; i++)
	{
		char tmp;
		scanf(" %c", &tmp);
		if (tmp != '-') change.push_back(tmp);
	}
	n = (int)change.size();
	using vi = std::vector<Mint>;
	using vvi = std::vector<vi>;
	vvi dp(n + 1, vi(n + 1));
	dp[0][0] = Mint(1ll);
	for (int i{}; i < n; i++)
	{
		if (change[i] == 'D')
		{
			// 使う使う
			for (int unused{1}; unused <= n; unused++)
				dp[i + 1][unused - 1] += Mint(unused) * Mint(unused) * dp[i][unused];
			// 使う保留
			for (int unused{1}; unused <= n; unused++)
				dp[i + 1][unused] += Mint(unused) * dp[i][unused];
		}
		else
		{
			// 保留使う
			for (int unused{1}; unused <= n; unused++)
				dp[i + 1][unused] += Mint(unused) * dp[i][unused];
			// 保留保留
			for (int unused{}; unused < n; unused++)
				dp[i + 1][unused + 1] += dp[i][unused];
		}
	}
	std::cout << dp[n][0] << std::endl;

	return 0;
}


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

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

typedef pair<double,int> pdi;

const double EPS=1e-10;

bool operator<(const pdi& a,const pdi& b)
{
	return abs(a.first-b.first)<EPS?a.second<b.second:a.first<b.first;
}

int main()
{
	for(int n;cin>>n,n;){
		vector<pdi> people;
		rep(i,n){
			int id,h,w; cin>>id>>h>>w;
			people.push_back(mp(abs(22-w/(h*h*1e-4)),id));
		}
		cout<<min_element(allof(people))->second<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
using System;
using System.IO;
using System.Linq;
using System.Runtime;
using System.Reflection;
using System.Diagnostics;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;


class P
{
    static void Main()
    {
        Console.WriteLine(Console.ReadLine().Split().Select(int.Parse).Aggregate((x, y) => x + y / 2));
    }
}

Measured memory_bytes: 11348
#include <iostream>
#include <tuple>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

vi comp(vi a, vi b) {
    vi c(a.size());
    forn(i, a.size()) c[i] = a[b[i]];
    return c;
}

vi deg(vi a, i64 d) {
    int n = a.size();
    vi x(n);
    forn(i, n) x[i] = i;
    while (d) {
        if (d & 1) x = comp(x, a);
        a = comp(a, a);
        d /= 2;
    }
    return x;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    int n;
    cin >> n;
    vi64 x(n);
    forn(i, n) cin >> x[i];
    vi64 d(n - 1);
    forn(i, n - 1) d[i] = x[i + 1] - x[i];
    vi p(n - 1);
    forn(i, n - 1) p[i] = i;
    i64 m, k;
    cin >> m >> k;
    forn(i, m) {
        int j;
        cin >> j;
        --j;
        swap(p[j - 1], p[j]);
    }
    p = deg(p, k);
    i64 x0 = x[0];
    forn(i, n - 1) {
        cout << x0 << '\n';
        x0 += d[p[i]];
    }
    cout << x0 << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 4232
import heapq

n, m = map(int, input().split())
a = []
for i in list(map(int, input().split())):
    heapq.heappush(a, -i)

for _ in range(m):
    p = heapq.heappop(a)
    heapq.heappush(a, int(p/2))

print(-sum(a))


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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int INF = 10101010;

int main(){
    int n;
    cin >>n;
    vector<int> l(n);
    rep(i,n) cin >>l[i];

    vector<int> pre(n+1);
    rep(i,n) pre[i+1] = l[i];
    rep(i,n) pre[i+1] += pre[i];

    vector<int> v;
    rep(i,n)for(int j=i; j<n; ++j) v.pb(pre[j+1]-pre[i]);
    sort(all(v));
    v.erase(unique(all(v)), v.end());

    int ans = INF;
    for(int lb:v){
        vector<int> dp(n+1,INF);
        dp[0]=0;
        rep(i,n){
            for(int j=i; j<n; ++j){
                if(i==0 && j==n-1) continue;

                int t = pre[j+1]-pre[i];
                if(t<lb) continue;
                dp[j+1] = min(dp[j+1], max(dp[i],t));
            }
        }

        ans = min(ans, dp[n]-lb);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3164
// CODING BEAST
/*******************************************************************************************************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define sum(a)     ( accumulate ((a).begin(), (a).end(), 0ll))
#define mine(a)    (*min_element((a).begin(), (a).end()))
#define maxe(a)    (*max_element((a).begin(), (a).end()))
#define mini(a)    ( min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a)    ( max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b) / gcd(a, b)
#define Precision(a) cout << fixed << setprecision(a)

using ll = long long;
ll inf = 1e18;
using vb = vector<bool>; using vc = vector<char>; using vd = vector<double>; using vi = vector<int>; using vvi = vector<vi>;
using vll = vector<ll>; using vvll = vector<vll>; using pi = pair<int, int>; using pll = pair<ll, ll>;
#define endl "\n"
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i = 0; i < n; i++)
#define repc(i,a,n) for(ll i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define pow2(x) (1ll<<(x))
#define Blazing_fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define trav(a,v) for(auto &a:v)
int a[8] = { -1, -1, -1, 0, 0, 1, 1, 1};
int b[8] = { -1, 0, 1, -1, 1, -1, 0, 1};
inline ll power(ll x, ll y)
{
    ll temp;
    if ( y == 0)
        return 1;
    temp = power(x, y / 2) ;
    if (y % 2 == 0)
        return (temp * temp) ;
    else
        return (x * temp * temp) ;
}
bool sortbysec(pll & a, pll & b) {
    return (a.second < b.second);
}
/*
ll fact(ll n)
{
    ll res = 1;
    for (ll i = 2; i <= n; i++)
        res = (res * i) ;
    return res;
}

ll ncr(ll n, ll r)
{
    return fact(n) / (fact(r) * fact(n - r));
}
bool isprime(ll n) {
    if (n <= 1) return false;
    if (n <= 3) return true;
    if ((n % 2 == 0) || (n % 3 == 0)) return false;
    for (ll i = 5; i * i <= n; i = i + 6)
        if ((n % i == 0) || (n % (i + 2) == 0)) return false;

    return true;
}*/
/*********************************************************************************************************************************************************/

signed main() {
    ll n, x, t;
    cin >> n >> x >> t;
    ll p;
    if (n % x == 0) {
        p = n / x;
    }
    else {
        p = (n / x) + 1;
    }
    // cout << p << endl;
    cout << p*t << endl;
}




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

using namespace std;
using ll = long long;

int main() {
    int M = 0;
    int N;
    cin >> N;
    cin >> M;
    vector<int> A(M,0);
    if(M == 1 || N >= M) {
        cout << 0 << endl;
        return 0;
    }
    for(int i = 0; i < M; i++) {
        cin >> A.at(i);
    }
    sort(A.begin(),A.end());
    ll ans = A.at(M - 1) - A.at(0);
    //cout << ans << endl;
    for(int i = 0; i < M - 1; i++) {
        A.at(i) = A.at(i + 1) - A.at(i);
    }
    A.at(M - 1) = 0;
    sort(A.begin(),A.end());
    reverse(A.begin(),A.end());

    for(int i = 0; i < N - 1; i++) {
        //cout << A.at(i) << endl;
        ans -= A.at(i);
    }
    
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 3700
n = int(input())
p = list(map(int, input().split()))

cnt = 0
for i in range(n):
    if p[i] == i + 1:
        if i == 0:
            p[i], p[i + 1] = p[i + 1], p[i]
        elif i == n-1:
            p[i], p[i - 1] = p[i - 1], p[i]
        else:
            if p[i - 1] == i + 1:
                p[i], p[i - 1] = p[i - 1], p[i]
            else:
                p[i], p[i + 1] = p[i + 1], p[i]
        cnt += 1

print(cnt)

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

int H[100000];

int main(void) {
  int N;
  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> H[i]; 
  }
  if(N == 1) {
    cout << "Yes" << endl;
    return 0;
  }
  for(int i = N - 1; i > 0; i--) {
    if(H[i] < H[i-1]) {
      H[i-1]--;
      if(H[i] < H[i-1]) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0; 
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n, m, k ;
int a[3001][3001];
int f[3001][3001][4];
int dp ( int i, int j, int cnt)
{
    if ( i == n && j == m)
    {
        if ( cnt  < 3)
            return a[i][j];
        else
            return 0;
    }
    int &res =f[i][j][cnt];
    if (res != -1 )
        return res;
    res = 0;

    if(cnt<3)
    {
        if(j < m)res=max(res,max(dp(i,j+1,cnt),a[i][j]+dp(i,j+1,cnt+1)));

        if(i < n)res=max(res,a[i][j]+dp(i+1,j,0));

    }
    else
    {
        if(j < m)res = max(res,dp(i,j+1,cnt));
        if(i < n)res = max(res,dp(i+1,j,0));
    }
    return res;

}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m >> k;
    memset(f, -1, sizeof f);
    for(int i = 1; i<= k ; i++)
    {
        int u, v, w;
        cin >> u >> v >> w;
        a[u][v] = w;
    }
    cout<<dp(1,1,0);

    return 0;
}


Measured memory_bytes: 355752
L, R = (int(lr) for lr in input().split())
min_mod = 2019
has_found = False
for l in range(L, R):
    for r in range(l+1, R+1):
        mod = (l*r) % 2019
        if mod == 0:
            min_mod = 0
            has_found = True
            break
        else:
            min_mod = min(min_mod, mod)
    if has_found:
        break

print(min_mod)


Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(
				new InputStreamReader(System.in))) {

			int n = Integer.parseInt( br.readLine());
				System.out.println(n*(1+n)/2);

		}
	}
}


Measured memory_bytes: 21204
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <stack>
#include <bitset>
#include <utility>
// #include <numeric>
using namespace std;



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector<vector<ll>> vvint;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define INT_MAX 2147483647
#define LLONG_MAX 9223372036854775807
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())


typedef struct{
  ll pos;
  ll depth;
} data;
//
// struct Node{
//
// }



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

// ll X,Y,Z,K;
// ll pmax = 30000000000;
// vint A,B,C;




// int binary_search(int key){
//  //isOKを満たす要素のうち最小のインデックスを返す。（要ソート）
//   int left = -1;
//   int right = N;
//
//   while(right - left > 1){
//     int mid = left + (right - left)/2;
//
//     if(isOK(mid, key)) right=mid;
//     else left=mid;
//   }
//
//   return right;
// }

// ll gcd(ll m, ll n){
//   if(m<n) swap(m,n);
//   if(n==0) return m;
//   return gcd(n, m%n);
// }





int main() {

  ll N,W;
  cin>>N>>W;
  vint w(N),v(N);
  rep(i,N)cin>>w[i]>>v[i];

  vvint dp(N+1, vint(W+1,0));

  rep(i,N){
    rep(j,W+1){
      if(j-w[i]>=0){
        dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]]+v[i]);
      }else{
        dp[i+1][j] = dp[i][j];
      }
    }
  }

  cout << dp[N][W] << endl;

}

















//


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

using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N), B(N);

    ll C = 0, X = 0, Y = 0;
    for (int i = 0; i < N; ++i) cin >> A[i];
    for (int i = 0; i < N; ++i) cin >> B[i];
    for (int i = 0; i < N; ++i) C += B[i] - A[i];
    for (int i = 0; i < N; ++i) {
        if (A[i] > B[i]) X += A[i] - B[i];
        else Y += (B[i] - A[i] + 1) / 2;
    }
    puts(max(X, Y) <= C ? "Yes" : "No");
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>

using namespace std;

int main() {
	int n, m;
	cin >> n;
	vector <string> red(n),small;
	vector <int> point;
	for (int i = 0; i < n; i++) {
		cin >> red.at(i);
		if (i == 0) { 
			small.push_back(red.at(0)); 
			point.push_back(1);
		}
		else {
			int a = small.size();
			for (int j = 0; j < a; j++) {
				if (red.at(i) == small.at(j)) {
					point.at(j)++;
					break;
				}
				else if (j == small.size() - 1){
					small.push_back(red.at(i));
					point.push_back(1);
				}
			}
		}
	}
	cin >> m;
	vector <string> blue(m);
	for (int i = 0; i < m; i++) {
		cin >> blue.at(i);
		for(int j = 0; j < small.size();j++)
			if (blue.at(i) == small.at(j)) {
				point.at(j)--;
			}
	}
	int max = 0;
	for (int i = 0; i < point.size();i++) {
		if (max < point.at(i)) max = point.at(i);
	}
	cout << max << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
vector<int>G[N];
int vis[N],color[N],n,u,v,mx=0,s;
struct node{
    int u,v;
};
vector<node>edge;
map<pair<int,int>,int>m;
void bfs(int s){
    queue<int>q;
    q.push(s);
    vis[s]=1;
    while(!q.empty()){
        int u=q.front();
        q.pop();
        int c=1;
        for(auto v:G[u]){
            if(!vis[v]){
                q.push(v);
                if(c==color[u]) (c==mx-1)?c=mx:(c=(c+1)%mx);
                color[v]=c;
                //cout<<v<<c<<endl;
                m[{min(u,v),max(u,v)}]=c;
                (c==mx-1)?c=mx:(c=(c+1)%mx);
                vis[v]=1;
            }
        }
    }
}
int main(){
    cin>>n;
    for(int i=0;i<n-1;i++){
        cin>>u>>v;
        edge.push_back({u,v});
        G[u].push_back(v);
        G[v].push_back(u);
    }
    for(int i=1;i<=n;i++){
        if(G[i].size()>mx){
            mx=G[i].size();
            s=i;
        }
    }
    //cout<<s<<mx<<endl;
    bfs(s);
    color[s]=0;
    cout<<G[s].size()<<endl;
    for(auto i:edge) cout<<m[{min(i.u,i.v),max(i.u,i.v)}]<<endl;
    return 0;
}


Measured memory_bytes: 16560
#include <bits/stdc++.h>
typedef long long ll;
#define vstroku() to_string()
#define vchislo() to_ulong()
#define gcd(x,y) __builtin_gcd(x,y)
#define numberof1(x) __builtin_popcount(x)
#define povsemelementam(i,mnozh) for(auto i: mnozh)
#define podotrezok(i,j) substr(i-1,j) // like prefix sum, (i,j)=s[j]-s[i-1]
#define pb push_back
#define pf push_front
#define popf pop_front
#define popb pop_back 
#define pii pair <int, int>
#define F first
#define S second
#define mipletsplay ios_base::sync_with_stdio(0); cin.tie(0); 


using namespace std;
const ll INFLL = 1e18;
const int MAXN = 3e5;
const ll INF = 1e9;
const ll kek=998244353;

int main() {
mipletsplay;
int n;
cin>>n;
vector <int> a(n);
vector <int> c(n-1);
for (int i=0;i<n;i++)
cin>>a[i];
ll sum=0;
for (int i=0;i<n;i++)
{
int x;
cin>>x;
sum+=x;
}
for (int i=0;i<n-1;i++)
{
  cin>>c[i];
}
for (int i=1;i<n;i++)
{
if ((a[i-1]+1)==a[i]){
sum+=c[a[i-1]-1];
}
}
cout<<sum;}

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;

//テストケースはあんまり見ないほうが良い。デバッグする能力が必要.
int main(){
    int h,n;
    cin >> h >> n;
    int a[n];
    rep(i,n)cin >> a[i];
    int sum =0;
    rep(i,n)sum+=a[i];
    if(sum>=h){
        cout << "Yes" << endl;
    }else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;cin>>S;
  if(S.size()==26){
    if(S=="zyxwvutsrqponmlkjihgfedcba")cout<<"-1"<<endl;
    else{
      int i=25;
      while(S.at(i)<S.at(i-1))i--;
      int j=25;
      while(S.at(i-1)>S.at(j))j--;
      S.at(i-1)=S.at(j);
      cout<<S.substr(0,i)<<endl;
    }
  }
  else{
    string T=S;
    sort(S.begin(),S.end());
    char a='a';
    while(binary_search(S.begin(),S.end(),a))a++;
    cout<<T+a<<endl;
  }
}

Measured memory_bytes: 256
/* 
 * Project: AtCoder Beginners Contest 155 B - Papers, Please
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/06/24
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
#include <algorithm>
#include <numeric>
using namespace std;

int n;
int a[1000];

void solve() {

    for (int i=0;i<n;i++) {
        if (!(a[i] & 1)) {
            if (a[i]%3 != 0 && a[i]%5 != 0) {
                printf("DENIED\n");
                return;
            }
        }
    }
    printf("APPROVED\n");

}

int main() {

    scanf("%d", &n);
    for (int i=0;i<n;i++) {
        scanf("%d", &a[i]);
    }

    solve();

}

Measured memory_bytes: 3120
S = str(input())
T = str(input())
lenS = len(S)
lenT = len(T)

n = lenS-lenT+1
ans = []

for i in range(n):
  c = 0
  for j in range(lenT):
    if S[j+i] != T[j]:
      c += 1
  ans.append(c)

print(min(ans))

Measured memory_bytes: 9048
#include <iostream>
#include <cstring>
#include <cstdio>
#define ll long long
using namespace std;

inline int read(){
	int sum=0,f=1;char c=getchar();
	while(c>'9'||c<'0'){if(c=='-') f=-1;c=getchar();}
	while(c<='9'&&c>='0'){sum=sum*10+c-'0';c=getchar();}
	return f*sum;
}

const int N=305;
int n,m,K;
int f[N][N][N];

signed main(){
	n=read();K=read();m=read();
	f[0][1][0]=1;
	for(int i=0;i<=n;i++){
		for(int j=1;j<=K;j++){
			for(int k=i;k>=0;k--){
				if(k) f[i][j][k-1]=(f[i][j][k-1]+f[i][j][k])%m;
				else f[i][j+1][i]=(f[i][j+1][i]+f[i][j][k])%m;
				f[i+1][j][k]=(f[i+1][j][k]+1ll*f[i][j][k]*(k+1)%m)%m;
			}
		}
	}
	printf("%d\n",f[n][K][0]);
	return 0;
}


Measured memory_bytes: 110848
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define mod 1000000007
using namespace std;

int main(int argc, char const *argv[])
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--){
        ll h,w;
        cin>>h>>w;
        char arr[h][w];
        ll dp[h][w];
        for(ll i=0;i<h;i++){
            for(ll j=0;j<w;j++){
                cin>>arr[i][j];
                dp[i][j]=0;
                if(i==0 && j==0){
                    dp[i][j]=1;
                    continue;
                }
                if(i>0 && j>0){
                    if(arr[i-1][j]!='#' && arr[i][j-1]!='#'){
                        dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
                    }
                    else if(arr[i-1][j]=='#' && arr[i][j-1]!='#'){
                        dp[i][j]=dp[i][j-1]%mod;
                    }
                    else if(arr[i-1][j]!='#' && arr[i][j-1]=='#'){
                        dp[i][j]=dp[i-1][j]%mod;
                    }
                }
                else if(i>0){
                    if(arr[i-1][j]!='#')
                    dp[i][j]=dp[i-1][j]%mod;
                }
                else if(j>0){
                    if(arr[i][j-1]!='#')
                    dp[i][j]=dp[i][j-1]%mod;
                }
                //cout<<dp[i][j]<<" ";
            }
            //cout<<endl;
        }

        cout<<dp[h-1][w-1]<<endl;
    }
    return 0;
}


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

#define ft first
#define sd second
#define pb push_back
#define all(x) x.begin(),x.end()

#define ll long long int
#define vi vector<int>
#define vii vector<pair<int,int> >
#define pii pair<int,int>
#define plii pair<pair<ll, int>, int>
#define piii pair<pii, int>
#define viii vector<pair<pii, int> >
#define vl vector<ll>
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define mp make_pair
#define ms(x, v) memset(x, v, sizeof x)
#define pr_vec(v) for(int i=0;i<v.size();i++) cout << v[i] << " " ;

#define f_in(st) freopen(st,"r",stdin)
#define f_out(st) freopen(st,"w",stdout)

#define fr(i, a, b) for(i=a; i<=b; i++)
#define fb(i, a, b) for(i=a; i>=b; i--)
#define ASST(x, l, r) assert( x <= r && x >= l )
const int  p=31,po=1,N=260, M=(ll)1e9+1 ;
const int mod = 998244353 ;
// struct node{
//   ll prefixsum,suffixsum,bettersum,totalsum;
//   void create(ll val){
//     prefixsum=suffixsum=bettersum=val;
//   }
//   void Merge(node& a,node &b){
//     prefixsum=max(a.prefixsum,a.totalsum+b.prefixsum);
//     suffixsum=max(b.suffixsum,a.suffixsum+b.sum);
//     totalsum=a.totalsum+b.totalsum;
    
//   }
// }
//ll dp[2][100];
vl compute(string s){
        vl has(s.length());
        ll i;

        for(i=0;i<s.length();i++){
            if(i==0){
                has[i]=((s[i]-'a'+1))%mod;
            }
            else
                has[i]=(has[i-1]*p + (s[i]-'a'+1))%mod;
        }
        return has;
}
ll g[N][N],keep[N*N];

ll solve(ll l,ll r){
  if(l==r)
    return l;
  ll n1=solve(l,(l+r)/2);
  ll n2=solve((l+r)/2 +1,r);
  if(g[n1][n2]>0){
    keep[g[n1][n2]]=true;
    return n1;
  }
  else{
    keep[g[n2][n1]]=true;
    return n2;
  }
  
}
ll x(ll n){
  ll rem=n%4;
  if(rem==0)
    return n;
  else if(rem==1)
    return 1;
  else if(rem==2)
    return n+1;
  else
    return 0;
}
int main(){
 ios_base::sync_with_stdio(0);
  ll n,a,b;
  cin >> n;
  cin >> a >> b;
  vl an(n),c(3,0);
  ll i;
  for(i=0;i<n;i++){
    cin >> an[i];
    if(an[i]<=a){
      c[0]++;
    }
    else if(an[i]>a && an[i]<=b )
      c[1]++;
    else 
      c[2]++;
  } 
  cout << min(c[0],min(c[1],c[2]));
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int main(){
  int N, res;
  rd(N);
  res = 180 * (N-2);
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190601-1

// --- original code ---
// {
//   int N, res;
//   rd(N);
//   res = 180 * (N-2);
//   wt(res);
// }


Measured memory_bytes: 256
sub g{($d[$x=@@[@_]]-$d[$y=$@[$_[0]+1]])/($H[$y]-$H[$x])-$H[$x]-$H[$y]}<>=~$";map{shift@@while@@>1&&-2*$_<g 0;$d[@d]=$X=$d[$@[0]]+$'+($H[$@[0]]-$_)**2;$#@-=2while$@[@@]=$i,@@>2&&g(-2)>g-3;$i++}@H=glob<>;print$X-$'

Measured memory_bytes: 69668
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repp(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;

const int INF = 1e15;

int n, m, r;
vector<int> d;

struct edge{
    int to, cost;
    edge(int to, int cost): to(to), cost(cost){}
};

vector<vector<edge> > G;

void dijkstra(int s){
    priority_queue<P, vector<P>, greater<P> > q;
    d.clear();
    d.resize(n, INF);
    d[s] = 0;
    q.push(P(d[s], s));

    while(q.size()){
        P p = q.top(); q.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        rep(i, 0, G[v].size()){
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                q.push(P(d[e.to], e.to));
            }
        }
    }
    return;
}

signed main(){
    cin >> n >> m >> r;
    G.clear();
    G.resize(n, vector<edge>());
    rep(i, 0, m){
        int s, t, c;
        cin >> s >> t >> c;
        G[s]. push_back(edge(t, c));
        // G[t]. push_back(edge(s, c));
    }
    
    dijkstra(r);
    rep(i, 0, n){
        if(d[i] == INF) cout << "INF" << endl;
        else cout << d[i] << endl;
    }
}

Measured memory_bytes: 17636
fun main(args: Array<String>) {
    val MOD = 1000000007L
    val (N, K) = listOfInt()
    var s = mutableListOf<Pair<Int, Int>>()
    for (i in 1..Math.sqrt(N.toDouble()).toInt()) {
        s.add(Pair(i, 0))
        s.add(Pair(N / i, 0))
    }
    s.sortBy { it.first }
    s = s.distinctBy { it.first }.toMutableList()
    for (i in 0 until s.count() - 1) {
        val l = N / s[i + 1].first
        val r = N / s[i].first
        s[i] = Pair(s[i].first, r - l)
    }
    s[s.count() - 1] = Pair(s[s.count() - 1].first, 1)
    val m = s.count()
    val map = mutableMapOf<Int, Int>()
    repeat(m) { map[s[it].first] = it }
    var dp = Array<LongArray>(K + 1) { LongArray(m, { 0 }) }
    dp[0][map[N]!!] = 1
    for (i in 0 until K) {
        for (j in m - 2 downTo 0) {
            dp[i][j] += dp[i][j + 1]
            dp[i][j] %= MOD
        }
        repeat(m) {
            val nj = map[N / s[it].first]!!
            dp[i + 1][it] += dp[i][nj] * s[it].second
            dp[i + 1][it] %= MOD
        }
    }
    var ans = 0L
    repeat(m) { ans += dp[K][it]; ans %= MOD }
    println(ans)
}

fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }


Measured memory_bytes: 140916
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)
#define rrep(i,a,b) for(int (i)=int(a);(i)>=int(b);(i)--)

#define put(a) cout << (a) << endl

#define INF 1000000001
#define MOD 1000000007
#define INF64 1000000000000000001

#define F first
#define S second

#define Pii  pair<int,int>
#define Pll  pair<long long,long long>
#define Piii pair<int,pair<int,int>>
#define Plll pair<long long,pair<long long,long long>>

#define Vll(a,b,c)    vector<vector<long long>> (a)((b),vector<long long>((c))
#define Vlll(a,b,c,d) vector<vector<vector<long long>>> (a)((b),vector<vector<long long>>((c),vector<long long>((d)))

#define MAX_N 1000000
int N;
int M;
// vector<int> K;
//int KK[MAX_N*MAX_N];
int K[MAX_N];
int L;
int ans;
bool bool_ans;

int iti,ni,san;

char S[4];

int main (void)
{
  cin >> N;

  rep(i,0,N) {
    cin >> K[i];
  }

  rep(i,0,N-2) {
    iti = max(K[i],max(K[i+1],K[i+2]));
    san = min(K[i],min(K[i+1],K[i+2]));
    if ((iti > K[i+1]) && (san < K[i+1])) {
      ans++;
    }
  }

  put(ans);

  return 0;
}


Measured memory_bytes: 256
# 「操作を最大 K 回まで行うことができる」という問題設定は、アルゴリズム的にできることがとても限られてくる
# ・1回操作するごとに、何らかの値が規則的に変化していく
# ・なんらかの意味で Greedy に、順にやっていくとよい
# とにかく、操作の意味をわかりやすく言い換える
# 文字列S(長さN)のスコアは、「文字と文字との間の隙間(N-1個)」のうちLとRが隣接しているもの(a個とする)を除いた、N−1−a
# 一回の反転操作で、LとRの変わり目を2箇所減らすことができる
# よって、求める最大値は N−1−max(a−2K,0)
N, K = map(int, input().split())
S = input()

cnt = 0
for i in range(N - 1):
    if S[i] != S[i + 1]:
        cnt += 1

ans = N - 1 - max(cnt - 2 * K, 0)
print(ans)


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

#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());

signed main()
{   
    gearup;
    int n,m,q; cin >> n >> m >> q;
    vvl a(n+10,vl(n+10));
    rep(i,m){
        int l,r; cin >> l >> r;
        a[l][r]++;
    }
    rep(i,n+1)rep1(j,n+1)a[i][j] += a[i][j-1];
    rep(i,q){
        int p,q; cin >> p >> q;
        ll res = 0;
        for(int j=p;j<=q;j++)res += a[j][q];
        out(res);
    }
}

Measured memory_bytes: 5256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++) cin >> a.at(i);
  for(int i=0;i<n;i++){
    if(a.at(i)%2==0){
      if(a.at(i)%3==0||a.at(i)%5==0){
        continue;
      }else{
       cout << "DENIED" << endl;
       return 0; 
      }
    }
  }
  cout << "APPROVED" << endl;
}

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

int main(){
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 0; i < n; i++){
        int r, l;
        cin >> r >> l;
        for(int j = r; j <= l; j++){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main(int argc, const char *argv[]) {
    int top1 = 0, top2 = 0, top3 = 0;
    for (int i = 0, h; i < 10 && std::cin >> h; i++) {
        if (h >= top1) {
            top3 = top2;
            top2 = top1;
            top1 = h;
        } else if (h >= top2) {
            top3 = top2;
            top2 = h;
        } else if (h >= top3) {
            top3 = h;
        }
    }
    std::cout << top1 << std::endl << top2 << std::endl << top3 << std::endl;
    return 0;
}

Measured memory_bytes: 3088
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>

using namespace std;

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


int main(){
	char buf[32];
	vector<int> nums;
	map<int,int> freq;
	int* dp = new int[60001];

	fill((int*)dp,(int*)dp+60001,1);

	dp[0]=0;
	dp[1]=0;

	for(int i=2;i<=60000;i++){
		if(dp[i]){
			for(int j=i+i;j<=60000;j+=i){
				dp[j]=0;
			}
		}
	}

	int num;
	while(~scanf("%d",&num)){
		for(int i=num-1;i>=0;i--){
			if(dp[i]){
				cout << i << " ";
				break;
			}
		}

		for(int i=num+1;i<=60000;i++){
			if(dp[i]){
				cout << i << endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define sz(arr) (int)(arr).size()
#define rng(arr) arr.begin(), arr.end()
#define show(x) cout << #x << " = " << x << endl;
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
typedef long long int ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

#define Cins(T, n, xs) \
  vector<T> xs(n);     \
  for (int i = 0; i < n; ++i) cin >> xs[i]

void Main();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

void Main() {
  Cin(int, n, k);
  Cins(int, n, h);
  sort(rng(h));
  int ans = 1001001001;
  for (int i = 0; i + k - 1 < n; ++i) ans = min(ans, h[i + k - 1] - h[i]);
  cout << ans << endl;
}

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

vector<int> g[100000];
int c[100000] = { 0 };

int k = 0;

void paint(int v, int prevColor) {
	int curr = 1;

	for (int i = 0; i < g[v].size(); ++i) {
		if (curr == prevColor) {
			++curr;
		}

		c[g[v][i]] = curr;
		++k;
		++curr;

		paint(g[v][i], curr - 1);
	}
}

int main() {
	int n;
	cin >> n;

	vector<int> l;
	for (int i = 0; i < n - 1; ++i) {
		int a, b;
		cin >> a >> b;

		g[a - 1].push_back(b - 1);
		l.push_back(b - 1);
	}

	paint(0, 0);

	int m = 0;
	for (int i = 1; i < n; ++i) {
		m = max(m, c[i]);
	}

	cout << m << endl;

	for (int li : l) {
		cout << c[li] << endl;
	}
	
	return 0;
}


Measured memory_bytes: 8572
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define fast ios::sync_with_stdio(false); cin.tie(NULL);
#define rep(n) for(int i=0; i<n; i++)
#define rep1(i,n) for(int i=0; i<n; i++)
const int INF = 2e18;

void solve(){
	
	int x,k,d;cin>>x>>k>>d;
	x = abs(x);
	if(k < (x/d)) cout<<x-k*d;
	else{
		int reqMoves = x/d+1;
		x = x - reqMoves*d;
		k = k - reqMoves;
		if(k%2==0)cout<<abs(x)<<endl;
		else cout<<x+d<<endl;
	}
}
	
signed main(){
    fast;    
    // int t;cin>>t;while(t--)
    solve();    
    return 0;
}


Measured memory_bytes: 3604
{-# LANGUAGE BangPatterns #-}

import           Control.Monad
import           Data.Array.ST
import           Data.Array.Unboxed    (UArray)
import qualified Data.Array.Unboxed    as U
import qualified Data.ByteString.Char8 as BS
import           Data.Char
import           Data.List

getAsInt :: IO [Int]
getAsInt =  unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

getAsIntLine :: Int -> IO [[Int]]
getAsIntLine n = replicateM n getAsInt

getAsIntArray2D :: Int -> Int -> IO (UArray (Int,Int) Int)
getAsIntArray2D n m = U.listArray ((1,1),(n,m)) . concat <$> getAsIntLine n


main :: IO ()
main = main2

main1 :: IO ()
main1 = do
  [n,w] <- getAsInt
  wvs <- getAsIntArray2D n 2
  let result = solve1 wvs n w
  print $ maximum $ map (\x -> result U.! (n,x)) [0..w]

main2 :: IO ()
main2 = do
  [n,w] <- getAsInt
  wvs <- map (\[x,y] -> (x, y)) <$> getAsIntLine n
  let solve = solve3
      result = solve w wvs
  print $ maximum $ map (\x -> result U.! x) [0..w]

solve1 :: UArray (Int,Int) Int -> Int -> Int -> UArray (Int,Int) Int
solve1 wvs n' w' = runSTUArray $ do
  dp <- newArray ((0,0),(n',w')) 0
  forM_ [(n_,w_) | n_ <- [1..n'], w_ <- [0..w']] $ \(n,w) -> do
    let wtmp = wvs U.! (n,1)
        vtmp = wvs U.! (n,2)
    if w - wtmp < 0
      then readArray dp (n-1,w) >>= writeArray dp (n,w)
      else do
        a <- readArray dp (n-1,w)
        b <- readArray dp (n-1,w-wtmp)
        writeArray dp (n,w) $ max a (b+vtmp)
  return dp

solve2 :: Int -> [(Int,Int)] -> UArray Int Int
solve2 w' [] = U.listArray (0,w') $ repeat 0
solve2 w' ((wtmp,vtmp):xs) = let a = solve2 w' xs
                                 f w = if w - wtmp >= 0
                                       then max (a U.! w) (a U.! (w - wtmp) + vtmp)
                                       else a U.! w
                             in U.array (0,w') [(w, f w) | w <- [0..w']]

solve3 :: Int -> [(Int,Int)] -> UArray Int Int
solve3 w' = foldr f (U.listArray (0,w') $ repeat 0)
  where f (wtmp,vtmp) a = let g w = if w - wtmp >= 0
                                    then max (a U.! w) (a U.! (w - wtmp) + vtmp)
                                    else a U.! w
                          in U.array (0,w') [(w, g w) | w <- [0..w']]

solve3' :: Int -> [(Int,Int)] -> UArray Int Int
solve3' !w' = foldr f (U.listArray (0,w') $ repeat 0)
  where f (!wtmp,!vtmp) !a = let g !w = if w - wtmp >= 0
                                        then max (a U.! w) (a U.! (w - wtmp) + vtmp)
                                        else a U.! w
                          in U.array (0,w') [(w, g w) | !w <- [0..w']]


Measured memory_bytes: 90876
var lines = [];
var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', (x) => {
    lines.push(x);
});

rl.on('close', () => {
    var N = Number(lines[0]);
    var A = lines[1].split(" ").map(i => Number(i));
    var ans = 0;

    for (var i = 0; i < N; i++) {
        
        for (var j = 0; j < 1000; j++) {
            if (A[i] % 2 !== 0) { break; }
            A[i] = A[i] / 2; ans++;
        }

    }
    
    console.log(ans);
});

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

#define ll long long

void solve()
{
    ll n,x,t, div;
    cin >> n >> x >> t;
    div = ceil(n/(double)x);
    cout << div*t << "\n";
    
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("D:\\Codings\\CPP\\input.in", "r", stdin);
    freopen("D:\\Codings\\CPP\\output.in", "w", stdout);
    #endif

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

    int t=1;
    //cin >> t;
    while(t--)
        solve();
   
    return 0;
}


Measured memory_bytes: 3644
#include <stdio.h>
#include <string>
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;

int main(void){
    int n,k;
    cin >> n >> k;
    int ans=k;
    for(int i=0; i<n-1; i++)ans*=k-1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int h=200001,f=0,i=0;
	char s[200001];
	scanf("%s",s);
	while(s[i]!=0){
		if(s[i]=='A'){
			if(i<h)h=i;
		}
		if(s[i]=='Z')f=i;
		i++;
	}
	printf("%d\n",f-h+1);
	return 0;
}

Measured memory_bytes: 384
#include<cstdio>
long long a[200005], b[200005];

long long max(long long a,long long b){ return a>b?a:b; }

int main(){
    int n;
    scanf("%d",&n);
    long long sum = 0;
    for(int i = 1; i <= n; i++){ 
        scanf("%lld%lld",&a[i],&b[i]);
        sum += a[i];
    }
    long long ans = 0;
    for(int i = 1; i <= n; i++){
        if(a[i]>b[i]){
            long long cur = sum-a[i]+a[i]-b[i];
            ans = max(ans,cur);
        }
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 2048
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
inline int read(){
	int x=0,f=1;char ch;
	do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
	do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
	return x*f;
}
const int N=200010,LOG=20;
int a[N],cnt[LOG];
void insert(int x){
	for (int i=0;i<LOG;++i)if (x&(1<<i)){
		++cnt[i];
	}
}
void del(int x){
	for (int i=0;i<LOG;++i)if (x&(1<<i)){
		--cnt[i];
	}
}
bool check(int x){
	for (int i=0;i<LOG;++i)if (x&(1<<i)){
		if (cnt[i]) return 0;
	}
	return 1;
}
int main(){
	int n=read();
	for (int i=1;i<=n;++i) a[i]=read();
	ll ans=0;
	int l=1;
	for (int r=1;r<=n;++r){
		while (!check(a[r])) del(a[l]),++l;
		insert(a[r]);
		ans+=(ll)(r-l+1ll);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

typedef long long ll;

int h,w;
int m[500][500];
int ans[100000][4];

int main(){
    cin >> h >> w;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> m[i][j];
        }
    }
    int count = 0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(i != 0){
                if(m[i-1][j] % 2 == 1){
                    ans[count][0] = i-1;
                    ans[count][1] = j;
                    ans[count][2] = i;
                    ans[count][3] = j;
                    m[i-1][j]--;
                    m[i][j]++;
                    count++;
                }
            }
            if(j != 0){
                if(m[i][j-1] % 2 == 1){
                    ans[count][0] = i;
                    ans[count][1] = j-1;
                    ans[count][2] = i;
                    ans[count][3] = j;
                    m[i][j-1]--;
                    m[i][j]++;
                    count++;
                }
            }
        }
    }
    cout << count << endl;
    for(int i=0;i<count;i++){
        for(int j=0;j<4;j++){
            cout << ans[i][j]+1;
            if(j != 3) cout << " ";
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 4608
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MAXM 100005
#define MOD 1000000007
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

int cur = 0;
string S, ans = "KIHBR";
bool flag;
vi id;

void solve(){

    rep(i, S.size()){
        if(ans[cur] == S[i]) {
            id.push_back(i);
            cur++;
        } else {
            if(S[i] != 'A') break;
        }
    }

    // rep(i, id.size()){
    //     cout << id[i] << endl;
    // }

    if(cur != 5) flag = false;
    else {
        if(id[0] < 2 && id[1] - id[0] == 1 && id[2] - id[1] == 1 && id[3] - id[2] <= 2 && id[4] - id[3] <= 2 && S.size() - id[4] <= 2)
            flag = true;
        else
            flag = false;
    }

    if(flag) cout << "YES" << endl;
    else cout << "NO" << endl;
}

int main(){
    cin >> S;

    solve();
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    int a, b, c, d;
    cin >> a >>b>>c>>d;
    cout << max(a*b, c*d) << endl;
    return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define int long long
#define all(x) (x).begin(), (x).end()

using LL = long long;
using LD = long double;
using pii = pair<int, int>;
using vii = vector<pii>;

const int INF = 1e18;
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;

int32_t main() {
    //ios::sync_with_stdio(false); cin.tie(nullptr);

    int a, b, c, k;
    cin >> a >> b >> c >> k;

    int sum = 1 * min(a, k); k -= min(a, k);
    sum += 0 * min(b, k); k -= min(b, k);
    sum += -1 * min(c, k); k -= min(c, k);

    cout << sum;
}

Measured memory_bytes: 3592
import scala.io.StdIn.{readInt,readLine}

object Main {

  def insert(l:List[Int],b:Int,c:Int):Boolean = {
    l match {
      case Nil => true
      case hd::tl =>
        if(b<hd) insert(tl,hd,c)
        else if(c<hd) insert(tl,b,hd)
        else false
    }
  }

  def main(args:Array[String]) =  {
    val n = readInt
    for(i<-0 until n) {
      if(insert(readLine.split(" ").map(_.toInt).toList,0,0))
        println("YES")
      else
        println("NO")
    }
  }
}

Measured memory_bytes: 43660