akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int N, K;
        public long[] A;
        public long MOD = 1000000007;
        public List<long> V;
        public void Run()
        {
            {
                var line = Input.ReadIntArray();
                N = line[0];
                K = line[1];
            }
            A = Input.ReadLongArray();
            V = new List<long>();

            for (int i = 0; i < N; i++)
            {
                long s = 0;
                for (int j = i; j < N; j++)
                {
                    s += A[j];
                    V.Add(s);
                }
            }

            long r = 0;
            for (int b = 60; b >= 0; b--)
            {
                int c = 0;
                for (int i = 0; i < V.Count; i++)
                {
                    if (((V[i] >> b) & 1L) == 1L) c++;
                }

                if (c >= K)
                {
                    r += (1L << b);
                    for (int i = 0; i < V.Count; i++)
                    {
                        if (((V[i] >> b) & 1L) == 0) V[i] = 0;
                    }
                }
            }
            Console.WriteLine(r);
        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

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

using ll = long long;
using ull = unsigned long long;
using st = string;
using ch = char;
using db = double;
using bl = bool;
using vll = vector<long long>;
using vdb = vector<db>;
using vst = vector<st>;
using vch = vector<char>;
using vbl = vector<bl>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
#define mkp(a, b) make_pair(a, b) 
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b;return true;} return false;}
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b;return true;} return false;}
const ll mod = 1000000007;
const ll inf = 1LL << 60;
const db pi = acos(-1.0L);

int main(){
  ll n, k;
  cin >> n >> k;
  vll p(n);
  vin(p);
  sort(all(p));
  ll ans = 0;
  rep(i, 0, k) ans += p.at(i);
  cout << ans << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }

const int mod=1000000007;
const int INF=1001001001;

int main() {
  int N,M;
  cin>>N>>M;
  vector<int>k(M);
  vector<vector<int>>s(10,vector<int>(10));
  for(int i=0;i<M;i++){
    cin>>k[i];
    for(int j=0;j<k[i];j++){
      cin>>s[i][j];
    }
  }
  vector<int>p(M);
  for(int i=0;i<M;i++){
    cin>>p[i];
  }

  int ans=0;
  for(int d=0;d<(1<<N);d++){
    vector<int>g(N);
    for(int i=0;i<N;i++){
      if((d>>i)&1){g[i]=1;}
    }
    bool ok=true;
    for(int i=0;i<M;i++){
      int cnt=0;
      for(int j=0;j<k[i];j++){
        int a=s[i][j];
        if(g[a-1]){cnt++;}
      }
      if(cnt%2!=p[i]){ok=false;}
    }
    if(ok){ans++;}
  }
  cout<<ans<<endl;
  return 0;  
}

Measured memory_bytes: 3616
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
# include <cstdlib>
# include <tuple>
# include <array>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2147483647;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr double HDINF = 50000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define RALL(qpqpq)           (qpqpq).rbegin(),(qpqpq).rend()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define RFOR(i,tptpt,ypypy)  for(LL i=(tptpt);i>=(ypypy);i--)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

const int MAX_V = 101010;
struct edge { LL to, cost; };
vector<edge> G[MAX_V];
int d[MAX_V];

LL n;

void bfs01(int s) {
	deque<pair<LL, LL>> que;
	fill(d, d + n, INF);
	d[s] = 0;
	que.push_back(make_pair(0, s));
	while (!que.empty()) {
		pair<int, int> p = que.front(); que.pop_front();
		int v = p.second;
		if (d[v] < p.first)continue;
		for (int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				if (e.cost == 0)que.push_front(make_pair(d[e.to], e.to));
				else que.push_back(make_pair(d[e.to], e.to));
			}
		}
	}
}

int main() {
	cin >> n;
	REP(i, n) {
		G[i].emplace_back(edge{ (i * 10) % n ,0 });
		G[i].emplace_back(edge{ (i + 1) % n,1 });
	}
	bfs01(1);
	cout << d[0]+1 << endl;
}

Measured memory_bytes: 8448
//#include <cmath>
//#include <cstdio>
//#include <vector>
//#include <map>
//#include <iostream>
//#include <algorithm>
//#include <set>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pil = pair<int,ll>;
using vi = vector<int>;
using vb = vector<bool>;
using pli = pair<ll,int>; 		
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
int INF = 1e9+7;


void solve(){
	int n;
	scanf("%d",&n);
	vi h(n);
	for(int i =0; i < n; ++i){
		scanf("%d",&h[i]);
	}
	vi dp(n+1,INF);//dp[i] -> min cost incurred to reach stone N
	dp[n-1] = 0;
	for(int i = n-1;i >=0 ;i--){
		for(int j : {i-1,i-2}){
			if(j >= 0)
			dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
		}
	}
	printf("%d\n",dp[0]);
	
}


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
	//cin >> t;
	//scanf("%d",&t);
	while(t--){
		solve();
	}
		
			
}


Measured memory_bytes: 3984
import sys
a, b, k = map(int, input().split())

if b == 0:
    if a-k >= 0:
        print(a-k, 0)
    else:
        print(0, 0)
    sys.exit()
elif a == 0:
    if b-k >= 0:
        print(0, b-k)
    else:
        print(0, 0)
    sys.exit()
elif a + b <= k:
    print(0, 0)
    sys.exit()
    
if a <= k:
    print(0, b -(k -a))
else:
    print(a-k, b)

Measured memory_bytes: 38256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll c(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }
map<ll, int> prime_factor(ll num) {
	map<ll, int> mp;
	ll k = (ll)sqrt(num);
	mp[1]++;
	rep(i, 2, k + 1) {
		while (num % i == 0) {
			num /= i;
			mp[i]++;
		}
	}
	if (num != 1)mp[num]++;
	return mp;
}
//mpの各要素は(first:素因数, second:指数)
//mp.size()にすれば素因数が何種類かを取得できる
//1が含まれることに注意
int main()
{
	map<int, int> mp;
	ll n;
	cin >> n;
	vector<int> a(n);
	rep(i, 0, n) {
		cin >> a[i];
		auto temp = prime_factor(a[i]);
		for (auto m : temp) {
			mp[m.first] = max(mp[m.first], m.second);
		}
	}
	ll lcm = 1;
	for (auto m : mp) {
		lcm *= mpower(m.first, m.second);
		lcm %= mod;
	}
	ll ans = 0;
	rep(i, 0, n) {
		ans += lcm * mpower(a[i], mod - 2);
		ans %= mod;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 4240
#include<bits/stdc++.h>
using namespace std;
int n,p[31],ans;
void f1(){
  swap(p[1],p[24]);
  swap(p[4],p[27]);
  swap(p[7],p[30]);
  swap(p[21],p[10]);
  swap(p[16],p[18]);
}
void f2(){
  swap(p[1],p[28]);
  swap(p[2],p[29]);
  swap(p[3],p[30]);
  swap(p[16],p[15]);
  swap(p[21],p[19]);
}
void f3(){
  swap(p[3],p[22]);
  swap(p[6],p[25]);
  swap(p[9],p[28]);
  swap(p[15],p[13]);
  swap(p[19],p[12]);
}
void f4(){
  swap(p[7],p[22]);
  swap(p[8],p[23]);
  swap(p[9],p[24]);
  swap(p[18],p[13]);
  swap(p[10],p[12]);
}
bool ch(){
  int f=1;
  for(int i=1;i<9;i++)if(p[i]!=p[i+1])f=0;
  for(int i=10;i<12;i++)if(p[i]!=p[i+1])f=0;
  for(int i=13;i<15;i++)if(p[i]!=p[i+1])f=0;
  for(int i=16;i<18;i++)if(p[i]!=p[i+1])f=0;
  for(int i=19;i<21;i++)if(p[i]!=p[i+1])f=0;
  for(int i=22;i<30;i++)if(p[i]!=p[i+1])f=0;
  return f;
}

void dfs(int a){
  if(a==9)return;
  if(ch()){ans=min(ans,a);return;}

  f1();
  dfs(a+1);
  f1();

  f2();
  dfs(a+1);
  f2();

  f3();
  dfs(a+1);
  f3();

  f4();
  dfs(a+1);
  f4();
}

int main(){
  cin>>n;
  while(n--){
    for(int i=1;i<=30;i++)cin>>p[i];
    ans=10;
    dfs(0);
    cout<<ans<<endl;   
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll MOD2=(ll)998244353;
const ll INF=(ll)1e18+10;
const double PI = 2.0*acos(0);

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

string str[200010];
int ans[100010];
int N;
int a[3];

bool syori(string com,int f, int s,int& i){
    if(a[f]==1&&a[s]==1){
        int tmp=i;
        while(str[tmp]==com&&tmp<N){
            ++tmp;
        }
        if(tmp==N||(tmp-i)%2==0){
            for (; i < tmp; ++i) {
                if(i%2==1) ans[i]=f;
                else ans[i]=s;
            }
        }else{
            bool add_f= false;
            if(com=="AB"){
                if(str[tmp]=="AC"){
                    add_f=true;
                }
            }else if(com=="AC"&&str[tmp]=="AB"){
                add_f=true;
            }else if(com=="BC"&&str[tmp]=="AB"){
                add_f=true;
            }
            bool p=add_f;
            for(;i<tmp;++i){
                if(add_f) ans[i]=f;
                else ans[i]=s;
                add_f^=1;
            }
            if(p){
                a[f]++; a[s]--;
            }else{
                a[s]++; a[f]--;
            }
        }
        i=tmp-1;
    }else if(a[f]==0&&a[s]==0){
        return false;
    }else{
        if(a[f]>a[s]){
            ans[i]=s;
            a[f]--;
            a[s]++;
        }else{
            ans[i]=f;
            a[f]++;
            a[s]--;
        }
    }
    return true;
}

void solve(int ca){
    cin>>N>>a[0]>>a[1]>>a[2];
    for (int i = 0; i < N; ++i) {
        cin>>str[i];
    }

    for (int i = 0; i < N; ++i) {
        int f,s;
        if(str[i]=="AB"){ f=0; s=1;}
        else if(str[i]=="BC"){ f=1; s=2;}
        else{ f=0; s=2;}
        if(!syori(str[i],f,s,i)){
            cout<<"No"<<"\n";
            return;
        }
        //cout<<ans[i]<<"\n";
    }
    cout<<"Yes"<<"\n";
    for (int i = 0; i < N; ++i) {
        cout<<(char)('A'+ans[i])<<"\n";
    }

}

//#define MULTI
int main() {
#ifdef MULTI
    int N; cin>>N;
    for (int i = 0; i < N; ++i) {
        solve(i+1);
    }
#else
    solve(0);
#endif
    return 0;
}


Measured memory_bytes: 10280
#include <bits/stdc++.h>
#define rep(i,s,t) for(int i = s;i <= t;i ++)
#define dow(i,t,s) for(int i = t;i >= s;i --)
#define REP(i,x) for(int i = 0;i < x.size();i ++)
#define DOW(i,x) for(int i = (int)s.size();i >= 0;i --)

#define fi first
#define se second

#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound


#define eps 1e-6
#define N
#define INF

#define SZ(x) ((int)(x).size())


using namespace std;

typedef vector<int> VI;
typedef long long LL;
typedef double db;
typedef pair<int,int> PII;


int n;
LL L[1001];
int main ()
{
    //freopen("in.in","r",stdin);
    //freopen("out.out","w",stdout);
    scanf("%d",&n);
    L[0] = 2;
    L[1] = 1;
    rep(i,2,n)L[i] = L[i - 1] + L[i - 2];
    cout << L[n] << endl;
    return 0;
}


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

int main(){
    ll a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    ll ans = 0;
    if (a + b > 2 * c){
        ans += min(x, y) * 2 * c;
        ll xx = x;
        x -= min(x,y);
        y -= min(xx,y);
        if (x > 0){
            if (a > 2 * c){
                ans += x * 2 * c;
            }
            else {
                ans += x * a;
            }
        }
        else {
            if (b > 2 * c){
                ans += y * 2 * c;
            }
            else {
                ans += y * b;
            }
        }
    }
    else {
        ans += x * a + y * b;
    }
    cout << ans << endl; 
}

Measured memory_bytes: 256
A, B, C, D = map(int, input().split())
def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x % y)

def lcm(x, y):
    return (x * y) // gcd(x, y)

def calc(n, c, d):
    lcm_num = n // lcm(c, d)
    c_num = n // c
    d_num = n // d
    return n - c_num - d_num + lcm_num

ret = calc(B, C, D) - calc(A-1, C, D)
print(ret)

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
   ll  h,w;cin >>h>>w;
   ll white=0;
   vector<vector<char>>s(h,vector<char>(w));
   vector<vector<ll>>d(h,vector<ll>(w,INF));
   d[0][0]=1;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >>s[i][j];
            if(s[i][j]=='.')white++;
        }
    }
   queue<P>que;que.push({0,0});
   while(!que.empty()){
       P pos=que.front();
       que.pop();
       ll x=pos.first;
       ll y=pos.second;
       ll pre=d[x][y];
       auto add=[&](ll x, ll y){
           if(x<0||x>=h)return ;
           if(y<0||y>=w)return;
           if(s[x][y]=='#')return;
           if(d[x][y]>pre+1){
               d[x][y]=pre+1;
               que.push({x,y});
           }
       };
       add(x+1,y);
       add(x-1,y);
       add(x,y+1);
       add(x,y-1);
   }
   if(d[h-1][w-1]==INF)cout <<-1<<endl;
   else cout <<white-d[h-1][w-1]<<endl;
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();

    VI a(3); cin >> a;
    SORT(a);
    cout << (a[0] + a[1] == a[2] ? "Yes\n" : "No\n");
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N = int(input())
STATE = [[]]*N
for i in range(N):
    a = int(input())
    STATE[i] = [list(map(int, input().split())) for i in range(a)]

def main():
    ans = 0
    for i in range(1<<N):
        ans = max(ans, detect(i))
    print(ans)

def detect(i):
    ONT = 0
    for j in range(N):
        if  not (i & 1<<j):
            continue
        ONT += 1
        for x, y in STATE[j]:
            # if (i & 1<<(x-1)) == (y>0):
            #     print('good')
            #     continue
            # else:
            #     return 0
            # if ((i & (1 << (x-1)))>0) != (y>0):
            if (y == 1) and (i&(1<<(x-1))) == 0:
                return 0
            # if (y == 0) and (i&(1<<(x-1))) > 0:
            if (y==0) and (i>>(x-1) & 1) == 1:
                return 0
    return ONT

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;


ll nextl(ll x){
  if(x<10) return x+1;
  ll x10 = x/10%10;
  ll x1 = x%10;
  if((x10-x1 == 0 || x10-x1 == 1) && !(x10==9 && x1 == 9))return x + 1;
  ll num = nextl(x/10);
  return num*10 + num%10 -1 + (num%10? 0 : 1); 

}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll k;cin >> k;
  ll ans = 0;
  rep(i,k){
    ans = nextl(ans);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
// #pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
#define IMAX 2147483647
#define LMAX 9223372036854775807
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);
#define fou(i,a,n) for(int i=a;i<n;i++)
#define fod(i,a,n) for(int i=n-1;i>=a;i--)
#define rep(n) fou(_,0,n)
#define tra(a,x) for(auto& a : x)
#define elif(c) else if(c)
#define VI vector<int>
#define VD vector<double>
#define VC vector<char>
#define VS vector<string>
#define VVI vector<VI>
#define VVD vector<VD>
#define VVC vector<VC>
#define VVS vector<VS>
#define emb emplace_back
#define pub push_back
#define pob pop_back
#define mp make_pair
#define fi first
#define se second
#define si(vec) ((int)(vec).size())
#define all(vec) vec.begin(),vec.end()
#define lla(vec) vec.rbegin(),vec.rend()
#define range(vec,x,y) vec.begin()+x,vec.begin()+y
#define sortup(vec) sort(all(vec))
#define sortdown(vec) sort(lla(vec))
#define eraseif(vec,condition_VAR) vec.erase(remove_if(all(vec),[&](auto VAR){return condition_VAR;}),vec.end())
#define countif(vec,condition_VAR) count_if(all(vec),[&](auto VAR){return condition_VAR;})
#define replaceif(vec,condition_VAR,n) replace_if(all(vec),[&](auto VAR){return condition_VAR;},n)
#define erase_unique(vec) vec.erase(unique(all(vec)),vec.end())
#define calcvec(vec,calc_VAR) for_each(all(vec),[&](auto&VAR){VAR=calc_VAR;});
#define calc2vec(vec1,op,vec2) {rep(1){int s=min(si(vec1),si(vec2));fou(i,0,s)vec1[i]=vec1[i] op vec2[i];}}
template<class C>void mini(C &a,C b){a=min(a,b);}
template<class C>void maxi(C &a,C b){a=max(a,b);}
#define in(T,...) T __VA_ARGS__;_cin(__VA_ARGS__);
#define out(...) _cout(__VA_ARGS__);
void _cin(){}template<class Head,class...Tail>void _cin(Head&head,Tail&&...tail){cin>>head;_cin(forward<Tail>(tail)...);}
template<class Head>void _cout(Head head){cout<<head<<endl;}template<class Head,class...Tail>void _cout(Head head,Tail...tail){cout<<head<<" ";_cout(forward<Tail>(tail)...);}
template<class C>void outvec(vector<C> vec){int vecsize=si(vec);fou(i,0,vecsize-1)cout<<vec[i]<<" ";out(vec[vecsize-1]);}
template<class C> C gcd(C a,C b){if(a&&b)return gcd(min(a,b),max(a,b)%min(a,b));else return a;}
template<class C> C lcm(C a,C b){return a/gcd(a,b)*b;}
template<class C>int binarysearch(vector<C> vec,C n,char c){int left=-1;int right=si(vec);bool outleft=(c=='d'||c=='U');int getmin=(c=='u'||c=='d')?1:-1;while(right-left>1){int mid=left+(right-left)/2;bool OK=vec[mid]*getmin>=n*getmin;if(outleft==OK) left=mid;else right=mid;}return outleft?left:right;}


// #define int int64_t
// #define double long double


// map,makepair



signed main(){
  IOS;

  VI a(3);
  fou(i,0,3) cin>>a[i];
  sortup(a);
  int ans=a[2]-a[0];
  out(ans)


}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,m;
	cin>>n>>m;
	long long int sum=0;
	for(int i=1;i<n;i++)
		sum=sum+i;
	for(int i=1;i<m;i++)
		sum=sum+i;

	cout<<sum<<endl;
}

Measured memory_bytes: 256
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7


def run():
    N = int(input())
    for h in range(1, 3501):
        for n in range(1, 3501):
            v = N * h * n
            a = 4 * h * n - N * n - N * h
            if a <= 0:continue
            if not v % a:
                w = v // a
                print(f'{h} {n} {w}')
                return

if __name__ == "__main__":
    run()


Measured memory_bytes: 9196
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n) { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x) { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};
struct bracket {
	int r;
	int c;
	int s;
	int cnt;
};

int main() {
	int p, q;
	while (cin >> p >> q, p) {
		cin.ignore();
		vector<bracket> brk(p, { 0,0,0,0 });
		vector<bracket> brk2(q, { 0,0,0,0 });
		REP(i, p) {
			if (i > 0)
				brk[i] = brk[i - 1];
			string s;
			getline(cin, s);
			int cnt = 0;
			while (cnt < s.length()&&s[cnt] == '.')
				cnt++;
			brk[i].cnt = cnt;
			REP(j, s.length()) {
				if (s[j] == '(')
					brk[i].r++;
				if (s[j] == ')')
					brk[i].r--;
				if (s[j] == '{')
					brk[i].c++;
				if (s[j] == '}')
					brk[i].c--;
				if (s[j] == '[')
					brk[i].s++;
				if (s[j] == ']')
					brk[i].s--;
			}
		}
		REP(i, q) {
			if (i > 0)
				brk2[i] = brk2[i - 1];
			string s;
			getline(cin, s);
			REP(j, s.length()) {
				if (s[j] == '(')
					brk2[i].r++;
				if (s[j] == ')')
					brk2[i].r--;
				if (s[j] == '{')
					brk2[i].c++;
				if (s[j] == '}')
					brk2[i].c--;
				if (s[j] == '[')
					brk2[i].s++;
				if (s[j] == ']')
					brk2[i].s--;
			}
		}
		cout << "0";
		FOR(m,1, q) {
			int ans = -1;
			FOR(i, 1, 21) {
				FOR(j, 1, 21) {
					FOR(k, 1, 21) {
						bool pass = true;
						REP(l, p - 1) {
							if (brk[l].r*i + brk[l].c*j + brk[l].s*k != brk[l + 1].cnt) {
								pass = false;
								break;
							}
						}
						if (!pass)
							continue;
						int tmp = brk2[m - 1].r*i + brk2[m - 1].c*j + brk2[m - 1].s*k;
						if (ans == -1) {
							ans = tmp;
						}
						else {
							if (ans != tmp) {
								ans = -1;
								i = j = k = 21;
							}
						}
					}
				}
			}
			cout << " " << ans;
		}
		cout << endl;
	}
}

Measured memory_bytes: 3196
#include<iostream>
#include<fstream>
#include<vector>
#include<initializer_list>
#include<string>
using namespace std;
  int main(){
 int a;
 cin >> a;
int b;
cin >> b;
int c;
cin >> c;


if (a==b&& b==c)
cout << 1 << endl;
else if (a==b&& b!=c)
cout << 2 << endl;

else if (a==c&& b!=c)
cout << 2 << endl;

else if (b==c&& b!=a)
cout << 2 << endl;

    else if ( b!=a && a!=c)
      cout << 3 << endl;

else 
cout << 1 << endl;






}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,cnt,a[20],f[100001];
int get(int k)
{
	if(f[k])return f[k];
	int res=k;
	for(int i=cnt;i>=1;i--)
	  if(k>=a[i])res=min(res,1+get(k-a[i]));
	return f[k]=res;
}
int main()
{
	int k=6;
	while(k<100000)a[++cnt]=k,k*=6;
	k=9;
	while(k<100000)a[++cnt]=k,k*=9;
	cin>>n;cout<<get(n)<<endl;
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
int main(void){
char s[100];
  scanf("%s",&s);
  for(int i=0;i<strlen(s);i++){
    if((i+1)%2!=0){
      if(s[i]=='L'){
        printf("No");
        return 0;
      }
    }
    else {
      if(s[i]=='R'){
        printf("No");
        return 0;
      }
    }
  }
    printf("Yes");
    return 0;
  }

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
    int x,a=1;
    cin>>x;
    for(;a;x++){
        a=0;
        for(int i=2;i*i<=x;i++) if(x%i==0) a=1;
    }
    cout<<x-1<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
 
int main()
{
  int N;
  cin >> N;
  vector<int> A(N);
  REP(i, N) cin >> A[i];
  
  sort(ALL(A));
  reverse(ALL(A));
  int a = 0, b = 0;
  REP(i,N){
    if(i%2 == 0){
      a += A.at(i);
    }else{
      b += A.at(i);
    }
  }
  cout << a - b << endl;
}

Measured memory_bytes: 256
N = int(input())

ans=[0]*N

for x in range(1,101):
  for y in range(1,101):
    for z in range(1,101):
      F=x**2 + y**2 + z**2 + x*y + y*z + z*x
      if(N>=F):
        ans[F-1] += 1
        
for i in ans:
  print(i)

Measured memory_bytes: 9104
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    string s1;
    cin>>s1;
    int c=0,k=s.size();
    for(int i=0;i<k;i++)
    {
        if(s[i]!=s1[i])
        {
            c++;
        }
    }
    cout<<c<<endl;
}


Measured memory_bytes: 3916
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>


using namespace std;


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

    int N;
    cin>>N;

    vector<int> vec(N,0);

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

    sort(vec.begin(),vec.end());

    int center = N/2 -1;

    int diff =  vec[center+1] - vec[center];

    cout<<diff;

    return 0;
}

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

int main() {
  
  ll a, b, x;
  cin >> a >> b >> x;
  
  ll c = b/x - a/x;
  if (a % x == 0) c++;
  
  cout << c << endl;
   
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iso646.h>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

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

const ll INF = 1e15;
const ll MOD = 1e9 + 7;

const ll N_MAX = 1e18;

int main() {
    ll N;
    cin >> N;
    vll A(N + 1);
    for(auto &e : A)
        cin >> e;
    vll M, L;
    ll i;
    if(N == 0) {
        if(A[0] == 1) {
            cout << 1 << endl;
        } else {
            cout << -1 << endl;
        }
        return 0;
    }
    if(N > 0 && A[0] != 0) {
        cout << -1 << endl;
        return 0;
    }
    for(i = 0; i < N + 1; i++) {
        ll m;
        if(i <= 50) {
            m = pow(2, i);
        } else {
            m = N_MAX;
        }
        M.push_back(m);
    }
    for(i = 0; i < N + 1; i++) {
        if(i == 0) {
            L.push_back(1);
        } else {
            ll n = min((L[i - 1] - A[i - 1]) * 2, M[i]);
            if(n <= 0) {
                cout << -1 << endl;
                return 0;
            }
            L.push_back(n);
        }
    }
    if(L[N] < A[N]) {
        cout << -1 << endl;
        return 0;
    }
    ll ans = 0;
    ll p = 0;
    for(i = N; i >= 0; i--) {
        p = min(p + A[i], L[i]);
        ans += p;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6200
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x) cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define SANKOU(n, a, b) cout << ((n) ? (#a) : (#b)) << endl
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define P pair<int, int>
#define V vector<int>
#define M map<int, int>
#define S set<int>

int L, n, x[200010];
int pref[200010];

void solve()
{
    FOR(i, 0, n)
    pref[i + 1] = pref[i] + x[i];
    int ans = 0;
    FOR(i, 0, n)
    {
        int k = min(i, n - 1 - i);
        int cur = x[i];
        cur += 2 * (pref[i] - pref[i - k]);
        if (i + k + 1 < n)
            k++;
        cur += 2 * (k * L - pref[i + k + 1] + pref[i + 1]);
        ans = max(cur, ans);
    }
    FOR(i, 0, n)
    {
        int k = min(i, n - 1 - i);
        int cur = L - x[i];
        cur += 2 * (k * L - pref[i + k + 1] + pref[i + 1]);
        if (i > k)
            k++;
        cur += 2 * (pref[i] - pref[i - k]);
        ans = max(cur, ans);
    }
    cout << ans << endl;
}

signed main()
{
    cin >> L >> n;
    FOR(i, 0, n)
    cin >> x[i];
    solve();
    return 0;
}


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

int main() {

  long long int w, h, x, y, r;
  cin >> w >> h >> x >> y >> r;

  if ( x - r < 0 || x + r > w || y - r < 0 || y + r > h ) {

    cout << "No" << endl;

  }else {

    cout << "Yes" << endl;

  }

  return 0;

}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int A,B,C;
    cin>>A>>B>>C;
    for(int i=1;i<=B;i++)
    {
        if(A*i%B==C)
        {
            cout<<"YES";
            return 0;
        }
    }
    cout<<"NO";
	return 0;
} 

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	m := map[string]int{}
	for i := 0; i < n; i++ {
		s := getNextString(scanner)
		m[s] = 1
	}
	fmt.Fprintln(writer, len(m))
}


Measured memory_bytes: 19396
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;


namespace Test1 {

    


    class ClassMain {

       
        public static void Main(String[] args) {
            string line;
            while ((line = Console.ReadLine()) != null) {
                int[] ints = line.Split(' ').Select(int.Parse).ToArray() ;
                int start = 60 * 60 * ints[0] + 60 * ints[1] + ints[2];
                int end = 60 * 60 * ints[3] + 60 * ints[4] + ints[5];
                int diff = end - start;
                Console.WriteLine(diff / 3600 + " " + (diff % 3600) / 60 + " " 
                    + (diff % (3600))%60);
                ints = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                start = 60 * 60 * ints[0] + 60 * ints[1] + ints[2];
                end = 60 * 60 * ints[3] + 60 * ints[4] + ints[5];
                diff = end - start;
                Console.WriteLine(diff / 3600 + " " + (diff % 3600) / 60 + " "
                    + (diff % (3600)) % 60);
                ints = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                start = 60 * 60 * ints[0] + 60 * ints[1] + ints[2];
                end = 60 * 60 * ints[3] + 60 * ints[4] + ints[5];
                diff = end - start;
                Console.WriteLine(diff / 3600 + " " + (diff % 3600) / 60 + " "
                    + (diff % (3600)) % 60);
                //break;
            }
        }

        
    }



    
}

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



int n, a[200];

int main() {
	cin >> n;
	for (int i = 0; i < 2 * n; i++) {
		cin >> a[i];
	}
	sort(a, a + (2 * n));

	int ans = 0;
	for (int i = 0; i < 2 * n - 1; i += 2) {
		ans += min(a[i], a[i + 1]);
	}
	cout << ans << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <utility>
#include <math.h>
#include <stdexcept>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string.h>
#include <cassert>
#include <string.h>
#include <tuple>

using namespace std;
#define  rep(i,n) for(int i=0;i<n;i++)
#define  rrep(i,n) for(int i=n-1;i>=0;i--)///n-1番目からn回
#define  REP(i,a,b) for(int i=a;i<=b;i++) ///a番目からb回
#define  RREP(i,a,b) for(int i=a;i<b;i--)
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pair_t;
#define MOD 1000000007

//int arr[N]
////sort(arr,arr +N)

//vector <int> hoge
////sort(hoge.begin(),hoge.end());
///*min_element(hoge.begin(),hoge.end();　最小値　　　最大値はmax_element();
///(10-(n%10))%10  10-(1桁目)取得 12->8 20->0

#define Ru(n)  ( ((n)+9)/10*10  ) //切りあげ
#define Rd(n)  ( ((n)-10)/10*10 +10 )	切り捨て


int gcd(int a,int b);
size_t length(const std::string& str) {
	return str.length();
}
bool comp(const pair_t &a, const pair_t &b) {
	return a.first < b.first;
}

int main() {

	string s,tmp,out="Good";
	cin>>s;
	rep(i,3){
		tmp=s[i];
		if(s[i]==s[i+1])
			out="Bad";
	}
	cout<<out<<endl;

	return 0;

}


int gcd(int a,int b){
	if(b==0) return a;
	return gcd(b,a%b);
}


Measured memory_bytes: 256
n=int(input())
hList=list(map(int,input().split()))
count = 0
for i in range(1,n-1):
    if (hList[i-1] < hList[i] and hList[i] < hList[i+1]) or (hList[i+1] < hList[i] and hList[i] < hList[i-1]):
        count += 1
print(count)

Measured memory_bytes: 3060
from functools import reduce
import math
def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0
def modinv(a, m):
    g, x, y = xgcd(a, m)
    return x % m
def modmul(a,b):
    return a * b % 998244353
def comb(n,r,m):
    if r == 0: return 1
    return memf[n]*pow(memf[r],m-2,m)*pow(memf[n-r],m-2,m)
def mempow(a,b):
    temp = 1
    yield temp
    for i in range(b):
        temp = temp * a % 998244353
        yield temp
def memfact(a):
    temp = 1
    yield temp
    for i in range(1,a+1):
        temp = temp * i % 998244353
        yield temp

N,M,K = (int(x) for x in input().split())
memp = []
memf = []
mpappend = memp.append
mfappend = memf.append
for x in mempow(M-1,N-1):
    mpappend(x)
for x in memfact(N-1):
    mfappend(x)
ans = 0
if M == 1:
    if K + 1 < N:
        print('0')
    else:
        print('1')
else:
    i = 0
    for i in range(K+1):
        ans = (ans + (comb(N-1,i,998244353)*M*memp[N-i-1])) % 998244353
    print(ans)

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

using ll = long long;

const ll INF = 1001001001001;

int main() {
	ll N, W;
	cin >> N >> W;
	const int max_value = 100000;
	vector<vector<ll>> dp(N + 1, vector<ll>(max_value + 1, INF));
	dp[0][0] = 0;
	for (int i = 1; i <= N; ++i) {
		ll w, v;
		cin >> w >> v;
		for (int j = 0; j <= max_value; ++j) {
			if (j - v < 0) {
				dp[i][j] = dp[i - 1][j];
			} else {
				dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v] + w);
			}
		}
	}
	int ans = 0;
	for (int i = max_value; i >= 0; --i) {
		if (dp[N][i] <= W) {
			ans = i;
			break;
		}
	}
	cout << ans << endl;

	// for (int i = 0; i < N + 1; ++i) {
	// 	for (int j = 0; j < 100001; ++j) {
	// 		cout << dp[i][j] << " ";
	// 	}
	// 	cout << endl;
	// }
}

Measured memory_bytes: 80256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class DChatInACircle {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        int N;
        in>>N;
        vc<int> A(N);
        REP(i, N) in>>A[i];
        sort(RALL(A));
        vc<lint> B;
        REP(i, N){
            B.pb(A[i]);
            if(i) B.pb(A[i]);
        }
        lint sum = 0;
        REP(i, N-1) sum += B[i];
        out<<sum<<'\n';
    }
};


int main() {
	DChatInACircle solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 8212
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
#include <bitset>
using namespace std;

typedef long long ll;

ll dp[3005][3005];

int main() {
	string s, t; cin >> s >> t;
	int n = s.size(), m = t.size();
	s = "@" + s;
	t = "@" + t;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			dp[i][j] = max({dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1] + (s[i] == t[j])});
		}
	}
	int i = n, j = m;
	string ans = "";
	while (i > 0 && j > 0) {
		if (dp[i][j] == dp[i - 1][j]) i--;
		else if (dp[i][j] == dp[i][j - 1]) j--;
		else ans += s[i--], j--;
	}
	reverse(ans.begin(), ans.end());
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 70656
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
using ll = long long;
using namespace std;
int main(){
    int h,w,a,b;
    cin>>h>>w>>a>>b;
    rep(i,b){
        rep(j,w){
            if(j<a) cout<<"1";
            else cout<<"0";
        }
        cout<<endl;
    }
    rep(i,h-b){
        rep(j,w){
            if(j<a) cout<<"0";
            else cout<<"1";
        }
        cout<<endl;
    }
}

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

using namespace std;
#define DIM  200007
#define DIM2 507
#define INF 10E16
#define MAXN 107
#define LG 18

typedef long long  ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef ll arr[DIM];
typedef vector<ll> vec;
typedef vector<ll> graph[DIM];
typedef pll parr[DIM];
typedef ll table[DIM][DIM2];
struct pp {
	ll a, b;
	bool operator <(const pp& V)const {
		if (a == V.a)return b < V.b;
		return a < V.a;
	}
	bool operator ==(const pp& V)const {
		if (a == V.a && b == V.b)return 1;
		return 0;
	}
};

ll n, m, all = 0,res = 0;
vec T;
arr D,vis;
graph A;
void topsort(ll x) {
	vis[x] = 1;
	for (ll to : A[x]) {
		if (vis[to] == 0)topsort(to);
	}
	T.push_back(x);
}
void dfs(ll x) {
	vis[x] = 1;
	for (ll to : A[x]) {
		if (vis[to] == 0)dfs(to);
		D[x] = max(D[x], D[to] + 1);
		//res = max(res, D[x]);
	}
}
int main()
{
	cin >> n >> m;
	for (int i = 1; i <= m; i++) {
		ll x, y; cin >> x >> y;
		A[x].push_back(y);
	}
	for (int i = 1; i <= n; i++) {
		if (vis[i] == 0)
			topsort(i);
	}
	memset(D, 0, sizeof(D));
	for (ll to : T) {
		dfs(to);
		res = max(res, D[to]);
	}
	cout << res << endl;
}
// 011 1

Measured memory_bytes: 14068
package main
import (
   "fmt"
   "os"
   "bufio"
   "strconv"
   "regexp"
   "strings"
)
var sc = bufio.NewScanner(os.Stdin)

func main() {
  sc.Split(bufio.ScanLines)
  str := getStdin()

  for _, v := range str {
	  if regexp.MustCompile(`[A-Z]`).Match([]byte(string(v))) {
		  fmt.Print(strings.ToLower(string(v)))
	  } else if regexp.MustCompile(`[a-z]`).Match([]byte(string(v))) {
		  fmt.Print(strings.ToUpper(string(v)))
	  } else {
		  fmt.Print(string(v))
	  }
  }
  fmt.Println()

}

func getStdin() (string) {
	sc.Scan()
	v := sc.Text()
	return v
}

func nextInt() (int) {
	sc.Scan()
	v, e := strconv.Atoi(sc.Text())
    if e != nil { panic(e) }
    return v
}

func nextFloat() (float64) {
	sc.Scan()
	v, e := strconv.ParseFloat(sc.Text(), 64)
    if e != nil { panic(e) }
    return v
}



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

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

int main() {
    int N; cin >> N;
    vector H(N, vector(3, int()));
    REP(i, N) cin >> H[i][0] >> H[i][1] >> H[i][2];

    // dp[i][a]: i日目にaをするときの、i日目までの幸福度の総和の最大値
    vector dp(N, vector(3, int()));

    REP(a, 3) dp[0][a] = H[0][a];
    FOR(i, 1, N) REP(a, 3) {
        dp[i][a] = max(dp[i-1][(a+1)%3], dp[i-1][(a+2)%3]) + H[i][a];
    }

    cout << *max_element(ALL(dp[N-1])) << '\n';
}


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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

const lli e5 = 1 << 20;
const lli mod = 1000000007;
const lli e3 = 1 << 13;
const lli INF = 1ll << 62;

lli n;
string s;
lli b[e5];
lli ans = 1;

int main(){
  cin >> n;
  cin >> s;
  for(lli i = 0;i < n;i++){
    b[s[i]]++;
  }
  for(lli i = 'a';i <= 'z';i++){
    ans *= (b[i]+1);
    ans %= mod;
  }
  cout << (ans-1+mod)%mod << endl;
}


Measured memory_bytes: 512