akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cctype>
#include <map>
#include <set>

const int INT_INF = 1e9;
const long long LONG_INF = 1e18;
const long long MOD = 1e9 + 7;

using namespace std;

int main()
{
    int n, m, q;
    cin >> n >> m >> q;
    vector<int> a(q), b(q), c(q), d(q);
    for (int i = 0; i < q; i++)
    {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }

    long long int ans = 0;

    vector<int> i(11);
    for (i[1] = 1; i[1] <= m; i[1]++)
        for (i[2] = i[1]; i[2] <= m; i[2]++)
            for (i[3] = i[2]; i[3] <= m; i[3]++)
                for (i[4] = i[3]; i[4] <= m; i[4]++)
                    for (i[5] = i[4]; i[5] <= m; i[5]++)
                        for (i[6] = i[5]; i[6] <= m; i[6]++)
                            for (i[7] = i[6]; i[7] <= m; i[7]++)
                                for (i[8] = i[7]; i[8] <= m; i[8]++)
                                    for (i[9] = i[8]; i[9] <= m; i[9]++)
                                        for (i[10] = i[9]; i[10] <= m; i[10]++)
                                        {

                                            bool f = true;
                                            long long int temp = 0;
                                            for (int j = 0; j < q; j++)
                                            {
                                                if (i[b[j]] - i[a[j]] == c[j])
                                                {
                                                    temp += d[j];
                                                }
                                            }
                                            ans = max(ans, temp);
                                        }

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

Measured memory_bytes: 3636
import sys

input = sys.stdin.readline
n, k = map(int, input().split())
v_list = list(map(int, input().split()))
ans = 0
for i in range(1, min(n,k)+1):
    for j in range(i+1):
        cnt = k - i
        tmp_list = []
        if j == 0:
            tmp_list += v_list[-i:]
        elif j == i:
            tmp_list += v_list[:i]
        else:
            tmp_list += v_list[:j]
            tmp_list += v_list[-(i-j):]
        tmp_list.sort()
        tmp_sum = sum(tmp_list)
        for tmp in tmp_list:
            if cnt <= 0:
                break
            if tmp < 0:
                tmp_sum -= tmp
                cnt -= 1
            else:
                break
        ans = max(ans, tmp_sum)
print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using pll=pair<ll,ll>;
using plll=pair<ll,pll>;
using graph=vector<vector<int>>;

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

ll abs1(ll a){
  if(a>=0)return a;
  else return -a;
}

ll pow1(ll a,ll b,ll p=LLONG_MAX){
  ll ret=1;
  while(b!=0){
    if((b&1)==1){
      ret*=a;
    }
    a*=a;
    if(a>=p)a%=p;
    b=b>>1;
  }
  return ret;
}

int digit(ll a,ll b){
  int i=0;
  while(a!=0){
    a/=b;
    i++;
  }
  return i;
}

ll gcd1(ll a,ll b){
  if(a==0 && b==0)return 0;
  ll n;
  while(a%b!=0){
    n=a%b;
    a=b;
    b=n;
  }
  return b;
}

ll solveLinear(ll n,ll m,ll c){
  if(n==0 && m==0)return 0;
  ll a[100],b[100];
  a[0]=n;b[0]=m;
  int i=1;
  while(b[i-1]!=0){
    a[i]=b[i-1];
    b[i]=a[i-1]%b[i-1];
    i++;
  }
  n=i;
  if(c%a[n-1]!=0){
    return 0;
  }
  ll x=c/a[n-1],y=0;
  for(i=1;i<n;i++){
    ll cnt=x;
    x=y;
    y=cnt-(a[n-i-1]/b[n-i-1])*y;
  }
  return x;
}

ll modInv(ll a,ll p=MOD){
  a%=p;
  ll n=solveLinear(a,p,1);
  n%=p;
  if(n<0)return n+p;
  return n;
}

ll fact(ll n,ll p=MOD){
  if(n<0)return 0;
  int i;
  ll ret=1;
  for(i=0;i<n;i++){
    ret=ret*(i+1);
    if(ret>=p)ret%=p;
  }
  return ret;
}

ll perm(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  int i;
  ll ret=1;
  for(i=0;i<k;i++){
    ret=ret*(n-i);
    if(ret>=p)ret%=p;
  }
  return ret;
}

ll binom(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  int i;
  ll ret=1,fact=1;
  for(i=0;i<k;i++){
    ret=ret*(n-i);
    fact*=i+1;
    if(ret>=p)ret%=p;
    if(fact>=p)fact%=p;
  }
  return (ret*modInv(fact))%p;
}

void pushHeap(vector<int>& h,int n){
  int i=h.size();
  h.push_back(n);
  while(i!=0 && h[(i-1)/2]<h[i]){
    swap(h[i],h[(i-1)/2]);
    i=(i-1)/2;
  }
  h[i]=n;
}

int popHeap(vector<int>& h){
  int n=h.size()-1;
  if(n==-1)return 0;
  int i,ret=h[0];
  swap(h[0],h[n]);
  h.pop_back();
  for(i=0;i<n;){
    int j=2*i+1;
    if(j>=n)break;
    if(j!=n-1 && h[j]<h[j+1])j++;
    if(h[i]<h[j]){
      swap(h[i],h[j]);
    }
    i=j;
  }
  return ret;
}

int num=1;
vector<int> ver;
void dfs(const graph &g,int v){
  ver[v]=num;
  for(auto i:g[v]){
    if(ver[i]!=0)continue;
    dfs(g,i);
  }
}

int main(){
  int i,j,k,cnt=0;
  int n,m;
  cin>>n>>m;
  int p[n];
  for(i=0;i<n;i++)cin>>p[i];
  graph g(n);
  for(i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    a--;b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  ver.assign(n,0);
  for(i=0;i<n;i++){
    if(ver[i]!=0)continue;
    dfs(g,i);
    num++;
  }
  for(i=0;i<n;i++){
    if(ver[p[i]-1]==ver[i])cnt++;
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 8576
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int N;
    cin >> N;
    int a[N];
    rep(i, N) cin >> a[i];
    int all = 0;
    rep(i, N) all ^= a[i];
    rep(i, N){
        cout << (all^a[i]) << ' ';
    }
    cout << endl;
}

Measured memory_bytes: 4376
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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 (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;

int main() {
    int a, b, h;
    cin >> a >> b >> h;
    cout << (a + b) * h / 2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=101000;
int n,k;
char p[N];
pair<char,int> go[N];
string s,t,ans;
int main() {
	scanf("%d%d",&n,&k);
	scanf("%s",p);
	s=p; t=s; reverse(all(t));
	s=s+t;
	per(i,0,SZ(s)) {
		if (i==SZ(s)-1||s[i]!=s[i+1]) go[i]=mp(s[i],-1);
		else { go[i]=go[i+1]; go[i].se--; }
	}
	auto v=*min_element(go,go+n);
	--k;
	rep(i,0,n) if (go[i]==v) {
		if (k>=20||(-(ll)go[i].se*(1<<k)>=n)) {
			rep(j,0,n) printf("%c",s[i]); puts("");
			return 0;
		}
		string ss(-go[i].se*(1<<k),go[i].fi);
		int j=i-go[i].se;
		while (SZ(ss)<n) ss.pb(s[j++]);
		if (ans.empty()) ans=ss;
		ans=min(ans,ss);
	}
	printf("%s\n",ans.c_str());
}


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

using namespace std;

int N, a[2017], dp[2017][2017];

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d %d %d", &N, &a[1], &a[2]);
for (int i=3; i<=N + 2; i++)
    scanf ("%d", &a[i]);
for (int i=1; i<=N + 1; i++)
    dp[N + 2][i] = dp[i][N + 2] = (a[i] - a[N + 2] > 0 ? a[i] - a[N + 2] : a[N + 2] - a[i]);
for (int lim = N + 1; lim >= 2; lim--)
{
    int curr = dp[lim + 1][lim];
    for (int i=lim + 2; i<=N + 2; i++)
        curr = max (curr, dp[i][lim]);
    for (int i=1; i<lim; i++)
    {
        int j = lim;
        ///dp[i][j] = max (dp[k][j], k > j)
        dp[i][j] = curr;
    }
    curr = dp[lim][lim + 1];
    for (int i=lim + 2; i<=N + 2; i++)
        curr = min (curr, dp[lim][i]);
    for (int j=1; j<lim; j++)
    {
        int i = lim;
        ///dp[i][j] = min (dp[i][k], k > i)
        dp[i][j] = curr;
    }
}
printf ("%d\n", dp[1][2]);
return 0;
}


Measured memory_bytes: 16000
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;

int main(){
    
    int n;
    cin >> n;
    ull cnt[30];
    for(int i = 0; i < 30; i++){
        cnt[i] = 1ULL;
    }
    for(int i = 0; i < n; i++){
        char c;
        cin >> c;
        cnt[c - 'a']++;
    }

    ull ans = 1ULL;

    ull div = (ull)1e9 + 7ULL;

    for(int i = 0; i < 30; i++){
        ans *= cnt[i];
        ans %= div;
        
    }

    ans--;

    

    cout << ans % div << endl;

}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

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

int main()
{
    cout << fixed << setprecision(15);
    ll H1, M1, H2, M2, K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;

    cout << (H2-H1)*60 + (M2-M1) - K << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

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

#define REP(i, n) for(ll i = 0; i < n; i++)

















int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    int cnt[200001] = {};
    for(int i = 0; i < n - 1; i++){
        int a;
        cin >> a;
        cnt[a]++;
    }
    for(int i = 1; i <= n; i++){
        cout << cnt[i] << '\n';
    }
}

Measured memory_bytes: 4396
#include <iostream>
#include <vector>
#include <algorithm>
#include <ios>
#include <iomanip>

int main(){
  int n, m;
  int cnt;
  std::cin >> n >> m;
  std::vector<std::pair<int, std::pair<int, int> > > city(m), ans(m);
  std::pair<int, int> pair, pair_new;
  for(int i = 0; i < m; i++){
    std::cin >> city[i].first >> pair.first;
    pair.second = i;
    city[i].second = pair;
  }
  std::sort(city.begin(), city.end());

  pair_new.first = 1;
  cnt = 0;
  for(int i = 0; i < m; i++){
    pair = city[i].second;
    ans[i].first = pair.second;
    if(pair_new.first != city[i].first){
      pair_new.first = city[i].first;
      cnt = 0;
    }
    cnt++;
    pair_new.second = cnt;
    ans[i].second = pair_new;
  }
  std::sort(ans.begin(), ans.end());

  for(int i = 0; i < m; i++){
    pair = ans[i].second;
    std::cout << std::setfill('0') << std::right << std::setw(6) << pair.first;
    std::cout << std::setfill('0') << std::right << std::setw(6) << pair.second << std::endl;
  }
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char C;
  string A="abcdefghijklmnopqrstuvwxyz";
  cin >> C;
  for(int i=0;i<25;i++){
 if(C==A.at(i)){
    cout << A.at(i+1) << endl;
 }
  }
  
}

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

int main() {
  int n;

  cin >> n;

  vector<int> a(n);
  vector<long long> b(n + 1, 0); // cumulative sum table
  int mod = 1e9 + 7;

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

  long ans = 0;

  for(int i = 0; i < n; i++) {
    long long sum = (b[n] - b[i+1]) % mod;

    ans += a[i] * sum;
    ans %= mod;
  }

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

Measured memory_bytes: 5548
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

using std::string;
using std::vector;
using std::map;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

template<class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vc)
{
  for (auto it = vc.begin(); it != vc.end(); ++it)
  {
    if (std::next(it) == vc.end())
      os << *it;
    else
      os << *it << ' ';
  }
  return os;
}

template<class T1, class T2>
inline std::ostream& operator<<(std::ostream & os, const std::pair<T1, T2> & p)
{
  return os << p.first << ' ' << p.second;
}

void solve(void)
{
  ui N{}; std::cin >> N;
  vector<ll> A(N), B(N);
  for(auto& a : A) cin >> a;
  for(auto& b : B) cin >> b;

  typedef pair<ll, ui> Pair;
  std::priority_queue<Pair> queue;
  for(ui i = 0; i < N; ++i)
  {
    if(B[i] > A[i])
    {
      queue.push(Pair{B[i], i});
    }
    else if(B[i] < A[i])
    {
      cout << "-1" << '\n';
      return;
    }
  }

  ll ans{};
  while(!queue.empty())
  {
    auto curr = queue.top().second;
    queue.pop();

    auto sum = B[(curr + N - 1) % N] + B[(curr + 1) % N];

    if((A[curr] - B[curr]) % sum == 0)
    {
      ans += (B[curr] - A[curr]) / sum;
      B[curr] = A[curr];
      continue;
    }
    if(B[curr] <= sum)
    {
      ans = -1;
      break;
    }
    
    ans += B[curr] / sum;
    B[curr] %= sum;
    if(B[curr] < A[curr])
    {
      ans = -1;
      break;
    }
    queue.push(Pair{B[curr], curr});
  }

  cout << ans << '\n';
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


Measured memory_bytes: 9584
#include <bits/stdc++.h>
#define FOR(i,a,b) for(register int i=(a);i<(b);++i)
#define ROF(i,a,b) for(register int i=(a);i>=(b);--i)
#define pi pair<int,int>
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef double db;
const int maxn = 5005;
const int maxm = 100;
const int inf = 2147483647;
typedef long long ll;
const double eps = 1e-9;
const long long INF = 9223372036854775807ll;
ll qpow(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c;b>>=1;}return ans;}
int a[maxn];

int main(){
	int n;
	scanf("%d",&n);
	FOR(i,0,n)scanf("%d",&a[i]);
	sort(a,a+n);
	ll cnt=0;
	FOR(i,0,n)
	FOR(j,i+1,n){
		int t=lower_bound(a,a+n,a[i]+a[j])-a;
		cnt+=n-t;
	}
	cnt=(ll)n*(n-1)*(n-2)/6ll-cnt;
	printf("%lld\n",cnt);
}


Measured memory_bytes: 3816
#include <iostream>


using namespace std;


int main()
{
	int N;
	int p;
	int sum = 0;
	int max_p = 0;

	cin >> N;

	for (int n = 0; n < N; n++) {
		cin >> p;
		sum += p;
		if (p > max_p) max_p = p;
	}

	sum -= max_p / 2;

	printf("%d", sum);

	return 0;
}



Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String [] args){
        Scanner sc = new Scanner(System.in);
        int n  = sc.nextInt();
        int [] A = new int [n+1];
        for(int i=1;i<=n;i++) A[i] = sc.nextInt();
        for(int i=n/2;i>=1;i--)maxheap_build(A,i);
        for(int i=1;i<=n;i++) System.out.print(" "+A[i]);
        System.out.println();
    }
    public static void maxheap_build(int [] A,int i){
        int largest = 0;
        if (i * 2 < A.length&& A[i*2] > A[i]) largest = i*2;
        else largest = i;
        if(i*2+1<A.length&&A[i*2+1]>A[largest]) largest = i*2+1;
        if(largest!=i){
            int k = A[largest];
            A[largest] = A[i];
            A[i] = k;
            maxheap_build(A,largest);
        }
    }
}


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

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

  double ans = 0.0;

  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    ans += 1.0 / A;
  }

  cout << 1.0 / ans << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <math.h>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

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

int a, b, c, d, e, f;
float ans = 0;
int ansA = 0, ansB = 0;

int addSuger(int limit);

void rec(int i, int j) {
	if (100 * a * i + 100 * b * j > f) {
		return;
	}

	// 操作１をi回、2をj回やったときの最大濃度
	int limit = (a * i + b * j) * e;
	limit = min(limit, f - (100 * a * i + 100 * b * j));
	int res = addSuger(limit);

	if (ans <= (float)res / (float)(a * i + b * j + res)) {
		ans = (float)res / (float)(a * i + b * j + res);
		ansA = 100 * a * i + 100 * b * j + res;
		ansB = res;
	}

	rec(i + 1, j);
	rec(i, j + 1);
}

int addSuger(int limit) {
	// 砂糖を限界まで入れる
	int maxNum = 0;
	rep(i, limit / c + 1) {
		rep(j, limit / d + 1) {
			if (c * i + d * j > limit) continue;
			maxNum = max(maxNum, c * i + d * j);
		}
	}

	return maxNum;
}


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

	//int a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;

	// 高濃度の砂糖水を作る
	// 100g当たりに溶ける砂糖Eに近づける

	// 操作１を30回したら限界
	// 操作１と操作２を任意の数確かめ、全探索

	// 計算量 30 * 30 * 30 * 30? = 1e6 間に合う
	rec(0, 0);

	cout << ansA << " " << ansB << endl;

	return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> v;
    for (int i = 0; i < n; i++) {
        int l;
        cin >> l;
        v.push_back(l);
    }
    sort(v.begin(), v.end());

    int cnt = 0;
    for (int i = n - 1; i >= 2; i--) {
        int left = 0;
        int right = i - 1;
        while (left < right) {
            if (v[left] + v[right] > v[i]) {
                cnt += right - left;
                right--;
            }
            else {
                left++;
            }
        }
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 998244353ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

const int N = 200000; // ~ 1e7
s64 fac[N + 1], finv[N + 1];

s64 mypow(s64 x, s64 n)
{
    s64 ret = 1;
    while (n > 0)
    {
        if (n & 1) ret = (ret * x) % MOD;
        x = (x * x) % MOD;
        n >>= 1;
    }
    return ret;
}

void init(int n)
{
    if (n > N) n = N;
    fac[0] = 1;
    rep (i, n)
    {
        fac[i + 1] = (fac[i] * (i + 1)) % MOD;
    }
    finv[n] = mypow(fac[n], MOD - 2);
    for (int i = n; i >= 1; --i)
    {
        finv[i - 1] = (finv[i] * i) % MOD;
    }
}

s64 com(int n, int k)
{
    if (n < k || n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

    s64 n, m, k;
    cin >> n >> m >> k;

    init(n);

    s64 ans = 0;
    s64 f[n + 1];
    f[0] = 1;
    rep (i, n)
    {
        f[i + 1] = f[i] * (m - 1) % MOD;
    }
    rep (i, k + 1)
    {
        ans += com(n - 1, i) * m % MOD * f[n - i - 1] % MOD;
        ans %= MOD;
    }

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 8300
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        for (int i = a; i <= a * b; i += a) {
            if (i % b == c) {
                System.out.println("YES");
                return;
            }
        }
        System.out.println("NO");
    }
}

Measured memory_bytes: 22996
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        boolean hasA = false;
        boolean hasB = false;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == 'A') {
                hasA = true;
            }
            if (s.charAt(i) == 'B') {
                hasB = true;
            }
        }
        System.out.println(hasA&&hasB ? "Yes" : "No");
    }
}


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

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dumpi(x1) fprintf(stderr, "#%s.%d (%s) = (%d)\n", __func__, __LINE__, #x1, x1);
#define dumpii(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%d, %d)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumpiii(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%d, %d, %d)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);

template<typename a>
struct S001 {
  int n;
  std::vector<a> xs;
  S001(int n_, const std::vector<a>& ys) : n(n_), xs(n_ + 1) {
    a t = 0;
    xs[0] = 0;
    for(int i = 0; i < n; ++i) {
      t += ys[i];
      xs[i+1] = t;
    }
  }
  a operator [] (int i) {
    return xs[i];
  }
  a f(int x, int y) {
    return xs[y] - xs[x];
  }
};

struct Solver {
  int n, k;
  std::vector<long> xs;
  void read() {
    scanf("%d %d", &n, &k);
    xs.resize(n);
    for(int i = 0; i < n; ++i) {
      scanf("%ld", &xs[i]);
    }
  }
  void solve() {
    read();
    std::vector<long> ys, zs;
    std::transform(xs.begin(), xs.end(), std::back_inserter(ys),
                   [](long x) { return std::max((long)0, x); });
    std::transform(xs.begin(), xs.end(), std::back_inserter(zs),
                   [](long x) { return std::min((long)0, x); });
    S001<long> s(n, ys);
    S001<long> t(n, zs);
    long z = 11223344;
    for(int i = 0; i < n - k + 1; ++i) {
      long x = s.f(0, i) + s.f(i + k, n) + s.f(i, i + k) + t.f(i, i + k);
      long y = s.f(0, i) + s.f(i + k, n);
      if( i == 0 ) z = std::max(x, y);
      else z = std::max(std::max(z, x), y);      
    }
    printf("%ld\n", z);
  }
};

int main() {
  Solver s;
  s.solve();
  
  return 0;
}

Measured memory_bytes: 4340
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>


using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<n;++i)
#define FOR(i, a, b) for(int i=a;i<b;++i)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=b-1;i>=a;--i)

#define all(x) begin(x),end(x)
#define dump(x) cerr<<#x<<" = "<<(x)<<endl
#define debug(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

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

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


template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> p) {
    os << p.first << ":" << p.second;
    return os;
}

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

template<class T1, class T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
    os << "[";
    for (auto it = mp.begin(); it != mp.end(); ++it) {
        if (it != mp.begin()) {
            os << ", ";
        }
        os << *it;
    }
    return os << "]";
}

// edit

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

    vector<ll> L(N);
    REP(i, N) cin >> L[i];


    int ans = 0;
    REP(i, N) {
        FOR(j, i + 1, N) {
            FOR(k, j + 1, N) {
                vector<ll> vec{L[i], L[j], L[k]};
                sort(all(vec));
                if (vec[0] == vec[1] || vec[1] == vec[2]) continue;
                if (vec[0] + vec[1] > vec[2]) {
//                    cout << i << " " << j << " " << k << endl;
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    solve();


    return 0;
}


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

int main()
{
	int n,x;
	bool t;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>x;
		if(x%2==0)
			if(x%3!=0 && x%5!=0)
			{
				cout<<"DENIED"<<endl;
				return 0;
			}
	}
	cout<<"APPROVED"<<endl;
	return 0;
}

Measured memory_bytes: 256
//{{{
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    string s; cin >> s;
    int r = 0, b = 0;
    for(auto& c : s){
        r += c == 'R';
        b += c == 'B';
    }
    cout << (r > b ? "Yes" : "No") << '\n';
}


Measured memory_bytes: 888
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <tuple>
#include <functional>

using namespace std;

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main() {
	int n;
	string s;
	cin >> s;
	n = s.size();
	vector<int> ans(n);
	rep(ri, 2) {
		{
			int cnt = 0;
			rep(i, n) {
				if (s[i] == 'R') cnt++;
				else {
					ans[i] += cnt / 2;
					ans[i - 1] += (cnt + 1) / 2;
					cnt = 0;
				}
			}
		}

		reverse(ans.begin(), ans.end());
		reverse(s.begin(), s.end());
		rep(i, n) {
			if (s[i] == 'L') s[i] = 'R';
			else s[i] = 'L';
		}
	}

	rep(i, n) {
		printf("%d\n", ans[i]);
	}
	return 0;
}


Measured memory_bytes: 1152
/*
* ワーシャルフロイドと全探索
*/

#include <algorithm>
#include <iostream>
#include <set>
#include <vector>
#include <cmath>
#include <utility>
#include <numeric>

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

#define all(a) (a).begin(), (a).end()
#define rep(i, n) for (int i=0;(i)<(n);(i)++)
#define repi(i, n) for (int i=0;(i)<=(n);(i)++)
#define repr(i, n) for (int i=n;(i)>=0;(i)--)
#define INF (1<<29);

int main() {
    int n,m,r; cin>>n>>m>>r;
    vi rs(r); rep(i, r) cin>>rs[i];
    vvi d(n, vi(n));
    rep(i, n) rep(j, n) if (i!=j) d[i][j]=INF;
    rep(i, m) {
        int a, b, c; cin>>a>>b>>c;
        a--; b--;
        d[a][b] = d[b][a] = c;
    }
    rep(k, n) {
        rep(i, n) {
            rep(j, n) {
                if (d[i][j] > d[i][k] + d[k][j]) {
                    d[i][j] = d[i][k] + d[k][j];
                }
            }
        }
    }
    int ans = INF;
    sort(all(rs));
    do {
        int t = 0;
        rep(i, r-1) {
            t += d[rs[i]-1][rs[i+1]-1];
        }
        if (t < ans) ans = t;
    } while (next_permutation(all(rs)));
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;
using pll=pair<ll,ll>;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

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 (b<a) { a=b; return 1; } return 0; }

int main() {
	string S;
	cin >> S;
	int n = S.length();
	if(S == "keyence") {
		cout << "YES" << endl;
		return 0;
	}
	rep(i,n) for(int j=0; j<n-i; j++) {
		string s = S;
		s.erase(i,j);
		//cout << i << " " << j << " " << s << endl;
		if(s=="keyence") {
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;



  return 0;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const long long mod = 1e9 + 7;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

ll powMod(ll n, ll k, ll m) {
	if (k == 0) {
		return 1;
	} else if (k % 2 == 1) {
		return powMod(n, k - 1, m) * n % m;
	} else {
		ll t = powMod(n, k / 2, m);
		return t * t % m;
	}
}

int main() {

	int ans=0;

	rep(i, 5) {
		int n;
		cin >> n;
		if (n == 0) {
			ans=i+1;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 3416
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;


void main()
{
  auto s = readln.chomp.split;
  writeln(s[1] ~ s[0]);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct Edge{
    ll to, weight;
    Edge(ll t, ll w) : to(t), weight(w){}
};
using graph = vector<vector<ll>>;
using Graph = vector<vector<Edge>>;


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

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

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

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INF = 1000000007;
const int mod = 1000000007;

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;
}

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

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

//----------------------------------------------------------------

int main()
{
    int n;
    cin >> n;
    map<string, int> rensou;
    string s;
    for (int i = 0; i < n; i++)
    {
        cin >> s;
        rensou[s]++;
    }
    int max = -INF;
    for (auto f : rensou)
    {
        chmax(max, f.second);
    }
    vector<string> ans;
    for (auto f : rensou)
    {
        if (f.second == max)
        {
            ans.push_back(f.first);
        }
    }
    sort(ans.begin(), ans.end());
    for (auto f : ans)
    {
        cout << f << endl;
    }
}

Measured memory_bytes: 26868
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
const int maxn=1e4+5,maxm=4e4+5;
const ll inf=1e18;
inline int fa(int u){ return u/2; }
inline int ls(int u){ return u*2; }
inline int rs(int u){ return u*2+1; }
struct heap{
	int hea[maxn],pos[maxn],siz;
	ll *dis;
	heap(ll a[],int n){
		dis=a; siz=n;
		int i;
		for (i=1;i<=n;i++){
			dis[i]=inf; hea[i]=i; pos[i]=i;
		}
	}
	void hswap(int u,int v){
		swap(hea[u],hea[v]);
		pos[hea[u]]=u; pos[hea[v]]=v;
	}
	void update(int u){
		if (u==1) return;
		if (dis[hea[fa(u)]]<=dis[hea[u]]) return;
		hswap(u,fa(u));
		update(fa(u));
	}
	void pushdown(int u){
		int v=u;
		if (ls(u)<=siz&&dis[hea[ls(u)]]<dis[hea[v]]) v=ls(u);
		if (rs(u)<=siz&&dis[hea[rs(u)]]<dis[hea[v]]) v=rs(u);
		if (u==v) return;
		hswap(u,v);
		pushdown(v);
	}
	void change(int u,ll val){
		dis[u]=val;
		update(pos[u]);
		pushdown(pos[u]);
	}
	int pop(){
		hswap(1,siz);
		siz--;
		pushdown(1);
		return hea[siz+1];
	}
};
struct gragh{
	int head[maxn],next[maxm],to[maxm],tot;
	ll wei[maxm],cost[maxm];
	gragh(){
		memset(head,-1,sizeof(head));
		tot=0;
	}
	void clear(){
		memset(head,-1,sizeof(head));
		tot=0;
	}
	void add(int u,int v,ll w,ll c){
		next[tot]=head[u];
		head[u]=tot;
		to[tot]=v;
		wei[tot]=w;
		cost[tot]=c;
		tot++;
	}
	void dijkstra(ll dis[],ll val[],int st,int n){
		heap hp(dis,n);
		hp.change(st,0);
		int i,u,v,ed;
		for (i=1;i<=n;i++) val[i]=inf;
		val[st]=0;
		while (hp.siz){
			u=hp.pop();
			for (ed=head[u];ed!=-1;ed=next[ed])
				if (dis[v=to[ed]]>dis[u]+wei[ed])
					hp.change(v,dis[u]+wei[ed]);
		}
		for (u=1;u<=n;u++) for (ed=head[u];ed!=-1;ed=next[ed])
			if (dis[v=to[ed]]==dis[u]+wei[ed])
			val[v]=min(val[v],cost[ed]);
	}
};
gragh g;
ll dis[maxn],val[maxn];
int main(){
	int n,m,i,u,v;
	ll w,c,ans;
	while (scanf("%d%d",&n,&m)&&(n||m)){
		g.clear();
		for (i=0;i<m;i++){
			scanf("%d%d%lld%lld",&u,&v,&w,&c);
			g.add(u,v,w,c);
			g.add(v,u,w,c);
		}
		g.dijkstra(dis,val,1,n);
		ans=0;
		for (i=1;i<=n;i++) ans+=val[i];
		printf("%lld\n",ans);
	}
	return 0;
}


Measured memory_bytes: 4404
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n; cin>>n;
	for(int i=1; i<=9; i++){
		for(int j=1; j<=9; j++){
			if(i*j==n){
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	static final long MOD = 1000000007;

	static int H, W, K;
	static long[][] dp = new long[110][10];
	static int ans = 0;
	static int n = 0;
	static long x = 0;
	static long[] X;
	static long[] P;




	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		n = sc.nextInt();
		if(n == 7 || n == 5 || n == 3){
			System.out.println("YES");
		}else{
			System.out.println("NO");

		}


	}

}







class Pair implements Comparable{
	int from;		//p
	int end;		//y
	int num;
	int bango;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}


Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
 
typedef vector <int> vi;
typedef pair< int ,int > pii;
#define all(v) v.begin(),v.end()
#define PB push_back
#define T(val) while(val--)
#define FIN for(i=0;i<n;i++)
#define FIS for(i=0;i<s.length();i++)
#define AIN for(i=0;i<n;i++){cin>>a[i];}
#define F(i,k,n) for(i=k;i<n;i++)
#define FG(i,k,n,x) for(i=k;i<n;i+=x)
#define YES cout<<"YES\n"; 
#define NO cout<<"NO\n"; 
#define ll long long
#define MOD 1000000007
#define deb(x) cout << #x << "=" << x << endl;
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//sort(arr, arr+n, greater<int>()); For sorting in reverse order 
ll dp[101][100001];

int solve(){
  ll N,W;
  cin>>N>>W;
  ll w[N],v[N];
  ll i,j;
  for(i=0;i<N;i++){
    cin>>w[i]>>v[i];
  }
  
  for(i=0;i<=N;i++){
    for(ll j=0;j<=100000;j++)
      dp[i][j]=1e18;
  }
  dp[1][0]=0;
  dp[1][v[0]]=w[0];
  for(i=2;i<=N;i++){
    dp[i][0]=0;
    for(j=1;j<=100000;j++){
      if(w[i-1]>W){
        dp[i][j]=dp[i-1][j];
      }
      else
        dp[i][j]=min(dp[i-1][j],w[i-1] + dp[i-1][j-v[i-1]]);
    }
  }
  
  for(i=100000;i>=0;i--){
    // cout<<i<<" "<<dp[N][i]<<"\n";
    if(dp[N][i]<=W){
      cout<<i<<"\n";
      return 0;
    }
  }
  return 0;
}
int main(){
fast
  int t=1;
  // cin>>t; 
  T(t){
    solve();
  }
  return 0;
}

Measured memory_bytes: 82436
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef complex<double> xy_t;
typedef vector<lint> poly;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

const lint mod = 1e9+7;
const lint INF = mod*mod;
const int MAX =100010;

int n, K;
lint h[310], dp[2][310][310];
vector<lint> h_idx;

int main(){
    scanf("%d%d", &n, &K);
    h_idx.push_back(0);
    rep(i, n){
        scanf("%lld", &h[i]);
        h_idx.push_back(h[i]);
    }
    sort(h_idx.begin(), h_idx.end());
    h_idx.erase(unique(h_idx.begin(), h_idx.end()), h_idx.end());

    rep(i, 2)rep(j, K+1)rep(k, 310) dp[i][j][k]=INF;
    dp[0][0][0]=0;
    rep(i, n){
        rep(j, K+1)rep(k, 310)if(dp[0][j][k]<INF){
            if(j<K) chmin(dp[1][j+1][k], dp[0][j][k]);

            int idx=lower_bound(h_idx.begin(), h_idx.end(), h[i])-h_idx.begin();
            chmin(dp[1][j][idx], dp[0][j][k]+max(0LL, h[i]-h_idx[k]));
        }

        rep(j, K+1)rep(k, 310){
            swap(dp[0][j][k], dp[1][j][k]);
            dp[1][j][k]=INF;
        }
    }

    lint ans=INF;
    rep(j, K+1)rep(k, 310) chmin(ans, dp[0][j][k]);
    printf("%lld\n", ans);
}

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

vector<int> factmod;
vector<int> factmod_inv;
int modpower(int num, int mod, int to) {
  long ntemp = num;
  int ret = 1;
  for (int pow = 0; pow < 32; pow++) {
    if (to >> pow == 0) {
      return ret;
    }
    if ((to | 1 << pow) == to) {
      ret = (long)(ret * ntemp) % mod;
    }
    ntemp = (long)(ntemp * ntemp) % mod;
  }
  return ret;
}
int MOD = 1e9 + 7;
int main() {
  int N, K;
  cin >> N >> K;
  int f_size = 2e6 + 1;
  factmod.resize(f_size);
  factmod_inv.resize(f_size);
  factmod.at(0) = 1;
  for (int f_i = 1; f_i < f_size; f_i++) {
    factmod.at(f_i) = ((long)factmod.at(f_i - 1) * f_i) % MOD;
    // if (factmod.at(f_i) < 0) {
    //
    //   cout << f_i << endl;
    // }
    // if (modpower(factmod.at(f_i), MOD, MOD - 2) < 0) {
    //   cout << f_i << endl;
    // }
  }

  long retsum = 0;
  for (int m_i = 0; m_i <= min(K, N - 1); m_i++) {
    long ret = ((long)factmod.at(N) * factmod.at(N - 1)) % MOD;
    int mfact_inv = modpower(factmod.at(m_i), MOD, MOD - 2);
    ret = (ret * mfact_inv) % MOD;
    ret = (ret * mfact_inv) % MOD;
    ret = (ret * modpower(factmod.at(N - m_i), MOD, MOD - 2)) % MOD;
    ret = (ret * modpower(factmod.at(N - m_i - 1), MOD, MOD - 2)) % MOD;
    retsum = (retsum + ret) % MOD;
  }
  cout << retsum << endl;
}


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

#define endl '\n'
#define ff first
#define ss second
#define mp make_pair
#define pb push_back

typedef long long llong;
typedef pair<int, int> pii;


void solve(){

	int n, l;
	cin >> n >> l;

	vector<string> arr(n);

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

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

	for(string &s : arr){
		cout << s;
	}

}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	#ifdef LOCAL
		ifstream in("in");
		cin.rdbuf(in.rdbuf());
	#endif

	solve();

	return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range;
import std.bigint;

void main(){
	
	long[] ins = readln.chomp.split.map!(to!long).array;
	long n = ins[0], x = ins[1];
	
	long y = n - x;
	
	long a, b;
	if(x > y) a = x, b = y;
	else a = y, b = x;
	
	long ans = a + b;
	while(b > 0){
		long r = a % b;
		ans += b * 2 * (a / b);
		a = b;
		b = r;
		}
	ans -= a;
	
	ans.writeln;
	
	}

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

const int Maxl = 26;
const int Maxd = 5;

int n, m;
int freq[Maxl];
int all[Maxd];

int main()
{
	scanf("%d %d", &n, &m);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++) {
			char ch; scanf(" %c", &ch);
			freq[ch - 'a']++;
		}
	for (int i = 0; i <= n - i - 1; i++)
		for (int j = 0; j <= m - j - 1; j++)
			if (i == n - i - 1 && j == m - j - 1) all[1]++;
			else if (i == n - i - 1 || j == m - j - 1) all[2]++;
				 else all[4]++;
	for (int i = 0; i < Maxl; i++) {
		if (freq[i] % 2) {
			if (all[1] == 0) { printf("No\n"); return 0; }
			freq[i]--; all[1]--;
		}
		if (freq[i] % 4 == 2) {
			if (all[2] == 0) { printf("No\n"); return 0; }
			freq[i] -= 2; all[2]--;
		}
	}
	for (int i = 0; i < Maxl; i++)
		for (int j = 1; j < Maxd; j++) while (all[j] > 0 && freq[i] >= j) {
			all[j]--; freq[i] -= j;
		}
	for (int i = 1; i < Maxd; i++) if (all[i] > 0) { printf("No\n"); return 0; }
	printf("Yes\n");
	return 0;
}

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

int N;
int A[20];
int x[20][20];
int y[20][20];

int counter(int x) {
    if(x == 0) return 0;
    return counter(x >> 1) + (x & 1);
}
//xの中の1の総数

void solve() {
    cin >> N;
    for(int i = 1; i <= N; i++) {
        cin >> A[i];
        for(int j = 1; j <= A[i]; j++) {
            cin >> x[i][j] >> y[i][j];
        }
    }
    int ans = 0;
    for(int bits = 1; bits < (1 << N); bits++) {
      //n桁まで調べる
        bool ok = true;
        for(int i = 1; i <= N; i++) {
            if(!(bits & (1 << (i-1)))) continue;
            //i番目のフラグが１でない時
            for(int j = 1; j <= A[i]; j++) {
              //証言の数全てについて正しいか検証
                if(((bits >> (x[i][j]-1)) & 1) ^ y[i][j]) ok = false;
                //XOR(^)演算子
            }
        }
        if(ok) ans = max(ans, counter(bits));
    }
    cout << ans << endl;
    return;
}

int main() {
    solve();
    return 0;
}


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

int n;
int a[100];

signed main() {
	cin >> n;
	
	
	int mmax = -114514;
	int mmin = 114514;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		mmax = max(a[i], mmax);
		mmin = min(a[i], mmin);
	}
	
	cout << mmax - mmin << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a[10000000],b;
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n - 1; i++) {
		if (a[i + 1] > a[i]) {
			b++;
		}
	}
	cout << b << endl;
}


Measured memory_bytes: 3508
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    h,w=MI()
    cc=[SI() for _ in range(h)]
    dd=[""]*h*2
    for i in range(h):
        dd[i*2]=dd[i*2+1]=cc[i]
    p2D(dd)

main()

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstddef>
#include<queue>
#include<math.h>
#include<iomanip>
using namespace std;

int main()
{
    long long N, A, B, ans = 0, rem = 0;
    cin >> N >> A >> B;
    ans = N / (A + B) * A;
    rem = N % (A + B);
    ans += min(rem, A);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256